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 public void testBadPathMissingType()
19 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
22 public void testBadPathReleaseInSnapshotDir()
24 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
27 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
29 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
30 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
33 public void testBadPathTooShort()
35 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
38 public void testBadPathVersionMismatchA()
40 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
43 public void testBadPathVersionMismatchB()
45 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
48 public void testBadPathWrongArtifactId()
50 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
51 "wrong artifact id" );
55 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
57 public void testGoodButDualExtensions()
58 throws LayoutException
60 String groupId = "org.project";
61 String artifactId = "example-presentation";
62 String version = "3.2";
63 String classifier = null;
64 String type = "xml-zip";
65 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
67 assertLayout( path, groupId, artifactId, version, classifier, type );
71 * [MRM-432] Oddball version spec.
72 * Example of an oddball / unusual version spec.
73 * @throws LayoutException
75 public void testGoodButOddVersionSpecGanymedSsh2()
76 throws LayoutException
78 String groupId = "ch.ethz.ganymed";
79 String artifactId = "ganymed-ssh2";
80 String version = "build210";
81 String classifier = null;
83 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
85 assertLayout( path, groupId, artifactId, version, classifier, type );
89 * [MRM-432] Oddball version spec.
90 * Example of an oddball / unusual version spec.
91 * @throws LayoutException
93 public void testGoodButOddVersionSpecJavaxComm()
94 throws LayoutException
96 String groupId = "javax";
97 String artifactId = "comm";
98 String version = "3.0-u1";
99 String classifier = null;
101 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
103 assertLayout( path, groupId, artifactId, version, classifier, type );
107 * Test the ejb-client type spec.
108 * Type specs are not a 1 to 1 map to the extension.
109 * This tests that effect.
110 * @throws LayoutException
112 /* TODO: Re-enabled in the future.
113 public void testGoodFooEjbClient()
114 throws LayoutException
116 String groupId = "com.foo";
117 String artifactId = "foo-client";
118 String version = "1.0";
119 String classifier = null;
120 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
121 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
123 assertLayout( path, groupId, artifactId, version, classifier, type );
128 * [MRM-432] Oddball version spec.
129 * Example of an oddball / unusual version spec.
130 * @throws LayoutException
132 public void testGoodButOddVersionSpecJavaxPersistence()
133 throws LayoutException
135 String groupId = "javax.persistence";
136 String artifactId = "ejb";
137 String version = "3.0-public_review";
138 String classifier = null;
140 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
143 * The version id of "public_review" can cause problems. is it part of
144 * the version spec? or the classifier?
145 * Since the path spec below shows it in the path, then it is really
146 * part of the version spec.
149 assertLayout( path, groupId, artifactId, version, classifier, type );
152 public void testGoodComFooTool()
153 throws LayoutException
155 String groupId = "com.foo";
156 String artifactId = "foo-tool";
157 String version = "1.0";
158 String classifier = null;
160 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
162 assertLayout( path, groupId, artifactId, version, classifier, type );
165 public void testGoodCommonsLang()
166 throws LayoutException
168 String groupId = "commons-lang";
169 String artifactId = "commons-lang";
170 String version = "2.1";
171 String classifier = null;
173 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
175 assertLayout( path, groupId, artifactId, version, classifier, type );
179 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
181 public void testGoodDashedArtifactId()
182 throws LayoutException
184 String groupId = "test.maven-arch";
185 String artifactId = "test-arch";
186 String version = "2.0.3-SNAPSHOT";
187 String classifier = null;
189 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
191 assertLayout( path, groupId, artifactId, version, classifier, type );
195 * It may seem odd, but this is a valid artifact.
197 public void testGoodDotNotationArtifactId()
198 throws LayoutException
200 String groupId = "com.company.department";
201 String artifactId = "com.company.department";
202 String version = "0.2";
203 String classifier = null;
205 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
207 assertLayout( path, groupId, artifactId, version, classifier, type );
211 * It may seem odd, but this is a valid artifact.
213 public void testGoodDotNotationSameGroupIdAndArtifactId()
214 throws LayoutException
216 String groupId = "com.company.department";
217 String artifactId = "com.company.department.project";
218 String version = "0.3";
219 String classifier = null;
221 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
223 assertLayout( path, groupId, artifactId, version, classifier, type );
227 * Test the classifier, and java-source type spec.
228 * @throws LayoutException
230 public void testGoodFooLibSources()
231 throws LayoutException
233 String groupId = "com.foo.lib";
234 String artifactId = "foo-lib";
235 String version = "2.1-alpha-1";
236 String classifier = "sources";
237 String type = "java-source"; // oddball type-spec (should result in jar extension)
238 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
240 assertLayout( path, groupId, artifactId, version, classifier, type );
244 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
245 * @throws LayoutException
247 public void testGoodSnapshotMavenTest()
248 throws LayoutException
250 String groupId = "org.apache.archiva.test";
251 String artifactId = "redonkulous";
252 String version = "3.1-beta-1-20050831.101112-42";
253 String classifier = null;
255 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
257 assertLayout( path, groupId, artifactId, version, classifier, type );
261 * [MRM-519] version identifiers within filename cause misidentification of version.
262 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
264 public void testGoodVersionKeywordInArtifactId()
265 throws LayoutException
267 String groupId = "maven";
268 String artifactId = "maven-test-plugin";
269 String version = "1.8.2";
270 String classifier = null;
272 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
274 assertLayout( path, groupId, artifactId, version, classifier, type );
278 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
279 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
281 public void testGoodDetectMavenTestPlugin()
282 throws LayoutException
284 String groupId = "maven";
285 String artifactId = "maven-test-plugin";
286 String version = "1.8.2";
287 String classifier = null;
288 String type = "maven-plugin";
289 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
291 assertLayout( path, groupId, artifactId, version, classifier, type );
295 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
297 public void testGoodDetectCoberturaMavenPlugin()
298 throws LayoutException
300 String groupId = "org.codehaus.mojo";
301 String artifactId = "cobertura-maven-plugin";
302 String version = "2.1";
303 String classifier = null;
304 String type = "maven-plugin";
305 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
307 assertLayout( path, groupId, artifactId, version, classifier, type );
310 public void testToArtifactOnEmptyPath()
314 DefaultPathParser.toArtifactReference( "" );
315 fail( "Should have failed due to empty path." );
317 catch ( LayoutException e )
323 public void testToArtifactOnNullPath()
327 DefaultPathParser.toArtifactReference( null );
328 fail( "Should have failed due to null path." );
330 catch ( LayoutException e )
336 public void testToArtifactReferenceOnEmptyPath()
340 DefaultPathParser.toArtifactReference( "" );
341 fail( "Should have failed due to empty path." );
343 catch ( LayoutException e )
349 public void testToArtifactReferenceOnNullPath()
353 DefaultPathParser.toArtifactReference( null );
354 fail( "Should have failed due to null path." );
356 catch ( LayoutException e )
363 * Perform a path to artifact reference lookup, and verify the results.
365 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
367 throws LayoutException
369 // Path to Artifact Reference.
370 ArtifactReference testReference = DefaultPathParser.toArtifactReference( path );
371 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
374 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
375 String version, String classifier, String type )
377 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
380 assertNotNull( expectedId + " - Should not be null.", actualReference );
382 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
383 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
384 if ( StringUtils.isNotBlank( classifier ) )
386 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
388 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
389 assertEquals( expectedId + " - Type", type, actualReference.getType() );
392 private void assertBadPath( String path, String reason )
396 DefaultPathParser.toArtifactReference( path );
397 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
399 catch ( LayoutException e )