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