1 package org.apache.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.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.LegacyArtifactPath;
25 import org.apache.archiva.model.ArtifactReference;
26 import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
27 import org.apache.archiva.repository.layout.LayoutException;
28 import org.junit.Before;
29 import org.junit.Test;
31 import javax.inject.Inject;
32 import javax.inject.Named;
34 import static org.junit.Assert.*;
37 * LegacyPathParserTest
41 public class LegacyPathParserTest
42 extends AbstractRepositoryLayerTestCase
44 private LegacyPathParser parser;
47 @Named( value = "archivaConfiguration#default" )
48 ArchivaConfiguration config;
51 * Configure the ArchivaConfiguration
58 parser = new LegacyPathParser( config );
59 LegacyArtifactPath jaxen = new LegacyArtifactPath();
60 jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
61 jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
62 config.getConfiguration().addLegacyArtifactPath( jaxen );
63 parser.configuration = config;
67 public void testBadPathArtifactIdMissingA()
69 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
73 public void testBadPathArtifactIdMissingB()
75 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
79 public void testBadPathMissingType()
81 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
85 public void testBadPathTooShort()
88 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
92 public void testBadPathWrongPackageExtension()
94 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
98 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
101 public void testGoodButDualExtensions()
102 throws LayoutException
104 String groupId = "org.project";
105 String artifactId = "example-presentation";
106 String version = "3.2.xml";
107 String type = "distribution-zip";
108 String path = "org.project/zips/example-presentation-3.2.xml.zip";
110 assertLayout( path, groupId, artifactId, version, null, type );
114 * [MRM-432] Oddball version spec.
115 * Example of an oddball / unusual version spec.
117 * @throws LayoutException
120 public void testGoodButOddVersionSpecGanymedSsh2()
121 throws LayoutException
123 String groupId = "ch.ethz.ganymed";
124 String artifactId = "ganymed-ssh2";
125 String version = "build210";
127 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
129 assertLayout( path, groupId, artifactId, version, null, type );
133 * [MRM-432] Oddball version spec.
134 * Example of an oddball / unusual version spec.
136 * @throws LayoutException
139 public void testGoodButOddVersionSpecJavaxComm()
140 throws LayoutException
142 String groupId = "javax";
143 String artifactId = "comm";
144 String version = "3.0-u1";
146 String path = "javax/jars/comm-3.0-u1.jar";
148 assertLayout( path, groupId, artifactId, version, null, type );
152 * [MRM-432] Oddball version spec.
153 * Example of an oddball / unusual version spec.
155 * @throws LayoutException
158 public void testGoodButOddVersionSpecJavaxPersistence()
159 throws LayoutException
161 String groupId = "javax.persistence";
162 String artifactId = "ejb";
163 String version = "3.0-public_review";
165 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
168 * The version id of "public_review" can cause problems. is it part of
169 * the version spec? or the classifier?
172 assertLayout( path, groupId, artifactId, version, null, type );
176 public void testGoodCommonsLang()
177 throws LayoutException
179 String groupId = "commons-lang";
180 String artifactId = "commons-lang";
181 String version = "2.1";
183 String path = "commons-lang/jars/commons-lang-2.1.jar";
185 assertLayout( path, groupId, artifactId, version, null, type );
189 public void testGoodDerby()
190 throws LayoutException
192 String groupId = "org.apache.derby";
193 String artifactId = "derby";
194 String version = "10.2.2.0";
196 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
198 assertLayout( path, groupId, artifactId, version, null, type );
202 * Test the ejb-client type spec.
203 * Type specs are not a 1 to 1 map to the extension.
204 * This tests that effect.
205 * @throws LayoutException
207 /* TODO: Re-enabled in the future.
208 public void testGoodFooEjbClient()
209 throws LayoutException
211 String groupId = "com.foo";
212 String artifactId = "foo-client";
213 String version = "1.0";
214 String type = "ejb"; // oddball type-spec (should result in jar extension)
215 String path = "com.foo/ejbs/foo-client-1.0.jar";
217 assertLayout( path, groupId, artifactId, version, classifier, type );
222 * Test the classifier.
224 * @throws LayoutException
227 public void testGoodFooLibJavadoc()
228 throws LayoutException
230 String groupId = "com.foo.lib";
231 String artifactId = "foo-lib";
232 String version = "2.1-alpha-1";
233 String type = "javadoc";
234 String classifier = "javadoc";
235 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
237 assertLayout( path, groupId, artifactId, version, classifier, type );
239 assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1",
240 "javadoc", "javadoc" );
244 * Test the classifier, and java-source type spec.
246 * @throws LayoutException
249 public void testGoodFooLibSources()
250 throws LayoutException
252 String groupId = "com.foo.lib";
253 String artifactId = "foo-lib";
254 String version = "2.1-alpha-1";
255 String type = "java-source"; // oddball type-spec (should result in jar extension)
256 String classifier = "sources";
257 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
259 assertLayout( path, groupId, artifactId, version, classifier, type );
263 * Test the classifier, and java-source type spec.
265 * @throws LayoutException
268 public void testBadClassifierFooLibSources()
269 throws LayoutException
271 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1.jar", "missing required classifier" );
272 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-javadoc.jar", "incorrect classifier" );
273 assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-other.jar", "incorrect classifier" );
277 * Test the classifier, and java-source type spec.
279 * @throws LayoutException
282 public void testGoodFooLibTestSources()
283 throws LayoutException
285 String groupId = "com.foo.lib";
286 String artifactId = "foo-lib";
287 String version = "2.1-alpha-1-test-sources";
289 String classifier = null; // we can't parse this type of classifier in legacy format
290 String path = "com.foo.lib/jars/foo-lib-2.1-alpha-1-test-sources.jar";
292 assertLayout( path, groupId, artifactId, version, classifier, type );
296 public void testGoodFooTool()
297 throws LayoutException
299 String groupId = "com.foo";
300 String artifactId = "foo-tool";
301 String version = "1.0";
303 String path = "com.foo/jars/foo-tool-1.0.jar";
305 assertLayout( path, groupId, artifactId, version, null, type );
309 public void testGoodGeronimoEjbSpec()
310 throws LayoutException
312 String groupId = "org.apache.geronimo.specs";
313 String artifactId = "geronimo-ejb_2.1_spec";
314 String version = "1.0.1";
316 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
318 assertLayout( path, groupId, artifactId, version, null, type );
322 public void testGoodLdapClientsPom()
323 throws LayoutException
325 String groupId = "directory-clients";
326 String artifactId = "ldap-clients";
327 String version = "0.9.1-SNAPSHOT";
329 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
331 assertLayout( path, groupId, artifactId, version, null, type );
335 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
337 * @throws LayoutException
340 public void testGoodSnapshotMavenTest()
341 throws LayoutException
343 String groupId = "org.apache.archiva.test";
344 String artifactId = "redonkulous";
345 String version = "3.1-beta-1-20050831.101112-42";
347 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
349 assertLayout( path, groupId, artifactId, version, null, type );
353 * [MRM-519] version identifiers within filename cause misidentification of version.
354 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
357 public void testGoodVersionKeywordInArtifactId()
358 throws LayoutException
360 String groupId = "maven";
361 String artifactId = "maven-test-plugin";
362 String version = "1.8.2";
365 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
367 assertLayout( path, groupId, artifactId, version, null, type );
371 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
372 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
375 public void testGoodDetectPluginMavenTest()
376 throws LayoutException
378 String groupId = "maven";
379 String artifactId = "maven-test-plugin";
380 String version = "1.8.2";
381 String type = "maven-one-plugin";
382 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
384 assertLayout( path, groupId, artifactId, version, null, type );
388 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
391 public void testGoodDetectPluginAvalonMeta()
392 throws LayoutException
394 String groupId = "avalon-meta";
395 String artifactId = "avalon-meta-plugin";
396 String version = "1.1";
397 String type = "maven-one-plugin";
398 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
400 assertLayout( path, groupId, artifactId, version, null, type );
404 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
407 public void testGoodDetectPluginCactusMaven()
408 throws LayoutException
410 String groupId = "cactus";
411 String artifactId = "cactus-maven";
412 String version = "1.7dev-20040815";
413 String type = "maven-one-plugin";
414 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
416 assertLayout( path, groupId, artifactId, version, null, type );
420 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
423 public void testGoodDetectPluginGeronimoPackaging()
424 throws LayoutException
426 String groupId = "geronimo";
427 String artifactId = "geronimo-packaging-plugin";
428 String version = "1.0.1";
429 String type = "maven-one-plugin";
430 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
432 assertLayout( path, groupId, artifactId, version, null, type );
436 * [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution
441 public void testCustomExceptionsInArtifactResolution()
442 throws LayoutException
444 String groupId = "jaxen";
445 String artifactId = "jaxen";
446 String version = "1.0-FCS";
448 String classifier = "full";
449 String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
451 assertLayout( path, groupId, artifactId, version, classifier, type );
455 * Perform a path to artifact reference lookup, and verify the results.
457 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
459 throws LayoutException
461 // Path to Artifact Reference.
462 ArtifactReference testReference = parser.toArtifactReference( path );
463 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
466 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
467 String version, String classifier, String type )
470 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
472 assertNotNull( expectedId + " - Should not be null.", actualReference );
474 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
475 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
476 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
477 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
478 assertEquals( expectedId + " - Type", type, actualReference.getType() );
481 protected void assertBadPath( String path, String reason )
485 parser.toArtifactReference( path );
487 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
489 catch ( LayoutException e )