1 package org.apache.maven.scm.provider.svn;
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.ScmBranch;
23 import org.apache.maven.scm.ScmRevision;
24 import org.apache.maven.scm.ScmTag;
25 import org.apache.maven.scm.ScmTestCase;
26 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
27 import org.apache.maven.scm.repository.ScmRepository;
28
29
30
31
32
33 public class SvnTagBranchUtilsTest
34 extends ScmTestCase
35 {
36
37
38
39
40 public void testAppendPath()
41 throws Exception
42 {
43 assertEquals( "http://foo.com/svn/myproject/tags/foo",
44 SvnTagBranchUtils.appendPath( "http://foo.com/svn", "myproject/tags/foo" ) );
45 }
46
47 public void testAppendPathNullAddlPath()
48 throws Exception
49 {
50 assertEquals( "http://foo.com/svn", SvnTagBranchUtils.appendPath( "http://foo.com/svn", null ) );
51 }
52
53 public void testAppendPathNullAddlTrailingSlash()
54 throws Exception
55 {
56 assertEquals( "http://foo.com/svn", SvnTagBranchUtils.appendPath( "http://foo.com/svn/", null ) );
57 }
58
59 public void testAppendPathTrailingSlash()
60 throws Exception
61 {
62 assertEquals( "http://foo.com/svn/myproject/tags/foo",
63 SvnTagBranchUtils.appendPath( "http://foo.com/svn/", "myproject/tags/foo" ) );
64 }
65
66 public void testAppendPathLeadingAndTrailingSlash()
67 throws Exception
68 {
69 assertEquals( "http://foo.com/svn/myproject/tags/foo",
70 SvnTagBranchUtils.appendPath( "http://foo.com/svn/", "/myproject/tags/foo" ) );
71 }
72
73
74
75
76
77 public void testResolveTagBase()
78 {
79 assertEquals( "http://foo.com/svn/myproject/tags",
80 SvnTagBranchUtils.resolveTagBase( "http://foo.com/svn/myproject/trunk" ) );
81 assertEquals( "http://foo.com/svn/myproject/tags",
82 SvnTagBranchUtils.resolveTagBase( "http://foo.com/svn/myproject/trunk/" ) );
83 }
84
85
86
87
88
89 public void testGetProjectRootTagBranchTrunk()
90 throws Exception
91 {
92
93 String[] paths = new String[]{"scm:svn:http://foo.com/svn/tags/my-tag", "scm:svn:http://foo.com/svn/tags",
94 "scm:svn:http://foo.com/svn/branches/my-branch", "scm:svn:http://foo.com/svn/branches",
95 "scm:svn:http://foo.com/svn/trunk", "scm:svn:http://foo.com/svn/trunk/some/path/to/some/file"};
96
97 for ( int i = 0; i < paths.length; i++ )
98 {
99 testGetProjectRoot( paths[i], "http://foo.com/svn" );
100 }
101 }
102
103 public void testGetProjectRootNoRootSpecifier()
104 throws Exception
105 {
106 testGetProjectRoot( "scm:svn:http://foo.com/svn/", "http://foo.com/svn" );
107
108 testGetProjectRoot( "scm:svn:http://foo.com/svn", "http://foo.com/svn" );
109
110 testGetProjectRoot( "scm:svn:http://foo.com/svn/ntags", "http://foo.com/svn/ntags" );
111
112 testGetProjectRoot( "scm:svn:http://foo.com/svn/nbranches", "http://foo.com/svn/nbranches" );
113 }
114
115 public void testGetProjectRootLooksLikeRootSpecifier()
116 throws Exception
117 {
118 testGetProjectRoot( "scm:svn:http://foo.com/svn/tagst", "http://foo.com/svn/tagst" );
119
120 testGetProjectRoot( "scm:svn:http://foo.com/svn/tagst/tags", "http://foo.com/svn/tagst" );
121
122 testGetProjectRoot( "scm:svn:http://foo.com/svn/branchess", "http://foo.com/svn/branchess" );
123
124 }
125
126 public void testGetProjectRootDoubleProjectRoots()
127 throws Exception
128 {
129 testGetProjectRoot( "scm:svn:http://foo.com/svn/tags/my-tag/tags/another-tag/",
130 "http://foo.com/svn/tags/my-tag" );
131 testGetProjectRoot( "scm:svn:http://foo.com/svn/trunk/a_directory/trunk/",
132 "http://foo.com/svn/trunk/a_directory" );
133 }
134
135
136
137
138
139 public void testResolveTagRelative()
140 throws Exception
141 {
142 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "my-tag", "http://foo.com/svn/tags/my-tag" );
143
144 testResolveTagUrl( "scm:svn:http://foo.com/svn/trunk", "my-tag", "http://foo.com/svn/tags/my-tag" );
145
146 testResolveTagUrl( "scm:svn:http://foo.com/svn/trunk/", "my-tag", "http://foo.com/svn/tags/my-tag" );
147
148 testResolveTagUrl( "scm:svn:http://foo.com/svn/branches", "my-tag", "http://foo.com/svn/tags/my-tag" );
149
150 testResolveTagUrl( "scm:svn:http://foo.com/svn/tags", "my-tag", "http://foo.com/svn/tags/my-tag" );
151 }
152
153 public void testResolveTagAbsolute()
154 throws Exception
155 {
156 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "http://foo.com/svn/branches/my-tag",
157 "http://foo.com/svn/branches/my-tag" );
158
159 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "file://C://svn/some/crazy/path/my-tag",
160 "file://C://svn/some/crazy/path/my-tag" );
161
162 }
163
164 public void testResolveTagViewCVS()
165 throws Exception
166 {
167 assertEquals( "http://foo.com/cgi-bin/viewcvs.cgi/svn/tags/my-tag?root=test", SvnTagBranchUtils.resolveTagUrl(
168 "http://foo.com/cgi-bin/viewcvs.cgi/svn/trunk/?root=test", new ScmTag( "/my-tag/" ) ) );
169 }
170
171 public void testResolveTagWithSlashes()
172 throws Exception
173 {
174 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "/my-tag/", "http://foo.com/svn/tags/my-tag" );
175
176 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "/my-branch/", "http://foo.com/svn/branches/my-branch" );
177
178 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "http://foo.com/svn/myproject/branches/", "/my-branch/",
179 "http://foo.com/svn/myproject/branches/my-branch" );
180 }
181
182 public void testResolveTagWithTagOverwritingBase()
183 throws Exception
184 {
185 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "branches/my-tag", "http://foo.com/svn/branches/my-tag" );
186
187 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "tags/my-tag", "http://foo.com/svn/tags/my-tag" );
188
189
190
191 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "trunk/my-tag", "http://foo.com/svn/trunk/my-tag" );
192
193 testResolveTagUrl( "scm:svn:svn+ssh://foo.com/svn/trunk/my_path/to/my_dir", "my-tag",
194 "svn+ssh://foo.com/svn/tags/my-tag" );
195
196 testResolveTagUrl( "scm:svn:svn+ssh://foo.com/svn/trunk/my_path/to/my_dir/trunk/mydir", "my-tag",
197 "svn+ssh://foo.com/svn/trunk/my_path/to/my_dir/tags/my-tag" );
198 testResolveTagUrl( "scm:svn:file://localhost/C:/mydir/myproject/trunk/my-module/target/scm-src/trunk", "my-tag",
199 "file://localhost/C:/mydir/myproject/trunk/my-module/target/scm-src/tags/my-tag" );
200 }
201
202 public void testResolveTagWithTagBaseSpecified()
203 throws Exception
204 {
205 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "../tags", "my-tag", "../tags/my-tag" );
206
207 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "http://foo.com/svn/non-standard/tag/dir/", "my-tag",
208 "http://foo.com/svn/non-standard/tag/dir/my-tag" );
209 }
210
211 public void testResolveTagLooksLikeOverwriteTagBase()
212 throws Exception
213 {
214 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "tagst/my-tag", "http://foo.com/svn/tags/tagst/my-tag" );
215
216 testResolveTagUrl( "scm:svn:http://foo.com/svn/", "metatags/my-tag",
217 "http://foo.com/svn/tags/metatags/my-tag" );
218 }
219
220 public void testResolveBranchSimple()
221 throws Exception
222 {
223 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "my-branch", "http://foo.com/svn/branches/my-branch" );
224
225 testResolveBranchUrl( "scm:svn:svn+ssh://foo.com/svn/trunk", "my-branch",
226 "svn+ssh://foo.com/svn/branches/my-branch" );
227
228 testResolveBranchUrl( "scm:svn:svn+ssh://foo.com/svn/trunk/my_path/to/my_dir", "my-branch",
229 "svn+ssh://foo.com/svn/branches/my-branch" );
230
231 testResolveBranchUrl( "scm:svn:http://foo.com/svn/trunk", "branches/my-branch",
232 "http://foo.com/svn/branches/my-branch" );
233
234 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "subbranches/my-branch",
235 "http://foo.com/svn/branches/subbranches/my-branch" );
236
237 }
238
239 public void testResolveBranchTagBase()
240 throws Exception
241 {
242 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "../branches", "my-branch", "../branches/my-branch" );
243
244 testResolveBranchUrl( "scm:svn:http://foo.com/svn/", "http://foo.com/svn/non-standard/branch/dir", "my-branch",
245 "http://foo.com/svn/non-standard/branch/dir/my-branch" );
246 }
247
248
249
250
251
252 public void testIsRevisionArgumentSimple()
253 {
254 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "12345" ) ) );
255
256 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "hEaD" ) ) );
257
258 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "bAsE" ) ) );
259
260 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "cOmMiTtEd" ) ) );
261
262 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "pReV" ) ) );
263
264 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "{2005-1-1}" ) ) );
265
266 }
267
268 public void testIsRevisionArgumentRange()
269 {
270 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "12345:12345" ) ) );
271
272 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "1:2" ) ) );
273
274 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "hEaD:bAsE" ) ) );
275
276 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "BaSe:CoMmItTeD" ) ) );
277
278 assertTrue( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "{2004-1-1}:{2005-1-1}" ) ) );
279
280 assertFalse( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( "BASE:" ) ) );
281 assertFalse( SvnTagBranchUtils.isRevisionSpecifier( new ScmRevision( ":BASE" ) ) );
282
283 }
284
285
286
287
288
289
290 public void testResolveUrlWithQuery()
291 throws Exception
292 {
293 String url = "https://myserver/plugins/scmsvn/viewcvs.php/pom/trunk?root=myproj";
294
295 SvnScmProviderRepository repo = new SvnScmProviderRepository( url );
296
297 assertEquals( "https://myserver/plugins/scmsvn/viewcvs.php/pom/trunk/tags/mytag-1?root=myproj",
298 SvnTagBranchUtils.resolveTagUrl( repo, new ScmTag( "mytag-1" ) ) );
299 }
300
301
302
303
304
305 private SvnScmProviderRepository getSvnRepository( String scmUrl )
306 throws Exception
307 {
308 ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
309
310 return (SvnScmProviderRepository) repository.getProviderRepository();
311 }
312
313 private void testGetProjectRoot( String scmUrl, String expected )
314 throws Exception
315 {
316 assertEquals( expected, SvnTagBranchUtils.getProjectRoot( getSvnRepository( scmUrl ).getUrl() ) );
317 }
318
319 private void testResolveTagUrl( String scmUrl, String tag, String expected )
320 throws Exception
321 {
322 testResolveTagUrl( scmUrl, null, tag, expected );
323 }
324
325 private void testResolveTagUrl( String scmUrl, String tagBase, String tag, String expected )
326 throws Exception
327 {
328 SvnScmProviderRepository repository = getSvnRepository( scmUrl );
329
330 if ( tagBase != null )
331 {
332 repository.setTagBase( tagBase );
333 }
334
335 if ( tagBase != null )
336 {
337 assertEquals( repository.getTagBase(), tagBase );
338 }
339 else
340 {
341 assertEquals( repository.getTagBase(), SvnTagBranchUtils.resolveTagBase( repository.getUrl() ) );
342 }
343
344 assertEquals( expected, SvnTagBranchUtils.resolveTagUrl( repository, new ScmTag( tag ) ) );
345 }
346
347 private void testResolveBranchUrl( String scmUrl, String branch, String expected )
348 throws Exception
349 {
350 testResolveBranchUrl( scmUrl, null, branch, expected );
351 }
352
353 private void testResolveBranchUrl( String scmUrl, String branchBase, String branch, String expected )
354 throws Exception
355 {
356 SvnScmProviderRepository repository = getSvnRepository( scmUrl );
357 if ( branchBase != null )
358 {
359 repository.setBranchBase( branchBase );
360 }
361
362 if ( branchBase != null )
363 {
364 assertEquals( repository.getBranchBase(), branchBase );
365 }
366 else
367 {
368 assertEquals( repository.getBranchBase(), SvnTagBranchUtils.resolveBranchBase( repository.getUrl() ) );
369 }
370
371 assertEquals( expected, SvnTagBranchUtils.resolveBranchUrl( repository, new ScmBranch( branch ) ) );
372 }
373
374 }