1 package org.apache.maven.archiva.repository.content;
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.maven.archiva.model.ArtifactReference;
5 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
6 import org.apache.maven.archiva.repository.layout.LayoutException;
9 * DefaultPathParserTest
11 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
14 public class DefaultPathParserTest
15 extends AbstractRepositoryLayerTestCase
17 private PathParser parser = new DefaultPathParser();
19 public void testBadPathMissingType()
21 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
24 public void testBadPathReleaseInSnapshotDir()
26 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
29 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
31 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
32 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
35 public void testBadPathTooShort()
37 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
40 public void testBadPathVersionMismatchA()
42 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
45 public void testBadPathVersionMismatchB()
47 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
50 public void testBadPathWrongArtifactId()
52 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
53 "wrong artifact id" );
57 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
59 public void testGoodButDualExtensions()
60 throws LayoutException
62 String groupId = "org.project";
63 String artifactId = "example-presentation";
64 String version = "3.2";
65 String classifier = null;
66 String type = "xml-zip";
67 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
69 assertLayout( path, groupId, artifactId, version, classifier, type );
73 * [MRM-432] Oddball version spec.
74 * Example of an oddball / unusual version spec.
75 * @throws LayoutException
77 public void testGoodButOddVersionSpecGanymedSsh2()
78 throws LayoutException
80 String groupId = "ch.ethz.ganymed";
81 String artifactId = "ganymed-ssh2";
82 String version = "build210";
83 String classifier = null;
85 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
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 testGoodButOddVersionSpecJavaxComm()
96 throws LayoutException
98 String groupId = "javax";
99 String artifactId = "comm";
100 String version = "3.0-u1";
101 String classifier = null;
103 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
105 assertLayout( path, groupId, artifactId, version, classifier, type );
109 * Test the ejb-client type spec.
110 * Type specs are not a 1 to 1 map to the extension.
111 * This tests that effect.
112 * @throws LayoutException
114 /* TODO: Re-enabled in the future.
115 public void testGoodFooEjbClient()
116 throws LayoutException
118 String groupId = "com.foo";
119 String artifactId = "foo-client";
120 String version = "1.0";
121 String classifier = null;
122 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
123 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
125 assertLayout( path, groupId, artifactId, version, classifier, type );
130 * [MRM-432] Oddball version spec.
131 * Example of an oddball / unusual version spec.
132 * @throws LayoutException
134 public void testGoodButOddVersionSpecJavaxPersistence()
135 throws LayoutException
137 String groupId = "javax.persistence";
138 String artifactId = "ejb";
139 String version = "3.0-public_review";
140 String classifier = null;
142 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
145 * The version id of "public_review" can cause problems. is it part of
146 * the version spec? or the classifier?
147 * Since the path spec below shows it in the path, then it is really
148 * part of the version spec.
151 assertLayout( path, groupId, artifactId, version, classifier, type );
154 public void testGoodComFooTool()
155 throws LayoutException
157 String groupId = "com.foo";
158 String artifactId = "foo-tool";
159 String version = "1.0";
160 String classifier = null;
162 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
164 assertLayout( path, groupId, artifactId, version, classifier, type );
167 public void testGoodCommonsLang()
168 throws LayoutException
170 String groupId = "commons-lang";
171 String artifactId = "commons-lang";
172 String version = "2.1";
173 String classifier = null;
175 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
177 assertLayout( path, groupId, artifactId, version, classifier, type );
181 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
183 public void testGoodDashedArtifactId()
184 throws LayoutException
186 String groupId = "test.maven-arch";
187 String artifactId = "test-arch";
188 String version = "2.0.3-SNAPSHOT";
189 String classifier = null;
191 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
193 assertLayout( path, groupId, artifactId, version, classifier, type );
197 * It may seem odd, but this is a valid artifact.
199 public void testGoodDotNotationArtifactId()
200 throws LayoutException
202 String groupId = "com.company.department";
203 String artifactId = "com.company.department";
204 String version = "0.2";
205 String classifier = null;
207 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
209 assertLayout( path, groupId, artifactId, version, classifier, type );
213 * It may seem odd, but this is a valid artifact.
215 public void testGoodDotNotationSameGroupIdAndArtifactId()
216 throws LayoutException
218 String groupId = "com.company.department";
219 String artifactId = "com.company.department.project";
220 String version = "0.3";
221 String classifier = null;
223 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
225 assertLayout( path, groupId, artifactId, version, classifier, type );
229 * Test the classifier, and java-source type spec.
230 * @throws LayoutException
232 public void testGoodFooLibSources()
233 throws LayoutException
235 String groupId = "com.foo.lib";
236 String artifactId = "foo-lib";
237 String version = "2.1-alpha-1";
238 String classifier = "sources";
239 String type = "java-source"; // oddball type-spec (should result in jar extension)
240 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
242 assertLayout( path, groupId, artifactId, version, classifier, type );
246 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
247 * @throws LayoutException
249 public void testGoodSnapshotMavenTest()
250 throws LayoutException
252 String groupId = "org.apache.archiva.test";
253 String artifactId = "redonkulous";
254 String version = "3.1-beta-1-20050831.101112-42";
255 String classifier = null;
257 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
259 assertLayout( path, groupId, artifactId, version, classifier, type );
263 * [MRM-519] version identifiers within filename cause misidentification of version.
264 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
266 public void testGoodVersionKeywordInArtifactId()
267 throws LayoutException
269 String groupId = "maven";
270 String artifactId = "maven-test-plugin";
271 String version = "1.8.2";
272 String classifier = null;
274 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
276 assertLayout( path, groupId, artifactId, version, classifier, type );
280 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
281 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
283 public void testGoodDetectMavenTestPlugin()
284 throws LayoutException
286 String groupId = "maven";
287 String artifactId = "maven-test-plugin";
288 String version = "1.8.2";
289 String classifier = null;
290 String type = "maven-plugin";
291 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
293 assertLayout( path, groupId, artifactId, version, classifier, type );
297 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
299 public void testGoodDetectCoberturaMavenPlugin()
300 throws LayoutException
302 String groupId = "org.codehaus.mojo";
303 String artifactId = "cobertura-maven-plugin";
304 String version = "2.1";
305 String classifier = null;
306 String type = "maven-plugin";
307 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
309 assertLayout( path, groupId, artifactId, version, classifier, type );
312 public void testToArtifactOnEmptyPath()
316 parser.toArtifactReference( "" );
317 fail( "Should have failed due to empty path." );
319 catch ( LayoutException e )
325 public void testToArtifactOnNullPath()
329 parser.toArtifactReference( null );
330 fail( "Should have failed due to null path." );
332 catch ( LayoutException e )
338 public void testToArtifactReferenceOnEmptyPath()
342 parser.toArtifactReference( "" );
343 fail( "Should have failed due to empty path." );
345 catch ( LayoutException e )
351 public void testToArtifactReferenceOnNullPath()
355 parser.toArtifactReference( null );
356 fail( "Should have failed due to null path." );
358 catch ( LayoutException e )
365 * Perform a path to artifact reference lookup, and verify the results.
367 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
369 throws LayoutException
371 // Path to Artifact Reference.
372 ArtifactReference testReference = parser.toArtifactReference( path );
373 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
376 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
377 String version, String classifier, String type )
379 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
382 assertNotNull( expectedId + " - Should not be null.", actualReference );
384 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
385 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
386 if ( StringUtils.isNotBlank( classifier ) )
388 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
390 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
391 assertEquals( expectedId + " - Type", type, actualReference.getType() );
394 private void assertBadPath( String path, String reason )
398 parser.toArtifactReference( path );
399 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
401 catch ( LayoutException e )