1 package org.apache.maven.scm.provider.git.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmTestCase;
23 import org.apache.maven.scm.manager.ScmManager;
24 import org.apache.maven.scm.repository.ScmRepository;
25 import org.apache.maven.scm.repository.ScmRepositoryException;
26
27
28
29
30
31 public class GitScmProviderRepositoryTest
32 extends ScmTestCase
33 {
34 private ScmManager scmManager;
35
36 public void setUp()
37 throws Exception
38 {
39 super.setUp();
40
41 scmManager = getScmManager();
42 }
43
44
45
46
47
48 public void testLegalFileURL()
49 throws Exception
50 {
51 testUrl( "scm:git:file:///tmp/repo", null, "file:///tmp/repo", null, null, null, null, 0, null);
52 }
53
54 public void testLegalFileHomeURL()
55 throws Exception
56 {
57 testUrl( "scm:git:file://~/repo", null, "file://~/repo", null, null, null, null, 0, null);
58 }
59
60 public void testLegalSshHomeURL()
61 throws Exception
62 {
63 testUrl( "scm:git:ssh://~/repo", null, "ssh://~/repo", null, null, null, null, 0, null);
64 }
65
66 public void testLegalLocalhostFileURL()
67 throws Exception
68 {
69 testUrl( "scm:git:file://somedirectory/tmp/repo", null, "file://somedirectory/tmp/repo", null, null,
70 null, null, 0, "somedirectory/tmp/repo");
71 }
72
73 public void testLegalHistnameFileURL()
74 throws Exception
75 {
76 testUrl( "scm:git:file://my_server/tmp/repo", null, "file://my_server/tmp/repo", null, null,
77 null, null, 0, "my_server/tmp/repo");
78 }
79
80 public void testLegalHttpURL()
81 throws Exception
82 {
83 testUrl( "scm:git:http://gitrepos.apache.org", null, "http://gitrepos.apache.org", null, null,
84 null, "gitrepos.apache.org", 0, null);
85 }
86
87 public void testLegalHttpURLWithUser()
88 throws Exception
89 {
90 testUrl( "scm:git:http://user@gitrepos.apache.org", null, "http://user@gitrepos.apache.org", null, "user",
91 null, "gitrepos.apache.org", 0, null);
92 }
93
94 public void testLegalHttpURLWithUserPassword()
95 throws Exception
96 {
97 testUrl( "scm:git:http://user:password@gitrepos.apache.org", null, "http://user:password@gitrepos.apache.org",
98 null, "user", "password", "gitrepos.apache.org", 0, null);
99 }
100
101 public void testLegalHttpsURL()
102 throws Exception
103 {
104 testUrl( "scm:git:https://gitrepos.apache.org/repos/projectA", null, "https://gitrepos.apache.org/repos/projectA", null, null,
105 null, "gitrepos.apache.org", 0, "repos/projectA");
106 }
107
108 public void testLegalFileWindowsURL()
109 throws Exception
110 {
111 testUrl( "scm:git:file://c:\\tmp\\repo", null, "file://c:\\tmp\\repo", null, null, null, null, 0, null);
112 }
113
114 public void testLegalHttpsURLWithUser()
115 throws Exception
116 {
117 testUrl( "scm:git:https://user@gitrepos.apache.org", null, "https://user@gitrepos.apache.org", null, "user",
118 null, "gitrepos.apache.org", 0, null);
119 }
120
121 public void testLegalHttpsURLWithUserPassword()
122 throws Exception
123 {
124 testUrl( "scm:git:https://user:password@gitrepos.apache.org", null, "https://user:password@gitrepos.apache.org",
125 null, "user", "password", "gitrepos.apache.org", 0, null);
126 }
127
128 public void testLegalSshURLWithUser()
129 throws Exception
130 {
131 testUrl( "scm:git:ssh://user@gitrepos.apache.org", null, "ssh://user@gitrepos.apache.org", null, "user",
132 null, "gitrepos.apache.org", 0, null);
133 }
134
135 public void testLegalSshURLWithUserPassword()
136 throws Exception
137 {
138 testUrl( "scm:git:ssh://user:password@gitrepos.apache.org", null, "ssh://user:password@gitrepos.apache.org",
139 null, "user", "password", "gitrepos.apache.org", 0, null);
140 }
141
142 public void testLegalGitURL()
143 throws Exception
144 {
145 testUrl( "scm:git:git://gitrepos.apache.org", null, "git://gitrepos.apache.org", null, null,
146 null, "gitrepos.apache.org", 0, null);
147 }
148
149 public void testGitDevURL()
150 throws Exception, ScmRepositoryException
151 {
152 testUrl( "scm:git:git@github.com:olamy/scm-git-test-one-module.git",
153 null, "git@github.com:olamy/scm-git-test-one-module.git", null, "git" , null, "github.com", 0, null);
154 }
155
156 public void testGitDevURLWIthPort()
157 throws Exception, ScmRepositoryException
158 {
159 testUrl( "scm:git:git@github.com:222:olamy/scm-git-test-one-module.git",
160 null, "git@github.com:222:olamy/scm-git-test-one-module.git", null, "git", null, "github.com", 222, null);
161 }
162
163
164 public void testGitDevUrlWithNumberedRepoAndNoPort()
165 throws Exception, ScmRepositoryException
166 {
167 testUrl( "scm:git:git@github.com:4sh/blah.git",
168 null, "git@github.com:4sh/blah.git", null, "git", null, "github.com", 0, null);
169 }
170
171
172
173 public void testGitDevUrlWithNumberedRepoAndMinus()
174 throws Exception, ScmRepositoryException
175 {
176 testUrl( "scm:git:ssh://git@github.com/360-Innovations/FJPAQuery.git",
177 null, "ssh://git@github.com/360-Innovations/FJPAQuery.git", null, "git", null, "github.com", 0, null);
178 }
179
180
181 public void testLegalGitPortUrl()
182 throws Exception
183 {
184 testUrl( "scm:git:http://username@gitrepos.apache.org:8800/pmgt/trunk",
185 null, "http://username@gitrepos.apache.org:8800/pmgt/trunk",
186 null, "username", null, "gitrepos.apache.org", 8800, null);
187
188 testUrl( "scm:git:https://username@gitrepos.apache.org:20443/pmgt/trunk",
189 null, "https://username@gitrepos.apache.org:20443/pmgt/trunk",
190 null, "username", null, "gitrepos.apache.org", 20443, null);
191
192 testUrl( "scm:git:git://username@gitrepos.apache.org:8800/pmgt/trunk",
193 null, "git://username@gitrepos.apache.org:8800/pmgt/trunk",
194 null, "username", null, "gitrepos.apache.org", 8800, null);
195
196 testUrl( "scm:git:ssh://username@gitrepos.apache.org:8080/pmgt/trunk",
197 null, "ssh://username@gitrepos.apache.org:8080/pmgt/trunk",
198 null, "username", null, "gitrepos.apache.org", 8080, null);
199
200 testUrl( "scm:git:ssh://username:password@gitrepos.apache.org/pmgt/trunk",
201 null, "ssh://username:password@gitrepos.apache.org/pmgt/trunk",
202 null, "username", "password", "gitrepos.apache.org", 0, null);
203 }
204
205
206
207
208
209 public void testHttpFetchSshPushUrl()
210 throws Exception
211 {
212 testUrl( "scm:git:[fetch=]http://git.apache.org/myprj.git[push=]ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git",
213 "[fetch=]http://myuser:mypassword@git.apache.org/myprj.git[push=]ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git",
214 "http://myuser:mypassword@git.apache.org/myprj.git",
215 "ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git", "myuser", "mypassword", "git.apache.org", 0, null);
216
217 testUrl( "scm:git:[push=]ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git[fetch=]http://git.apache.org/myprj.git",
218 "[fetch=]http://myuser:mypassword@git.apache.org/myprj.git[push=]ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git",
219 "http://myuser:mypassword@git.apache.org/myprj.git",
220 "ssh://myuser:mypassword@git.apache.org/~/myrepo/myprj.git", "myuser", "mypassword", "git.apache.org", 0, null);
221 }
222
223
224
225
226
227
228
229 public void nottestIllegalFileUrl()
230 throws Exception
231 {
232 testIllegalUrl( "file:/tmp/git" );
233 }
234
235
236
237
238
239 private GitScmProviderRepository testUrl(String scmUrl, String expectedToString,
240 String expectedFetchUrl, String expectedPushUrl,
241 String expectedUser, String expectedPassword,
242 String expectedHost, int expectedPort, String expectedPath)
243 throws Exception, ScmRepositoryException
244 {
245 ScmRepository repository = scmManager.makeScmRepository( scmUrl );
246
247 assertNotNull( "ScmManager.makeScmRepository() returned null", repository );
248
249 assertNotNull( "The provider repository was null.", repository.getProviderRepository() );
250
251 assertTrue( "The SCM Repository isn't a " + GitScmProviderRepository.class.getName() + ".", repository
252 .getProviderRepository() instanceof GitScmProviderRepository );
253
254 GitScmProviderRepository providerRepository = (GitScmProviderRepository) repository.getProviderRepository();
255
256 assertEquals( "fetch url is incorrect", expectedFetchUrl, providerRepository.getFetchUrl() );
257
258 if ( expectedPushUrl != null )
259 {
260 assertEquals( "push url is incorrect", expectedPushUrl, providerRepository.getPushUrl() );
261 }
262
263 if ( expectedToString != null )
264 {
265 assertEquals( "toString is incorrect", "git:" + expectedToString, repository.toString() );
266 }
267 else
268 {
269 assertEquals( "toString is incorrect", "git:" + expectedFetchUrl, repository.toString() );
270 }
271
272 assertEquals( "User is incorrect", expectedUser, providerRepository.getUser() );
273
274 assertEquals( "Password is incorrect", expectedPassword, providerRepository.getPassword() );
275
276 assertEquals( "Host is incorrect", expectedHost == null ? "" : expectedHost, providerRepository.getHost() );
277
278 if ( expectedPort > 0 )
279 {
280 assertEquals( "Port is incorrect", expectedPort, providerRepository.getPort() );
281 }
282
283 return providerRepository;
284 }
285
286 private void testIllegalUrl( String url )
287 throws Exception
288 {
289 try
290 {
291 scmManager.makeScmRepository( "scm:git:" + url );
292
293 fail( "Expected a ScmRepositoryException while testing the url '" + url + "'." );
294 }
295 catch ( ScmRepositoryException e )
296 {
297
298 }
299 }
300
301 public void testGetParent() throws Exception
302 {
303 new GitScmProviderRepository( "http://gitrepos.apache.org" );
304 }
305
306 }