1 package org.apache.maven.archiva.repository.content;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.maven.archiva.model.ArtifactReference;
24 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
25 import org.apache.maven.archiva.repository.layout.LayoutException;
26
27
28
29
30
31
32 public class DefaultPathParserTest
33 extends AbstractRepositoryLayerTestCase
34 {
35 private PathParser parser = new DefaultPathParser();
36
37 public void testBadPathMissingType()
38 {
39 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
40 }
41
42 public void testBadPathReleaseInSnapshotDir()
43 {
44 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
45 }
46
47 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
48 {
49 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
50 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
51 }
52
53 public void testBadPathTooShort()
54 {
55 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
56 }
57
58 public void testBadPathVersionMismatchA()
59 {
60 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
61 }
62
63 public void testBadPathVersionMismatchB()
64 {
65 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
66 }
67
68 public void testBadPathWrongArtifactId()
69 {
70 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
71 "wrong artifact id" );
72 }
73
74
75
76
77 public void testGoodButDualExtensions()
78 throws LayoutException
79 {
80 String groupId = "org.project";
81 String artifactId = "example-presentation";
82 String version = "3.2";
83 String classifier = null;
84 String type = "xml.zip";
85 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
86
87 assertLayout( path, groupId, artifactId, version, classifier, type );
88 }
89
90
91
92
93
94
95 public void testGoodButOddVersionSpecGanymedSsh2()
96 throws LayoutException
97 {
98 String groupId = "ch.ethz.ganymed";
99 String artifactId = "ganymed-ssh2";
100 String version = "build210";
101 String classifier = null;
102 String type = "jar";
103 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
104
105 assertLayout( path, groupId, artifactId, version, classifier, type );
106 }
107
108
109
110
111
112
113 public void testGoodButOddVersionSpecJavaxComm()
114 throws LayoutException
115 {
116 String groupId = "javax";
117 String artifactId = "comm";
118 String version = "3.0-u1";
119 String classifier = null;
120 String type = "jar";
121 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
122
123 assertLayout( path, groupId, artifactId, version, classifier, type );
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 public void testGoodButOddVersionSpecJavaxPersistence()
153 throws LayoutException
154 {
155 String groupId = "javax.persistence";
156 String artifactId = "ejb";
157 String version = "3.0-public_review";
158 String classifier = null;
159 String type = "jar";
160 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
161
162
163
164
165
166
167
168
169 assertLayout( path, groupId, artifactId, version, classifier, type );
170 }
171
172 public void testGoodComFooTool()
173 throws LayoutException
174 {
175 String groupId = "com.foo";
176 String artifactId = "foo-tool";
177 String version = "1.0";
178 String classifier = null;
179 String type = "jar";
180 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
181
182 assertLayout( path, groupId, artifactId, version, classifier, type );
183 }
184
185 public void testGoodCommonsLang()
186 throws LayoutException
187 {
188 String groupId = "commons-lang";
189 String artifactId = "commons-lang";
190 String version = "2.1";
191 String classifier = null;
192 String type = "jar";
193 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
194
195 assertLayout( path, groupId, artifactId, version, classifier, type );
196 }
197
198
199
200
201 public void testGoodDashedArtifactId()
202 throws LayoutException
203 {
204 String groupId = "test.maven-arch";
205 String artifactId = "test-arch";
206 String version = "2.0.3-SNAPSHOT";
207 String classifier = null;
208 String type = "pom";
209 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
210
211 assertLayout( path, groupId, artifactId, version, classifier, type );
212 }
213
214
215
216
217 public void testGoodDotNotationArtifactId()
218 throws LayoutException
219 {
220 String groupId = "com.company.department";
221 String artifactId = "com.company.department";
222 String version = "0.2";
223 String classifier = null;
224 String type = "pom";
225 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
226
227 assertLayout( path, groupId, artifactId, version, classifier, type );
228 }
229
230
231
232
233 public void testGoodDotNotationSameGroupIdAndArtifactId()
234 throws LayoutException
235 {
236 String groupId = "com.company.department";
237 String artifactId = "com.company.department.project";
238 String version = "0.3";
239 String classifier = null;
240 String type = "pom";
241 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
242
243 assertLayout( path, groupId, artifactId, version, classifier, type );
244 }
245
246
247
248
249
250 public void testGoodFooLibSources()
251 throws LayoutException
252 {
253 String groupId = "com.foo.lib";
254 String artifactId = "foo-lib";
255 String version = "2.1-alpha-1";
256 String classifier = "sources";
257 String type = "java-source";
258 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
259
260 assertLayout( path, groupId, artifactId, version, classifier, type );
261 }
262
263
264
265
266
267 public void testGoodSnapshotMavenTest()
268 throws LayoutException
269 {
270 String groupId = "org.apache.archiva.test";
271 String artifactId = "redonkulous";
272 String version = "3.1-beta-1-20050831.101112-42";
273 String classifier = null;
274 String type = "jar";
275 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
276
277 assertLayout( path, groupId, artifactId, version, classifier, type );
278 }
279
280
281
282
283
284 public void testGoodLongSnapshotMavenTest()
285 throws LayoutException
286 {
287 String groupId = "a.group.id";
288 String artifactId = "artifact-id";
289 String version = "1.0-abc-1.1-20080221.062205-9";
290 String classifier = null;
291 String type = "pom";
292 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
293
294 assertLayout( path, groupId, artifactId, version, classifier, type );
295 }
296
297
298
299
300 public void testBadSnapshotWithoutReleasePart()
301 {
302 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
303 "snapshot version without release part");
304 }
305
306
307
308
309
310 public void testClassifiedSnapshotMavenTest()
311 throws LayoutException
312 {
313 String groupId = "a.group.id";
314 String artifactId = "artifact-id";
315 String version = "1.0-20070219.171202-34";
316 String classifier = "test-sources";
317 String type = "jar";
318 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
319
320 assertLayout( path, groupId, artifactId, version, classifier, type );
321 }
322
323
324
325
326
327 public void testGoodVersionKeywordInArtifactId()
328 throws LayoutException
329 {
330 String groupId = "maven";
331 String artifactId = "maven-test-plugin";
332 String version = "1.8.2";
333 String classifier = null;
334 String type = "pom";
335 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
336
337 assertLayout( path, groupId, artifactId, version, classifier, type );
338 }
339
340
341
342
343
344 public void testGoodDetectMavenTestPlugin()
345 throws LayoutException
346 {
347 String groupId = "maven";
348 String artifactId = "maven-test-plugin";
349 String version = "1.8.2";
350 String classifier = null;
351 String type = "maven-plugin";
352 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
353
354 assertLayout( path, groupId, artifactId, version, classifier, type );
355 }
356
357
358
359
360 public void testGoodDetectCoberturaMavenPlugin()
361 throws LayoutException
362 {
363 String groupId = "org.codehaus.mojo";
364 String artifactId = "cobertura-maven-plugin";
365 String version = "2.1";
366 String classifier = null;
367 String type = "maven-plugin";
368 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
369
370 assertLayout( path, groupId, artifactId, version, classifier, type );
371 }
372
373 public void testToArtifactOnEmptyPath()
374 {
375 try
376 {
377 parser.toArtifactReference( "" );
378 fail( "Should have failed due to empty path." );
379 }
380 catch ( LayoutException e )
381 {
382
383 }
384 }
385
386 public void testToArtifactOnNullPath()
387 {
388 try
389 {
390 parser.toArtifactReference( null );
391 fail( "Should have failed due to null path." );
392 }
393 catch ( LayoutException e )
394 {
395
396 }
397 }
398
399 public void testToArtifactReferenceOnEmptyPath()
400 {
401 try
402 {
403 parser.toArtifactReference( "" );
404 fail( "Should have failed due to empty path." );
405 }
406 catch ( LayoutException e )
407 {
408
409 }
410 }
411
412 public void testToArtifactReferenceOnNullPath()
413 {
414 try
415 {
416 parser.toArtifactReference( null );
417 fail( "Should have failed due to null path." );
418 }
419 catch ( LayoutException e )
420 {
421
422 }
423 }
424
425
426
427
428 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
429 String type )
430 throws LayoutException
431 {
432
433 ArtifactReference testReference = parser.toArtifactReference( path );
434 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
435 }
436
437 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
438 String version, String classifier, String type )
439 {
440 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
441 + ":" + type;
442
443 assertNotNull( expectedId + " - Should not be null.", actualReference );
444
445 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
446 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
447 if ( StringUtils.isNotBlank( classifier ) )
448 {
449 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
450 }
451 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
452 assertEquals( expectedId + " - Type", type, actualReference.getType() );
453 }
454
455 private void assertBadPath( String path, String reason )
456 {
457 try
458 {
459 parser.toArtifactReference( path );
460 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
461 }
462 catch ( LayoutException e )
463 {
464
465 }
466 }
467 }