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 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
264 * @throws LayoutException
266 public void testGoodLongSnapshotMavenTest()
267 throws LayoutException
269 String groupId = "a.group.id";
270 String artifactId = "artifact-id";
271 String version = "1.0-abc-1.1-20080221.062205-9";
272 String classifier = null;
274 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
276 assertLayout( path, groupId, artifactId, version, classifier, type );
280 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
281 * @throws LayoutException
283 public void testClassifiedSnapshotMavenTest()
284 throws LayoutException
286 String groupId = "a.group.id";
287 String artifactId = "artifact-id";
288 String version = "1.0-20070219.171202-34";
289 String classifier = "test-sources";
291 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
293 assertLayout( path, groupId, artifactId, version, classifier, type );
297 * [MRM-519] version identifiers within filename cause misidentification of version.
298 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
300 public void testGoodVersionKeywordInArtifactId()
301 throws LayoutException
303 String groupId = "maven";
304 String artifactId = "maven-test-plugin";
305 String version = "1.8.2";
306 String classifier = null;
308 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
310 assertLayout( path, groupId, artifactId, version, classifier, type );
314 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
315 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
317 public void testGoodDetectMavenTestPlugin()
318 throws LayoutException
320 String groupId = "maven";
321 String artifactId = "maven-test-plugin";
322 String version = "1.8.2";
323 String classifier = null;
324 String type = "maven-plugin";
325 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
327 assertLayout( path, groupId, artifactId, version, classifier, type );
331 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
333 public void testGoodDetectCoberturaMavenPlugin()
334 throws LayoutException
336 String groupId = "org.codehaus.mojo";
337 String artifactId = "cobertura-maven-plugin";
338 String version = "2.1";
339 String classifier = null;
340 String type = "maven-plugin";
341 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
343 assertLayout( path, groupId, artifactId, version, classifier, type );
346 public void testToArtifactOnEmptyPath()
350 parser.toArtifactReference( "" );
351 fail( "Should have failed due to empty path." );
353 catch ( LayoutException e )
359 public void testToArtifactOnNullPath()
363 parser.toArtifactReference( null );
364 fail( "Should have failed due to null path." );
366 catch ( LayoutException e )
372 public void testToArtifactReferenceOnEmptyPath()
376 parser.toArtifactReference( "" );
377 fail( "Should have failed due to empty path." );
379 catch ( LayoutException e )
385 public void testToArtifactReferenceOnNullPath()
389 parser.toArtifactReference( null );
390 fail( "Should have failed due to null path." );
392 catch ( LayoutException e )
399 * Perform a path to artifact reference lookup, and verify the results.
401 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
403 throws LayoutException
405 // Path to Artifact Reference.
406 ArtifactReference testReference = parser.toArtifactReference( path );
407 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
410 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
411 String version, String classifier, String type )
413 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
416 assertNotNull( expectedId + " - Should not be null.", actualReference );
418 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
419 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
420 if ( StringUtils.isNotBlank( classifier ) )
422 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
424 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
425 assertEquals( expectedId + " - Type", type, actualReference.getType() );
428 private void assertBadPath( String path, String reason )
432 parser.toArtifactReference( path );
433 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
435 catch ( LayoutException e )