1 package org.apache.archiva.repository.content.legacy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.LegacyArtifactPath;
25 import org.apache.archiva.model.ArtifactReference;
26 import org.apache.archiva.repository.layout.LayoutException;
27 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.springframework.test.context.ContextConfiguration;
33 import javax.inject.Inject;
34 import javax.inject.Named;
36 import static org.junit.Assert.*;
39 * LegacyPathParserTest
43 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
44 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
45 public class LegacyPathParserTest
47 private LegacyPathParser parser;
50 @Named( "archivaConfiguration#default" )
51 ArchivaConfiguration config;
54 * Configure the ArchivaConfiguration
61 parser = new LegacyPathParser( config );
62 LegacyArtifactPath jaxen = new LegacyArtifactPath();
63 jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
64 jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
65 config.getConfiguration().addLegacyArtifactPath( jaxen );
66 parser.configuration = config;
70 public void testBadPathArtifactIdMissingA()
72 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
76 public void testBadPathArtifactIdMissingB()
78 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
82 public void testBadPathMissingType()
84 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
88 public void testBadPathTooShort()
91 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
95 public void testBadPathWrongPackageExtension()
97 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
101 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
104 public void testGoodButDualExtensions()
105 throws LayoutException
107 String groupId = "org.project";
108 String artifactId = "example-presentation";
109 String version = "3.2.xml";
110 String type = "distribution-zip";
111 String path = "org.project/zips/example-presentation-3.2.xml.zip";
113 assertLayout( path, groupId, artifactId, version, null, type );
117 * [MRM-432] Oddball version spec.
118 * Example of an oddball / unusual version spec.
120 * @throws org.apache.archiva.repository.layout.LayoutException
123 public void testGoodButOddVersionSpecGanymedSsh2()
124 throws LayoutException
126 String groupId = "ch.ethz.ganymed";
127 String artifactId = "ganymed-ssh2";
128 String version = "build210";
130 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
132 assertLayout( path, groupId, artifactId, version, null, type );
136 * [MRM-432] Oddball version spec.
137 * Example of an oddball / unusual version spec.
139 * @throws org.apache.archiva.repository.layout.LayoutException
142 public void testGoodButOddVersionSpecJavaxComm()
143 throws LayoutException
145 String groupId = "javax";
146 String artifactId = "comm";
147 String version = "3.0-u1";
149 String path = "javax/jars/comm-3.0-u1.jar";
151 assertLayout( path, groupId, artifactId, version, null, type );
155 * [MRM-432] Oddball version spec.
156 * Example of an oddball / unusual version spec.
158 * @throws org.apache.archiva.repository.layout.LayoutException
161 public void testGoodButOddVersionSpecJavaxPersistence()
162 throws LayoutException
164 String groupId = "javax.persistence";
165 String artifactId = "ejb";
166 String version = "3.0-public_review";
168 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
171 * The version id of "public_review" can cause problems. is it part of
172 * the version spec? or the classifier?
175 assertLayout( path, groupId, artifactId, version, null, type );
179 public void testGoodCommonsLang()
180 throws LayoutException
182 String groupId = "commons-lang";
183 String artifactId = "commons-lang";
184 String version = "2.1";
186 String path = "commons-lang/jars/commons-lang-2.1.jar";
188 assertLayout( path, groupId, artifactId, version, null, type );
192 public void testGoodDerby()
193 throws LayoutException
195 String groupId = "org.apache.derby";
196 String artifactId = "derby";
197 String version = "10.2.2.0";
199 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
201 assertLayout( path, groupId, artifactId, version, null, type );
205 * Test the ejb-client type spec.
206 * Type specs are not a 1 to 1 map to the extension.
207 * This tests that effect.
208 * @throws org.apache.archiva.repository.layout.LayoutException
210 /* TODO: Re-enabled in the future.
211 public void testGoodFooEjbClient()
212 throws LayoutException
214 String groupId = "com.foo";
215 String artifactId = "foo-client";
216 String version = "1.0";
217 String type = "ejb"; // oddball type-spec (should result in jar extension)
218 String path = "com.foo/ejbs/foo-client-1.0.jar";
220 assertLayout( path, groupId, artifactId, version, classifier, type );
225 * Test the classifier.
227 * @throws org.apache.archiva.repository.layout.LayoutException
230 public void testGoodFooLibJavadoc()
231 throws LayoutException
233 String groupId = "com.foo.lib";
234 String artifactId = "foo-lib";
235 String version = "2.1-alpha-1";
236 String type = "javadoc";
237 String classifier = "javadoc";
238 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
240 assertLayout( path, groupId, artifactId, version, classifier, type );
242 assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1",
243 "javadoc", "javadoc" );
247 * Test the classifier, and java-source type spec.
249 * @throws org.apache.archiva.repository.layout.LayoutException
252 public void testGoodFooLibSources()
253 throws LayoutException
255 String groupId = "com.foo.lib";
256 String artifactId = "foo-lib";
257 String version = "2.1-alpha-1";
258 String type = "java-source"; // oddball type-spec (should result in jar extension)
259 String classifier = "sources";
260 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
262 assertLayout( path, groupId, artifactId, version, classifier, type );
266 * Test the classifier, and java-source type spec.
268 * @throws org.apache.archiva.repository.layout.LayoutException
271 public void testBadClassifierFooLibSources()
272 throws LayoutException
274 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1.jar", "missing required classifier" );
275 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-javadoc.jar", "incorrect classifier" );
276 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-other.jar", "incorrect classifier" );
280 * Test the classifier, and java-source type spec.
282 * @throws org.apache.archiva.repository.layout.LayoutException
285 public void testGoodFooLibTestSources()
286 throws LayoutException
288 String groupId = "com.foo.lib";
289 String artifactId = "foo-lib";
290 String version = "2.1-alpha-1-test-sources";
292 String classifier = null; // we can't parse this type of classifier in legacy format
293 String path = "com.foo.lib/jars/foo-lib-2.1-alpha-1-test-sources.jar";
295 assertLayout( path, groupId, artifactId, version, classifier, type );
299 public void testGoodFooTool()
300 throws LayoutException
302 String groupId = "com.foo";
303 String artifactId = "foo-tool";
304 String version = "1.0";
306 String path = "com.foo/jars/foo-tool-1.0.jar";
308 assertLayout( path, groupId, artifactId, version, null, type );
312 public void testGoodGeronimoEjbSpec()
313 throws LayoutException
315 String groupId = "org.apache.geronimo.specs";
316 String artifactId = "geronimo-ejb_2.1_spec";
317 String version = "1.0.1";
319 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
321 assertLayout( path, groupId, artifactId, version, null, type );
325 public void testGoodLdapClientsPom()
326 throws LayoutException
328 String groupId = "directory-clients";
329 String artifactId = "ldap-clients";
330 String version = "0.9.1-SNAPSHOT";
332 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
334 assertLayout( path, groupId, artifactId, version, null, type );
338 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
340 * @throws org.apache.archiva.repository.layout.LayoutException
343 public void testGoodSnapshotMavenTest()
344 throws LayoutException
346 String groupId = "org.apache.archiva.test";
347 String artifactId = "redonkulous";
348 String version = "3.1-beta-1-20050831.101112-42";
350 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
352 assertLayout( path, groupId, artifactId, version, null, type );
356 * [MRM-519] version identifiers within filename cause misidentification of version.
357 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
360 public void testGoodVersionKeywordInArtifactId()
361 throws LayoutException
363 String groupId = "maven";
364 String artifactId = "maven-test-plugin";
365 String version = "1.8.2";
368 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
370 assertLayout( path, groupId, artifactId, version, null, type );
374 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
375 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
378 public void testGoodDetectPluginMavenTest()
379 throws LayoutException
381 String groupId = "maven";
382 String artifactId = "maven-test-plugin";
383 String version = "1.8.2";
384 String type = "maven-one-plugin";
385 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
387 assertLayout( path, groupId, artifactId, version, null, type );
391 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
394 public void testGoodDetectPluginAvalonMeta()
395 throws LayoutException
397 String groupId = "avalon-meta";
398 String artifactId = "avalon-meta-plugin";
399 String version = "1.1";
400 String type = "maven-one-plugin";
401 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
403 assertLayout( path, groupId, artifactId, version, null, type );
407 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
410 public void testGoodDetectPluginCactusMaven()
411 throws LayoutException
413 String groupId = "cactus";
414 String artifactId = "cactus-maven";
415 String version = "1.7dev-20040815";
416 String type = "maven-one-plugin";
417 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
419 assertLayout( path, groupId, artifactId, version, null, type );
423 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
426 public void testGoodDetectPluginGeronimoPackaging()
427 throws LayoutException
429 String groupId = "geronimo";
430 String artifactId = "geronimo-packaging-plugin";
431 String version = "1.0.1";
432 String type = "maven-one-plugin";
433 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
435 assertLayout( path, groupId, artifactId, version, null, type );
439 * [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution
444 public void testCustomExceptionsInArtifactResolution()
445 throws LayoutException
447 String groupId = "jaxen";
448 String artifactId = "jaxen";
449 String version = "1.0-FCS";
451 String classifier = "full";
452 String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
454 assertLayout( path, groupId, artifactId, version, classifier, type );
458 * Perform a path to artifact reference lookup, and verify the results.
460 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
462 throws LayoutException
464 // Path to Artifact Reference.
465 ArtifactReference testReference = parser.toArtifactReference( path );
466 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
469 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
470 String version, String classifier, String type )
473 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
475 assertNotNull( expectedId + " - Should not be null.", actualReference );
477 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
478 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
479 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
480 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
481 assertEquals( expectedId + " - Type", type, actualReference.getType() );
484 protected void assertBadPath( String path, String reason )
488 parser.toArtifactReference( path );
490 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
492 catch ( LayoutException e )