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
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;
28 * DefaultPathParserTest
32 public class DefaultPathParserTest
33 extends AbstractRepositoryLayerTestCase
35 private PathParser parser = new DefaultPathParser();
37 public void testBadPathMissingType()
39 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
42 public void testBadPathReleaseInSnapshotDir()
44 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
47 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
49 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
50 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
53 public void testBadPathTooShort()
55 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
58 public void testBadPathVersionMismatchA()
60 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
63 public void testBadPathVersionMismatchB()
65 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
68 public void testBadPathWrongArtifactId()
70 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
71 "wrong artifact id" );
75 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
77 public void testGoodButDualExtensions()
78 throws LayoutException
80 String groupId = "org.project";
81 String artifactId = "example-presentation";
82 String version = "3.2";
83 String classifier = null;
84 String type = "xml.zip";
85 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
87 assertLayout( path, groupId, artifactId, version, classifier, type );
91 * [MRM-432] Oddball version spec.
92 * Example of an oddball / unusual version spec.
93 * @throws LayoutException
95 public void testGoodButOddVersionSpecGanymedSsh2()
96 throws LayoutException
98 String groupId = "ch.ethz.ganymed";
99 String artifactId = "ganymed-ssh2";
100 String version = "build210";
101 String classifier = null;
103 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
105 assertLayout( path, groupId, artifactId, version, classifier, type );
109 * [MRM-432] Oddball version spec.
110 * Example of an oddball / unusual version spec.
111 * @throws LayoutException
113 public void testGoodButOddVersionSpecJavaxComm()
114 throws LayoutException
116 String groupId = "javax";
117 String artifactId = "comm";
118 String version = "3.0-u1";
119 String classifier = null;
121 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
123 assertLayout( path, groupId, artifactId, version, classifier, type );
127 * Test the ejb-client type spec.
128 * Type specs are not a 1 to 1 map to the extension.
129 * This tests that effect.
130 * @throws LayoutException
132 /* TODO: Re-enabled in the future.
133 public void testGoodFooEjbClient()
134 throws LayoutException
136 String groupId = "com.foo";
137 String artifactId = "foo-client";
138 String version = "1.0";
139 String classifier = null;
140 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
141 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
143 assertLayout( path, groupId, artifactId, version, classifier, type );
148 * [MRM-432] Oddball version spec.
149 * Example of an oddball / unusual version spec.
150 * @throws LayoutException
152 public void testGoodButOddVersionSpecJavaxPersistence()
153 throws LayoutException
155 String groupId = "javax.persistence";
156 String artifactId = "ejb";
157 String version = "3.0-public_review";
158 String classifier = null;
160 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
163 * The version id of "public_review" can cause problems. is it part of
164 * the version spec? or the classifier?
165 * Since the path spec below shows it in the path, then it is really
166 * part of the version spec.
169 assertLayout( path, groupId, artifactId, version, classifier, type );
172 public void testGoodComFooTool()
173 throws LayoutException
175 String groupId = "com.foo";
176 String artifactId = "foo-tool";
177 String version = "1.0";
178 String classifier = null;
180 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
182 assertLayout( path, groupId, artifactId, version, classifier, type );
185 public void testGoodCommonsLang()
186 throws LayoutException
188 String groupId = "commons-lang";
189 String artifactId = "commons-lang";
190 String version = "2.1";
191 String classifier = null;
193 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
195 assertLayout( path, groupId, artifactId, version, classifier, type );
199 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
201 public void testGoodDashedArtifactId()
202 throws LayoutException
204 String groupId = "test.maven-arch";
205 String artifactId = "test-arch";
206 String version = "2.0.3-SNAPSHOT";
207 String classifier = null;
209 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
211 assertLayout( path, groupId, artifactId, version, classifier, type );
215 * It may seem odd, but this is a valid artifact.
217 public void testGoodDotNotationArtifactId()
218 throws LayoutException
220 String groupId = "com.company.department";
221 String artifactId = "com.company.department";
222 String version = "0.2";
223 String classifier = null;
225 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
227 assertLayout( path, groupId, artifactId, version, classifier, type );
231 * It may seem odd, but this is a valid artifact.
233 public void testGoodDotNotationSameGroupIdAndArtifactId()
234 throws LayoutException
236 String groupId = "com.company.department";
237 String artifactId = "com.company.department.project";
238 String version = "0.3";
239 String classifier = null;
241 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
243 assertLayout( path, groupId, artifactId, version, classifier, type );
247 * Test the classifier, and java-source type spec.
248 * @throws LayoutException
250 public void testGoodFooLibSources()
251 throws LayoutException
253 String groupId = "com.foo.lib";
254 String artifactId = "foo-lib";
255 String version = "2.1-alpha-1";
256 String classifier = "sources";
257 String type = "java-source"; // oddball type-spec (should result in jar extension)
258 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
260 assertLayout( path, groupId, artifactId, version, classifier, type );
264 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
265 * @throws LayoutException
267 public void testGoodSnapshotMavenTest()
268 throws LayoutException
270 String groupId = "org.apache.archiva.test";
271 String artifactId = "redonkulous";
272 String version = "3.1-beta-1-20050831.101112-42";
273 String classifier = null;
275 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
277 assertLayout( path, groupId, artifactId, version, classifier, type );
281 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
282 * @throws LayoutException
284 public void testGoodLongSnapshotMavenTest()
285 throws LayoutException
287 String groupId = "a.group.id";
288 String artifactId = "artifact-id";
289 String version = "1.0-abc-1.1-20080221.062205-9";
290 String classifier = null;
292 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
294 assertLayout( path, groupId, artifactId, version, classifier, type );
298 * A timestamped versioned artifact but without release version part. Like on axiom trunk.
300 public void testBadSnapshotWithoutReleasePart()
302 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
303 "snapshot version without release part");
307 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
308 * @throws LayoutException
310 public void testClassifiedSnapshotMavenTest()
311 throws LayoutException
313 String groupId = "a.group.id";
314 String artifactId = "artifact-id";
315 String version = "1.0-20070219.171202-34";
316 String classifier = "test-sources";
318 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
320 assertLayout( path, groupId, artifactId, version, classifier, type );
324 * [MRM-519] version identifiers within filename cause misidentification of version.
325 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
327 public void testGoodVersionKeywordInArtifactId()
328 throws LayoutException
330 String groupId = "maven";
331 String artifactId = "maven-test-plugin";
332 String version = "1.8.2";
333 String classifier = null;
335 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
337 assertLayout( path, groupId, artifactId, version, classifier, type );
341 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
342 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
344 public void testGoodDetectMavenTestPlugin()
345 throws LayoutException
347 String groupId = "maven";
348 String artifactId = "maven-test-plugin";
349 String version = "1.8.2";
350 String classifier = null;
351 String type = "maven-plugin";
352 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
354 assertLayout( path, groupId, artifactId, version, classifier, type );
358 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
360 public void testGoodDetectCoberturaMavenPlugin()
361 throws LayoutException
363 String groupId = "org.codehaus.mojo";
364 String artifactId = "cobertura-maven-plugin";
365 String version = "2.1";
366 String classifier = null;
367 String type = "maven-plugin";
368 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
370 assertLayout( path, groupId, artifactId, version, classifier, type );
373 public void testToArtifactOnEmptyPath()
377 parser.toArtifactReference( "" );
378 fail( "Should have failed due to empty path." );
380 catch ( LayoutException e )
386 public void testToArtifactOnNullPath()
390 parser.toArtifactReference( null );
391 fail( "Should have failed due to null path." );
393 catch ( LayoutException e )
399 public void testToArtifactReferenceOnEmptyPath()
403 parser.toArtifactReference( "" );
404 fail( "Should have failed due to empty path." );
406 catch ( LayoutException e )
412 public void testToArtifactReferenceOnNullPath()
416 parser.toArtifactReference( null );
417 fail( "Should have failed due to null path." );
419 catch ( LayoutException e )
426 * Perform a path to artifact reference lookup, and verify the results.
428 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
430 throws LayoutException
432 // Path to Artifact Reference.
433 ArtifactReference testReference = parser.toArtifactReference( path );
434 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
437 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
438 String version, String classifier, String type )
440 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
443 assertNotNull( expectedId + " - Should not be null.", actualReference );
445 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
446 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
447 if ( StringUtils.isNotBlank( classifier ) )
449 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
451 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
452 assertEquals( expectedId + " - Type", type, actualReference.getType() );
455 private void assertBadPath( String path, String reason )
459 parser.toArtifactReference( path );
460 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
462 catch ( LayoutException e )