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