Mercurial > hg > mercurial
comparison mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java @ 428:a68741340603
minor
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Fri, 11 May 2012 16:05:21 +0400 |
parents | mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java@c91c4f1ebd53 |
children | 04eab204ba39 |
comparison
equal
deleted
inserted
replaced
427:144734686138 | 428:a68741340603 |
---|---|
1 /* | |
2 * Copyright 2000-2011 JetBrains s.r.o. | |
3 * | |
4 * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 * you may not use this file except in compliance with the License. | |
6 * You may obtain a copy of the License at | |
7 * | |
8 * http://www.apache.org/licenses/LICENSE-2.0 | |
9 * | |
10 * Unless required by applicable law or agreed to in writing, software | |
11 * distributed under the License is distributed on an "AS IS" BASIS, | |
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 * See the License for the specific language governing permissions and | |
14 * limitations under the License. | |
15 */ | |
16 package jetbrains.buildServer.buildTriggers.vcs.mercurial; | |
17 | |
18 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; | |
19 import jetbrains.buildServer.vcs.VcsRoot; | |
20 import jetbrains.buildServer.vcs.impl.VcsRootImpl; | |
21 import junit.framework.TestCase; | |
22 import org.jetbrains.annotations.NotNull; | |
23 import org.testng.annotations.Test; | |
24 | |
25 /** | |
26 * @author Pavel.Sher | |
27 */ | |
28 @Test | |
29 public class HgVcsRootTest extends TestCase { | |
30 | |
31 public void test_url_without_credentials() { | |
32 VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path"); | |
33 HgVcsRoot root = createHgRoot(vcsRoot); | |
34 assertEquals("http://user:pwd@host.com/path", root.getRepositoryUrlWithCredentials()); | |
35 } | |
36 | |
37 public void test_url_with_credentials() { | |
38 VcsRootImpl vcsRoot = createVcsRoot("http://user:pwd@host.com/path"); | |
39 HgVcsRoot root = createHgRoot(vcsRoot); | |
40 assertEquals("http://user:pwd@host.com/path", root.getRepositoryUrlWithCredentials()); | |
41 } | |
42 | |
43 public void test_url_with_username() { | |
44 VcsRootImpl vcsRoot = createVcsRoot("http://user@host.com/path"); | |
45 HgVcsRoot root = createHgRoot(vcsRoot); | |
46 assertEquals("http://user:pwd@host.com/path", root.getRepositoryUrlWithCredentials()); | |
47 } | |
48 | |
49 public void test_url_with_at_after_slash() { | |
50 VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path@"); | |
51 HgVcsRoot root = createHgRoot(vcsRoot); | |
52 assertEquals("http://user:pwd@host.com/path@", root.getRepositoryUrlWithCredentials()); | |
53 } | |
54 | |
55 public void test_url_with_at_in_username() { | |
56 VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path", "my.name@gmail.com", "1234"); | |
57 HgVcsRoot root = createHgRoot(vcsRoot); | |
58 assertEquals("http://my.name%40gmail.com:1234@host.com/path", root.getRepositoryUrlWithCredentials()); | |
59 } | |
60 | |
61 /** TW-13768 */ | |
62 public void test_underscore_in_host() { | |
63 VcsRootImpl vcsRoot = createVcsRoot("http://Klekovkin.SDK_GARANT:8000/", "my.name@gmail.com", "1234"); | |
64 HgVcsRoot root = createHgRoot(vcsRoot); | |
65 assertEquals("http://my.name%40gmail.com:1234@Klekovkin.SDK_GARANT:8000/", root.getRepositoryUrlWithCredentials()); | |
66 } | |
67 | |
68 /** TW-13768 */ | |
69 public void test_underscore_in_host_with_credentials_in_url() { | |
70 VcsRootImpl vcsRoot = createVcsRoot("http://me:mypass@Klekovkin.SDK_GARANT:8000/"); | |
71 HgVcsRoot root = createHgRoot(vcsRoot); | |
72 assertEquals("http://me:mypass@Klekovkin.SDK_GARANT:8000/", root.getRepositoryUrlWithCredentials()); | |
73 } | |
74 | |
75 public void test_windows_path() throws Exception { | |
76 VcsRootImpl vcsRoot = createVcsRoot("c:\\windows\\path"); | |
77 HgVcsRoot root = createHgRoot(vcsRoot); | |
78 assertEquals("c:\\windows\\path", root.getRepositoryUrlWithCredentials()); | |
79 } | |
80 | |
81 public void test_file_scheme_has_no_credentials() { | |
82 VcsRootImpl vcsRoot = createVcsRoot("file:///path/to/repo", "my.name@gmail.com", "1234"); | |
83 HgVcsRoot root = createHgRoot(vcsRoot); | |
84 assertEquals("file:///path/to/repo", root.getRepositoryUrlWithCredentials()); | |
85 } | |
86 | |
87 public void uncompressed_transfer() { | |
88 VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path"); | |
89 vcsRoot.addProperty(Constants.UNCOMPRESSED_TRANSFER, "true"); | |
90 HgVcsRoot root = createHgRoot(vcsRoot); | |
91 assertTrue(root.isUncompressedTransfer()); | |
92 } | |
93 | |
94 //TW-18262 | |
95 public void ampersand_in_password() { | |
96 VcsRootImpl vcsRoot = createVcsRoot("http://some.org/path", "user", "m&n"); | |
97 HgVcsRoot root = createHgRoot(vcsRoot); | |
98 assertEquals("http://user:m%26n@some.org/path", root.getRepositoryUrlWithCredentials()); | |
99 } | |
100 | |
101 //TW-18835 | |
102 public void test_ssh() { | |
103 VcsRootImpl vcsRoot = createVcsRoot("ssh://ourserver.com/mercurialrepo/", "user", "pwd"); | |
104 HgVcsRoot root = createHgRoot(vcsRoot); | |
105 assertEquals("ssh://user:pwd@ourserver.com/mercurialrepo/", root.getRepositoryUrlWithCredentials()); | |
106 } | |
107 | |
108 private VcsRootImpl createVcsRoot(String url) { | |
109 return createVcsRoot(url, "user", "pwd"); | |
110 } | |
111 | |
112 private VcsRootImpl createVcsRoot(String url, String userName, String password) { | |
113 VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME); | |
114 vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, "hg.exe"); | |
115 vcsRoot.addProperty(Constants.REPOSITORY_PROP, url); | |
116 vcsRoot.addProperty(Constants.USERNAME, userName); | |
117 vcsRoot.addProperty(Constants.PASSWORD, password); | |
118 return vcsRoot; | |
119 } | |
120 | |
121 private HgVcsRoot createHgRoot(@NotNull final VcsRoot root) { | |
122 ServerPluginConfig config = new ServerPluginConfigBuilder().build(); | |
123 return new HgVcsRoot(new ServerHgPathProvider(config), root); | |
124 } | |
125 } |