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-432] Oddball version spec.
56 * Example of an oddball / unusual version spec.
57 * @throws LayoutException
59 public void testGoodButOddVersionSpecGanymedSsh2()
60 throws LayoutException
62 String groupId = "ch.ethz.ganymed";
63 String artifactId = "ganymed-ssh2";
64 String version = "build210";
65 String classifier = null;
67 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
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 testGoodButOddVersionSpecJavaxComm()
78 throws LayoutException
80 String groupId = "javax";
81 String artifactId = "comm";
82 String version = "3.0-u1";
83 String classifier = null;
85 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
87 assertLayout( path, groupId, artifactId, version, classifier, type );
91 * Test the ejb-client type spec.
92 * Type specs are not a 1 to 1 map to the extension.
93 * This tests that effect.
94 * @throws LayoutException
96 /* TODO: Re-enabled in the future.
97 public void testGoodFooEjbClient()
98 throws LayoutException
100 String groupId = "com.foo";
101 String artifactId = "foo-client";
102 String version = "1.0";
103 String classifier = null;
104 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
105 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
107 assertLayout( path, groupId, artifactId, version, classifier, type );
112 * [MRM-432] Oddball version spec.
113 * Example of an oddball / unusual version spec.
114 * @throws LayoutException
116 public void testGoodButOddVersionSpecJavaxPersistence()
117 throws LayoutException
119 String groupId = "javax.persistence";
120 String artifactId = "ejb";
121 String version = "3.0-public_review";
122 String classifier = null;
124 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
127 * The version id of "public_review" can cause problems. is it part of
128 * the version spec? or the classifier?
129 * Since the path spec below shows it in the path, then it is really
130 * part of the version spec.
133 assertLayout( path, groupId, artifactId, version, classifier, type );
136 public void testGoodComFooTool()
137 throws LayoutException
139 String groupId = "com.foo";
140 String artifactId = "foo-tool";
141 String version = "1.0";
142 String classifier = null;
144 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
146 assertLayout( path, groupId, artifactId, version, classifier, type );
149 public void testGoodCommonsLang()
150 throws LayoutException
152 String groupId = "commons-lang";
153 String artifactId = "commons-lang";
154 String version = "2.1";
155 String classifier = null;
157 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
159 assertLayout( path, groupId, artifactId, version, classifier, type );
163 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
165 public void testGoodDashedArtifactId()
166 throws LayoutException
168 String groupId = "test.maven-arch";
169 String artifactId = "test-arch";
170 String version = "2.0.3-SNAPSHOT";
171 String classifier = null;
173 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
175 assertLayout( path, groupId, artifactId, version, classifier, type );
179 * It may seem odd, but this is a valid artifact.
181 public void testGoodDotNotationArtifactId()
182 throws LayoutException
184 String groupId = "com.company.department";
185 String artifactId = "com.company.department";
186 String version = "0.2";
187 String classifier = null;
189 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
191 assertLayout( path, groupId, artifactId, version, classifier, type );
195 * It may seem odd, but this is a valid artifact.
197 public void testGoodDotNotationSameGroupIdAndArtifactId()
198 throws LayoutException
200 String groupId = "com.company.department";
201 String artifactId = "com.company.department.project";
202 String version = "0.3";
203 String classifier = null;
205 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
207 assertLayout( path, groupId, artifactId, version, classifier, type );
211 * Test the classifier, and java-source type spec.
212 * @throws LayoutException
214 public void testGoodFooLibSources()
215 throws LayoutException
217 String groupId = "com.foo.lib";
218 String artifactId = "foo-lib";
219 String version = "2.1-alpha-1";
220 String classifier = "sources";
221 String type = "java-source"; // oddball type-spec (should result in jar extension)
222 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
224 assertLayout( path, groupId, artifactId, version, classifier, type );
228 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
229 * @throws LayoutException
231 public void testGoodSnapshotMavenTest()
232 throws LayoutException
234 String groupId = "org.apache.archiva.test";
235 String artifactId = "redonkulous";
236 String version = "3.1-beta-1-20050831.101112-42";
237 String classifier = null;
239 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
241 assertLayout( path, groupId, artifactId, version, classifier, type );
245 * [MRM-519] version identifiers within filename cause misidentification of version.
246 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
248 public void testGoodVersionKeywordInArtifactId()
249 throws LayoutException
251 String groupId = "maven";
252 String artifactId = "maven-test-plugin";
253 String version = "1.8.2";
254 String classifier = null;
256 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
258 assertLayout( path, groupId, artifactId, version, classifier, type );
262 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
263 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
265 public void testGoodDetectMavenTestPlugin()
266 throws LayoutException
268 String groupId = "maven";
269 String artifactId = "maven-test-plugin";
270 String version = "1.8.2";
271 String classifier = null;
272 String type = "maven-plugin";
273 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
275 assertLayout( path, groupId, artifactId, version, classifier, type );
279 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
281 public void testGoodDetectCoberturaMavenPlugin()
282 throws LayoutException
284 String groupId = "org.codehaus.mojo";
285 String artifactId = "cobertura-maven-plugin";
286 String version = "2.1";
287 String classifier = null;
288 String type = "maven-plugin";
289 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
291 assertLayout( path, groupId, artifactId, version, classifier, type );
294 public void testToArtifactOnEmptyPath()
298 DefaultPathParser.toArtifactReference( "" );
299 fail( "Should have failed due to empty path." );
301 catch ( LayoutException e )
307 public void testToArtifactOnNullPath()
311 DefaultPathParser.toArtifactReference( null );
312 fail( "Should have failed due to null path." );
314 catch ( LayoutException e )
320 public void testToArtifactReferenceOnEmptyPath()
324 DefaultPathParser.toArtifactReference( "" );
325 fail( "Should have failed due to empty path." );
327 catch ( LayoutException e )
333 public void testToArtifactReferenceOnNullPath()
337 DefaultPathParser.toArtifactReference( null );
338 fail( "Should have failed due to null path." );
340 catch ( LayoutException e )
347 * Perform a path to artifact reference lookup, and verify the results.
349 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
351 throws LayoutException
353 // Path to Artifact Reference.
354 ArtifactReference testReference = DefaultPathParser.toArtifactReference( path );
355 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
358 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
359 String version, String classifier, String type )
361 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
364 assertNotNull( expectedId + " - Should not be null.", actualReference );
366 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
367 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
368 if ( StringUtils.isNotBlank( classifier ) )
370 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
372 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
373 assertEquals( expectedId + " - Type", type, actualReference.getType() );
376 private void assertBadPath( String path, String reason )
380 DefaultPathParser.toArtifactReference( path );
381 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
383 catch ( LayoutException e )