1 package org.apache.maven.archiva.repository.content;
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.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.LegacyArtifactPath;
26 import org.apache.maven.archiva.model.ArtifactReference;
27 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
28 import org.apache.maven.archiva.repository.layout.LayoutException;
31 * LegacyPathParserTest
33 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 public class LegacyPathParserTest
37 extends AbstractRepositoryLayerTestCase
39 private LegacyPathParser parser = new LegacyPathParser();
42 * Configure the ArchivaConfiguration
44 * @see org.codehaus.plexus.PlexusTestCase#setUp()
46 protected void setUp()
50 ArchivaConfiguration config = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
51 LegacyArtifactPath jaxen = new LegacyArtifactPath();
52 jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
53 jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
54 config.getConfiguration().addLegacyArtifactPath( jaxen );
55 parser.configuration = config;
59 public void testBadPathArtifactIdMissingA()
61 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
64 public void testBadPathArtifactIdMissingB()
66 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
69 public void testBadPathMissingType()
71 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
74 public void testBadPathTooShort()
77 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
80 public void testBadPathWrongPackageExtension()
82 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
86 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
88 public void testGoodButDualExtensions()
89 throws LayoutException
91 String groupId = "org.project";
92 String artifactId = "example-presentation";
93 String version = "3.2.xml";
94 String type = "distribution-zip";
95 String path = "org.project/zips/example-presentation-3.2.xml.zip";
97 assertLayout( path, groupId, artifactId, version, null, type );
101 * [MRM-432] Oddball version spec.
102 * Example of an oddball / unusual version spec.
103 * @throws LayoutException
105 public void testGoodButOddVersionSpecGanymedSsh2()
106 throws LayoutException
108 String groupId = "ch.ethz.ganymed";
109 String artifactId = "ganymed-ssh2";
110 String version = "build210";
112 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
114 assertLayout( path, groupId, artifactId, version, null, type );
118 * [MRM-432] Oddball version spec.
119 * Example of an oddball / unusual version spec.
120 * @throws LayoutException
122 public void testGoodButOddVersionSpecJavaxComm()
123 throws LayoutException
125 String groupId = "javax";
126 String artifactId = "comm";
127 String version = "3.0-u1";
129 String path = "javax/jars/comm-3.0-u1.jar";
131 assertLayout( path, groupId, artifactId, version, null, type );
135 * [MRM-432] Oddball version spec.
136 * Example of an oddball / unusual version spec.
137 * @throws LayoutException
139 public void testGoodButOddVersionSpecJavaxPersistence()
140 throws LayoutException
142 String groupId = "javax.persistence";
143 String artifactId = "ejb";
144 String version = "3.0-public_review";
146 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
149 * The version id of "public_review" can cause problems. is it part of
150 * the version spec? or the classifier?
153 assertLayout( path, groupId, artifactId, version, null, type );
156 public void testGoodCommonsLang()
157 throws LayoutException
159 String groupId = "commons-lang";
160 String artifactId = "commons-lang";
161 String version = "2.1";
163 String path = "commons-lang/jars/commons-lang-2.1.jar";
165 assertLayout( path, groupId, artifactId, version, null, type );
168 public void testGoodDerby()
169 throws LayoutException
171 String groupId = "org.apache.derby";
172 String artifactId = "derby";
173 String version = "10.2.2.0";
175 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
177 assertLayout( path, groupId, artifactId, version, null, type );
181 * Test the ejb-client type spec.
182 * Type specs are not a 1 to 1 map to the extension.
183 * This tests that effect.
184 * @throws LayoutException
186 /* TODO: Re-enabled in the future.
187 public void testGoodFooEjbClient()
188 throws LayoutException
190 String groupId = "com.foo";
191 String artifactId = "foo-client";
192 String version = "1.0";
193 String type = "ejb"; // oddball type-spec (should result in jar extension)
194 String path = "com.foo/ejbs/foo-client-1.0.jar";
196 assertLayout( path, groupId, artifactId, version, classifier, type );
201 * Test the classifier.
202 * @throws LayoutException
204 public void testGoodFooLibJavadoc()
205 throws LayoutException
207 String groupId = "com.foo.lib";
208 String artifactId = "foo-lib";
209 String version = "2.1-alpha-1";
210 String type = "javadoc";
211 String classifier = "javadoc";
212 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
214 assertLayout( path, groupId, artifactId, version, classifier, type );
218 * Test the classifier, and java-source type spec.
219 * @throws LayoutException
221 public void testGoodFooLibSources()
222 throws LayoutException
224 String groupId = "com.foo.lib";
225 String artifactId = "foo-lib";
226 String version = "2.1-alpha-1";
227 String type = "java-source"; // oddball type-spec (should result in jar extension)
228 String classifier= "sources";
229 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
231 assertLayout( path, groupId, artifactId, version, classifier, type );
234 public void testGoodFooTool()
235 throws LayoutException
237 String groupId = "com.foo";
238 String artifactId = "foo-tool";
239 String version = "1.0";
241 String path = "com.foo/jars/foo-tool-1.0.jar";
243 assertLayout( path, groupId, artifactId, version, null, type );
246 public void testGoodGeronimoEjbSpec()
247 throws LayoutException
249 String groupId = "org.apache.geronimo.specs";
250 String artifactId = "geronimo-ejb_2.1_spec";
251 String version = "1.0.1";
253 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
255 assertLayout( path, groupId, artifactId, version, null, type );
258 public void testGoodLdapClientsPom()
259 throws LayoutException
261 String groupId = "directory-clients";
262 String artifactId = "ldap-clients";
263 String version = "0.9.1-SNAPSHOT";
265 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
267 assertLayout( path, groupId, artifactId, version, null, type );
271 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
272 * @throws LayoutException
274 public void testGoodSnapshotMavenTest()
275 throws LayoutException
277 String groupId = "org.apache.archiva.test";
278 String artifactId = "redonkulous";
279 String version = "3.1-beta-1-20050831.101112-42";
281 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
283 assertLayout( path, groupId, artifactId, version, null, type );
287 * [MRM-519] version identifiers within filename cause misidentification of version.
288 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
290 public void testGoodVersionKeywordInArtifactId()
291 throws LayoutException
293 String groupId = "maven";
294 String artifactId = "maven-test-plugin";
295 String version = "1.8.2";
298 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
300 assertLayout( path, groupId, artifactId, version, null, type );
304 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
305 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
307 public void testGoodDetectPluginMavenTest()
308 throws LayoutException
310 String groupId = "maven";
311 String artifactId = "maven-test-plugin";
312 String version = "1.8.2";
313 String type = "maven-plugin";
314 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
316 assertLayout( path, groupId, artifactId, version, null, type );
320 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
322 public void testGoodDetectPluginAvalonMeta()
323 throws LayoutException
325 String groupId = "avalon-meta";
326 String artifactId = "avalon-meta-plugin";
327 String version = "1.1";
328 String type = "maven-plugin";
329 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
331 assertLayout( path, groupId, artifactId, version, null, type );
335 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
337 public void testGoodDetectPluginCactusMaven()
338 throws LayoutException
340 String groupId = "cactus";
341 String artifactId = "cactus-maven";
342 String version = "1.7dev-20040815";
343 String type = "maven-plugin";
344 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
346 assertLayout( path, groupId, artifactId, version, null, type );
350 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
352 public void testGoodDetectPluginGeronimoPackaging()
353 throws LayoutException
355 String groupId = "geronimo";
356 String artifactId = "geronimo-packaging-plugin";
357 String version = "1.0.1";
358 String type = "maven-plugin";
359 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
361 assertLayout( path, groupId, artifactId, version, null, type );
365 * [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution
368 public void testCustomExceptionsInArtifactResolution()
369 throws LayoutException
371 String groupId = "jaxen";
372 String artifactId = "jaxen";
373 String version = "1.0-FCS";
375 String classifier = "full";
376 String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
378 assertLayout( path, groupId, artifactId, version, classifier, type );
382 * Perform a path to artifact reference lookup, and verify the results.
384 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
385 throws LayoutException
387 // Path to Artifact Reference.
388 ArtifactReference testReference = parser.toArtifactReference( path );
389 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
392 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
393 String version, String classifier, String type )
395 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
397 assertNotNull( expectedId + " - Should not be null.", actualReference );
399 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
400 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
401 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
402 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
403 assertEquals( expectedId + " - Type", type, actualReference.getType() );
406 protected void assertBadPath( String path, String reason )
410 parser.toArtifactReference( path );
411 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
413 catch ( LayoutException e )