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 );
198 public void testWindowsPathSeparator()
199 throws LayoutException
201 String groupId = "commons-lang";
202 String artifactId = "commons-lang";
203 String version = "2.1";
204 String classifier = null;
206 String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar";
208 assertLayout( path, groupId, artifactId, version, classifier, type );
212 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
214 public void testGoodDashedArtifactId()
215 throws LayoutException
217 String groupId = "test.maven-arch";
218 String artifactId = "test-arch";
219 String version = "2.0.3-SNAPSHOT";
220 String classifier = null;
222 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
224 assertLayout( path, groupId, artifactId, version, classifier, type );
228 * It may seem odd, but this is a valid artifact.
230 public void testGoodDotNotationArtifactId()
231 throws LayoutException
233 String groupId = "com.company.department";
234 String artifactId = "com.company.department";
235 String version = "0.2";
236 String classifier = null;
238 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
240 assertLayout( path, groupId, artifactId, version, classifier, type );
244 * It may seem odd, but this is a valid artifact.
246 public void testGoodDotNotationSameGroupIdAndArtifactId()
247 throws LayoutException
249 String groupId = "com.company.department";
250 String artifactId = "com.company.department.project";
251 String version = "0.3";
252 String classifier = null;
254 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
256 assertLayout( path, groupId, artifactId, version, classifier, type );
260 * Test the classifier, and java-source type spec.
261 * @throws LayoutException
263 public void testGoodFooLibSources()
264 throws LayoutException
266 String groupId = "com.foo.lib";
267 String artifactId = "foo-lib";
268 String version = "2.1-alpha-1";
269 String classifier = "sources";
270 String type = "java-source"; // oddball type-spec (should result in jar extension)
271 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
273 assertLayout( path, groupId, artifactId, version, classifier, type );
277 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
278 * @throws LayoutException
280 public void testGoodSnapshotMavenTest()
281 throws LayoutException
283 String groupId = "org.apache.archiva.test";
284 String artifactId = "redonkulous";
285 String version = "3.1-beta-1-20050831.101112-42";
286 String classifier = null;
288 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
290 assertLayout( path, groupId, artifactId, version, classifier, type );
294 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
295 * @throws LayoutException
297 public void testGoodLongSnapshotMavenTest()
298 throws LayoutException
300 String groupId = "a.group.id";
301 String artifactId = "artifact-id";
302 String version = "1.0-abc-1.1-20080221.062205-9";
303 String classifier = null;
305 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
307 assertLayout( path, groupId, artifactId, version, classifier, type );
311 * A timestamped versioned artifact but without release version part. Like on axiom trunk.
313 public void testBadSnapshotWithoutReleasePart()
315 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
316 "snapshot version without release part");
320 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
321 * @throws LayoutException
323 public void testClassifiedSnapshotMavenTest()
324 throws LayoutException
326 String groupId = "a.group.id";
327 String artifactId = "artifact-id";
328 String version = "1.0-20070219.171202-34";
329 String classifier = "test-sources";
331 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
333 assertLayout( path, groupId, artifactId, version, classifier, type );
337 * [MRM-519] version identifiers within filename cause misidentification of version.
338 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
340 public void testGoodVersionKeywordInArtifactId()
341 throws LayoutException
343 String groupId = "maven";
344 String artifactId = "maven-test-plugin";
345 String version = "1.8.2";
346 String classifier = null;
348 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
350 assertLayout( path, groupId, artifactId, version, classifier, type );
354 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
355 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
357 public void testGoodDetectMavenTestPlugin()
358 throws LayoutException
360 String groupId = "maven";
361 String artifactId = "maven-test-plugin";
362 String version = "1.8.2";
363 String classifier = null;
364 String type = "maven-plugin";
365 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
367 assertLayout( path, groupId, artifactId, version, classifier, type );
371 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
373 public void testGoodDetectCoberturaMavenPlugin()
374 throws LayoutException
376 String groupId = "org.codehaus.mojo";
377 String artifactId = "cobertura-maven-plugin";
378 String version = "2.1";
379 String classifier = null;
380 String type = "maven-plugin";
381 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
383 assertLayout( path, groupId, artifactId, version, classifier, type );
386 public void testToArtifactOnEmptyPath()
390 parser.toArtifactReference( "" );
391 fail( "Should have failed due to empty path." );
393 catch ( LayoutException e )
399 public void testToArtifactOnNullPath()
403 parser.toArtifactReference( null );
404 fail( "Should have failed due to null path." );
406 catch ( LayoutException e )
412 public void testToArtifactReferenceOnEmptyPath()
416 parser.toArtifactReference( "" );
417 fail( "Should have failed due to empty path." );
419 catch ( LayoutException e )
425 public void testToArtifactReferenceOnNullPath()
429 parser.toArtifactReference( null );
430 fail( "Should have failed due to null path." );
432 catch ( LayoutException e )
439 * Perform a path to artifact reference lookup, and verify the results.
441 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
443 throws LayoutException
445 // Path to Artifact Reference.
446 ArtifactReference testReference = parser.toArtifactReference( path );
447 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
450 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
451 String version, String classifier, String type )
453 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
456 assertNotNull( expectedId + " - Should not be null.", actualReference );
458 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
459 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
460 if ( StringUtils.isNotBlank( classifier ) )
462 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
464 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
465 assertEquals( expectedId + " - Type", type, actualReference.getType() );
468 private void assertBadPath( String path, String reason )
472 parser.toArtifactReference( path );
473 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
475 catch ( LayoutException e )