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
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.LegacyArtifactPath;
25 import org.apache.maven.archiva.model.ArtifactReference;
26 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
27 import org.apache.maven.archiva.repository.layout.LayoutException;
28
29
30
31
32
33
34 public class LegacyPathParserTest
35 extends AbstractRepositoryLayerTestCase
36 {
37 private LegacyPathParser parser = new LegacyPathParser();
38
39
40
41
42
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48 ArchivaConfiguration config = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
49 LegacyArtifactPath jaxen = new LegacyArtifactPath();
50 jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
51 jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
52 config.getConfiguration().addLegacyArtifactPath( jaxen );
53 parser.configuration = config;
54 }
55
56
57 public void testBadPathArtifactIdMissingA()
58 {
59 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
60 }
61
62 public void testBadPathArtifactIdMissingB()
63 {
64 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
65 }
66
67 public void testBadPathMissingType()
68 {
69 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
70 }
71
72 public void testBadPathTooShort()
73 {
74
75 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
76 }
77
78 public void testBadPathWrongPackageExtension()
79 {
80 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
81 }
82
83
84
85
86 public void testGoodButDualExtensions()
87 throws LayoutException
88 {
89 String groupId = "org.project";
90 String artifactId = "example-presentation";
91 String version = "3.2.xml";
92 String type = "distribution-zip";
93 String path = "org.project/zips/example-presentation-3.2.xml.zip";
94
95 assertLayout( path, groupId, artifactId, version, null, type );
96 }
97
98
99
100
101
102
103 public void testGoodButOddVersionSpecGanymedSsh2()
104 throws LayoutException
105 {
106 String groupId = "ch.ethz.ganymed";
107 String artifactId = "ganymed-ssh2";
108 String version = "build210";
109 String type = "jar";
110 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
111
112 assertLayout( path, groupId, artifactId, version, null, type );
113 }
114
115
116
117
118
119
120 public void testGoodButOddVersionSpecJavaxComm()
121 throws LayoutException
122 {
123 String groupId = "javax";
124 String artifactId = "comm";
125 String version = "3.0-u1";
126 String type = "jar";
127 String path = "javax/jars/comm-3.0-u1.jar";
128
129 assertLayout( path, groupId, artifactId, version, null, type );
130 }
131
132
133
134
135
136
137 public void testGoodButOddVersionSpecJavaxPersistence()
138 throws LayoutException
139 {
140 String groupId = "javax.persistence";
141 String artifactId = "ejb";
142 String version = "3.0-public_review";
143 String type = "jar";
144 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
145
146
147
148
149
150
151 assertLayout( path, groupId, artifactId, version, null, type );
152 }
153
154 public void testGoodCommonsLang()
155 throws LayoutException
156 {
157 String groupId = "commons-lang";
158 String artifactId = "commons-lang";
159 String version = "2.1";
160 String type = "jar";
161 String path = "commons-lang/jars/commons-lang-2.1.jar";
162
163 assertLayout( path, groupId, artifactId, version, null, type );
164 }
165
166 public void testGoodDerby()
167 throws LayoutException
168 {
169 String groupId = "org.apache.derby";
170 String artifactId = "derby";
171 String version = "10.2.2.0";
172 String type = "jar";
173 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
174
175 assertLayout( path, groupId, artifactId, version, null, type );
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202 public void testGoodFooLibJavadoc()
203 throws LayoutException
204 {
205 String groupId = "com.foo.lib";
206 String artifactId = "foo-lib";
207 String version = "2.1-alpha-1";
208 String type = "javadoc";
209 String classifier = "javadoc";
210 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
211
212 assertLayout( path, groupId, artifactId, version, classifier, type );
213
214 assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "javadoc" );
215 }
216
217
218
219
220
221 public void testGoodFooLibSources()
222 throws LayoutException
223 {
224 String groupId = "com.foo.lib";
225 String artifactId = "foo-lib";
226 String version = "2.1-alpha-1";
227 String type = "java-source";
228 String classifier= "sources";
229 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
230
231 assertLayout( path, groupId, artifactId, version, classifier, type );
232 }
233
234
235
236
237
238 public void testBadClassifierFooLibSources()
239 throws LayoutException
240 {
241 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1.jar", "missing required classifier" );
242 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-javadoc.jar", "incorrect classifier" );
243 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-other.jar", "incorrect classifier" );
244 }
245
246
247
248
249
250 public void testGoodFooLibTestSources()
251 throws LayoutException
252 {
253 String groupId = "com.foo.lib";
254 String artifactId = "foo-lib";
255 String version = "2.1-alpha-1-test-sources";
256 String type = "jar";
257 String classifier = null;
258 String path = "com.foo.lib/jars/foo-lib-2.1-alpha-1-test-sources.jar";
259
260 assertLayout( path, groupId, artifactId, version, classifier, type );
261 }
262
263 public void testGoodFooTool()
264 throws LayoutException
265 {
266 String groupId = "com.foo";
267 String artifactId = "foo-tool";
268 String version = "1.0";
269 String type = "jar";
270 String path = "com.foo/jars/foo-tool-1.0.jar";
271
272 assertLayout( path, groupId, artifactId, version, null, type );
273 }
274
275 public void testGoodGeronimoEjbSpec()
276 throws LayoutException
277 {
278 String groupId = "org.apache.geronimo.specs";
279 String artifactId = "geronimo-ejb_2.1_spec";
280 String version = "1.0.1";
281 String type = "jar";
282 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
283
284 assertLayout( path, groupId, artifactId, version, null, type );
285 }
286
287 public void testGoodLdapClientsPom()
288 throws LayoutException
289 {
290 String groupId = "directory-clients";
291 String artifactId = "ldap-clients";
292 String version = "0.9.1-SNAPSHOT";
293 String type = "pom";
294 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
295
296 assertLayout( path, groupId, artifactId, version, null, type );
297 }
298
299
300
301
302
303 public void testGoodSnapshotMavenTest()
304 throws LayoutException
305 {
306 String groupId = "org.apache.archiva.test";
307 String artifactId = "redonkulous";
308 String version = "3.1-beta-1-20050831.101112-42";
309 String type = "jar";
310 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
311
312 assertLayout( path, groupId, artifactId, version, null, type );
313 }
314
315
316
317
318
319 public void testGoodVersionKeywordInArtifactId()
320 throws LayoutException
321 {
322 String groupId = "maven";
323 String artifactId = "maven-test-plugin";
324 String version = "1.8.2";
325 String type = "pom";
326
327 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
328
329 assertLayout( path, groupId, artifactId, version, null, type );
330 }
331
332
333
334
335
336 public void testGoodDetectPluginMavenTest()
337 throws LayoutException
338 {
339 String groupId = "maven";
340 String artifactId = "maven-test-plugin";
341 String version = "1.8.2";
342 String type = "maven-one-plugin";
343 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
344
345 assertLayout( path, groupId, artifactId, version, null, type );
346 }
347
348
349
350
351 public void testGoodDetectPluginAvalonMeta()
352 throws LayoutException
353 {
354 String groupId = "avalon-meta";
355 String artifactId = "avalon-meta-plugin";
356 String version = "1.1";
357 String type = "maven-one-plugin";
358 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
359
360 assertLayout( path, groupId, artifactId, version, null, type );
361 }
362
363
364
365
366 public void testGoodDetectPluginCactusMaven()
367 throws LayoutException
368 {
369 String groupId = "cactus";
370 String artifactId = "cactus-maven";
371 String version = "1.7dev-20040815";
372 String type = "maven-one-plugin";
373 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
374
375 assertLayout( path, groupId, artifactId, version, null, type );
376 }
377
378
379
380
381 public void testGoodDetectPluginGeronimoPackaging()
382 throws LayoutException
383 {
384 String groupId = "geronimo";
385 String artifactId = "geronimo-packaging-plugin";
386 String version = "1.0.1";
387 String type = "maven-one-plugin";
388 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
389
390 assertLayout( path, groupId, artifactId, version, null, type );
391 }
392
393
394
395
396
397 public void testCustomExceptionsInArtifactResolution()
398 throws LayoutException
399 {
400 String groupId = "jaxen";
401 String artifactId = "jaxen";
402 String version = "1.0-FCS";
403 String type = "jar";
404 String classifier = "full";
405 String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
406
407 assertLayout( path, groupId, artifactId, version, classifier, type );
408 }
409
410
411
412
413 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
414 throws LayoutException
415 {
416
417 ArtifactReference testReference = parser.toArtifactReference( path );
418 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
419 }
420
421 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
422 String version, String classifier, String type )
423 {
424 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
425
426 assertNotNull( expectedId + " - Should not be null.", actualReference );
427
428 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
429 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
430 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
431 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
432 assertEquals( expectedId + " - Type", type, actualReference.getType() );
433 }
434
435 protected void assertBadPath( String path, String reason )
436 {
437 try
438 {
439 parser.toArtifactReference( path );
440 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
441 }
442 catch ( LayoutException e )
443 {
444
445 }
446 }
447 }