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