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
30 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
33 public class DefaultPathParserTest
34 extends AbstractRepositoryLayerTestCase
36 private PathParser parser = new DefaultPathParser();
38 public void testBadPathMissingType()
40 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
43 public void testBadPathReleaseInSnapshotDir()
45 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
48 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
50 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
51 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
54 public void testBadPathTooShort()
56 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
59 public void testBadPathVersionMismatchA()
61 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
64 public void testBadPathVersionMismatchB()
66 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
69 public void testBadPathWrongArtifactId()
71 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
72 "wrong artifact id" );
76 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
78 public void testGoodButDualExtensions()
79 throws LayoutException
81 String groupId = "org.project";
82 String artifactId = "example-presentation";
83 String version = "3.2";
84 String classifier = null;
85 String type = "xml.zip";
86 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
88 assertLayout( path, groupId, artifactId, version, classifier, type );
92 * [MRM-432] Oddball version spec.
93 * Example of an oddball / unusual version spec.
94 * @throws LayoutException
96 public void testGoodButOddVersionSpecGanymedSsh2()
97 throws LayoutException
99 String groupId = "ch.ethz.ganymed";
100 String artifactId = "ganymed-ssh2";
101 String version = "build210";
102 String classifier = null;
104 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
106 assertLayout( path, groupId, artifactId, version, classifier, type );
110 * [MRM-432] Oddball version spec.
111 * Example of an oddball / unusual version spec.
112 * @throws LayoutException
114 public void testGoodButOddVersionSpecJavaxComm()
115 throws LayoutException
117 String groupId = "javax";
118 String artifactId = "comm";
119 String version = "3.0-u1";
120 String classifier = null;
122 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
124 assertLayout( path, groupId, artifactId, version, classifier, type );
128 * Test the ejb-client type spec.
129 * Type specs are not a 1 to 1 map to the extension.
130 * This tests that effect.
131 * @throws LayoutException
133 /* TODO: Re-enabled in the future.
134 public void testGoodFooEjbClient()
135 throws LayoutException
137 String groupId = "com.foo";
138 String artifactId = "foo-client";
139 String version = "1.0";
140 String classifier = null;
141 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
142 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
144 assertLayout( path, groupId, artifactId, version, classifier, type );
149 * [MRM-432] Oddball version spec.
150 * Example of an oddball / unusual version spec.
151 * @throws LayoutException
153 public void testGoodButOddVersionSpecJavaxPersistence()
154 throws LayoutException
156 String groupId = "javax.persistence";
157 String artifactId = "ejb";
158 String version = "3.0-public_review";
159 String classifier = null;
161 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
164 * The version id of "public_review" can cause problems. is it part of
165 * the version spec? or the classifier?
166 * Since the path spec below shows it in the path, then it is really
167 * part of the version spec.
170 assertLayout( path, groupId, artifactId, version, classifier, type );
173 public void testGoodComFooTool()
174 throws LayoutException
176 String groupId = "com.foo";
177 String artifactId = "foo-tool";
178 String version = "1.0";
179 String classifier = null;
181 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
183 assertLayout( path, groupId, artifactId, version, classifier, type );
186 public void testGoodCommonsLang()
187 throws LayoutException
189 String groupId = "commons-lang";
190 String artifactId = "commons-lang";
191 String version = "2.1";
192 String classifier = null;
194 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
196 assertLayout( path, groupId, artifactId, version, classifier, type );
200 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
202 public void testGoodDashedArtifactId()
203 throws LayoutException
205 String groupId = "test.maven-arch";
206 String artifactId = "test-arch";
207 String version = "2.0.3-SNAPSHOT";
208 String classifier = null;
210 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
212 assertLayout( path, groupId, artifactId, version, classifier, type );
216 * It may seem odd, but this is a valid artifact.
218 public void testGoodDotNotationArtifactId()
219 throws LayoutException
221 String groupId = "com.company.department";
222 String artifactId = "com.company.department";
223 String version = "0.2";
224 String classifier = null;
226 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
228 assertLayout( path, groupId, artifactId, version, classifier, type );
232 * It may seem odd, but this is a valid artifact.
234 public void testGoodDotNotationSameGroupIdAndArtifactId()
235 throws LayoutException
237 String groupId = "com.company.department";
238 String artifactId = "com.company.department.project";
239 String version = "0.3";
240 String classifier = null;
242 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
244 assertLayout( path, groupId, artifactId, version, classifier, type );
248 * Test the classifier, and java-source type spec.
249 * @throws LayoutException
251 public void testGoodFooLibSources()
252 throws LayoutException
254 String groupId = "com.foo.lib";
255 String artifactId = "foo-lib";
256 String version = "2.1-alpha-1";
257 String classifier = "sources";
258 String type = "java-source"; // oddball type-spec (should result in jar extension)
259 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
261 assertLayout( path, groupId, artifactId, version, classifier, type );
265 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
266 * @throws LayoutException
268 public void testGoodSnapshotMavenTest()
269 throws LayoutException
271 String groupId = "org.apache.archiva.test";
272 String artifactId = "redonkulous";
273 String version = "3.1-beta-1-20050831.101112-42";
274 String classifier = null;
276 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
278 assertLayout( path, groupId, artifactId, version, classifier, type );
282 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
283 * @throws LayoutException
285 public void testGoodLongSnapshotMavenTest()
286 throws LayoutException
288 String groupId = "a.group.id";
289 String artifactId = "artifact-id";
290 String version = "1.0-abc-1.1-20080221.062205-9";
291 String classifier = null;
293 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
295 assertLayout( path, groupId, artifactId, version, classifier, type );
299 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
300 * @throws LayoutException
302 public void testClassifiedSnapshotMavenTest()
303 throws LayoutException
305 String groupId = "a.group.id";
306 String artifactId = "artifact-id";
307 String version = "1.0-20070219.171202-34";
308 String classifier = "test-sources";
310 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
312 assertLayout( path, groupId, artifactId, version, classifier, type );
316 * [MRM-519] version identifiers within filename cause misidentification of version.
317 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
319 public void testGoodVersionKeywordInArtifactId()
320 throws LayoutException
322 String groupId = "maven";
323 String artifactId = "maven-test-plugin";
324 String version = "1.8.2";
325 String classifier = null;
327 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
329 assertLayout( path, groupId, artifactId, version, classifier, type );
333 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
334 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
336 public void testGoodDetectMavenTestPlugin()
337 throws LayoutException
339 String groupId = "maven";
340 String artifactId = "maven-test-plugin";
341 String version = "1.8.2";
342 String classifier = null;
343 String type = "maven-plugin";
344 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
346 assertLayout( path, groupId, artifactId, version, classifier, type );
350 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
352 public void testGoodDetectCoberturaMavenPlugin()
353 throws LayoutException
355 String groupId = "org.codehaus.mojo";
356 String artifactId = "cobertura-maven-plugin";
357 String version = "2.1";
358 String classifier = null;
359 String type = "maven-plugin";
360 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
362 assertLayout( path, groupId, artifactId, version, classifier, type );
365 public void testToArtifactOnEmptyPath()
369 parser.toArtifactReference( "" );
370 fail( "Should have failed due to empty path." );
372 catch ( LayoutException e )
378 public void testToArtifactOnNullPath()
382 parser.toArtifactReference( null );
383 fail( "Should have failed due to null path." );
385 catch ( LayoutException e )
391 public void testToArtifactReferenceOnEmptyPath()
395 parser.toArtifactReference( "" );
396 fail( "Should have failed due to empty path." );
398 catch ( LayoutException e )
404 public void testToArtifactReferenceOnNullPath()
408 parser.toArtifactReference( null );
409 fail( "Should have failed due to null path." );
411 catch ( LayoutException e )
418 * Perform a path to artifact reference lookup, and verify the results.
420 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
422 throws LayoutException
424 // Path to Artifact Reference.
425 ArtifactReference testReference = parser.toArtifactReference( path );
426 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
429 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
430 String version, String classifier, String type )
432 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
435 assertNotNull( expectedId + " - Should not be null.", actualReference );
437 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
438 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
439 if ( StringUtils.isNotBlank( classifier ) )
441 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
443 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
444 assertEquals( expectedId + " - Type", type, actualReference.getType() );
447 private void assertBadPath( String path, String reason )
451 parser.toArtifactReference( path );
452 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
454 catch ( LayoutException e )