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
32 public class DefaultPathParserTest
33 extends AbstractRepositoryLayerTestCase
35 private PathParser parser = new DefaultPathParser();
37 public void testBadPathMissingType()
39 // TODO: should we allow this instead?
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 );
199 public void testWindowsPathSeparator()
200 throws LayoutException
202 String groupId = "commons-lang";
203 String artifactId = "commons-lang";
204 String version = "2.1";
205 String classifier = null;
207 String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar";
209 assertLayout( path, groupId, artifactId, version, classifier, type );
213 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
215 public void testGoodDashedArtifactId()
216 throws LayoutException
218 String groupId = "test.maven-arch";
219 String artifactId = "test-arch";
220 String version = "2.0.3-SNAPSHOT";
221 String classifier = null;
223 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
225 assertLayout( path, groupId, artifactId, version, classifier, type );
229 * It may seem odd, but this is a valid artifact.
231 public void testGoodDotNotationArtifactId()
232 throws LayoutException
234 String groupId = "com.company.department";
235 String artifactId = "com.company.department";
236 String version = "0.2";
237 String classifier = null;
239 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
241 assertLayout( path, groupId, artifactId, version, classifier, type );
245 * It may seem odd, but this is a valid artifact.
247 public void testGoodDotNotationSameGroupIdAndArtifactId()
248 throws LayoutException
250 String groupId = "com.company.department";
251 String artifactId = "com.company.department.project";
252 String version = "0.3";
253 String classifier = null;
255 String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
257 assertLayout( path, groupId, artifactId, version, classifier, type );
261 * Test the classifier, and java-source type spec.
262 * @throws LayoutException
264 public void testGoodFooLibSources()
265 throws LayoutException
267 String groupId = "com.foo.lib";
268 String artifactId = "foo-lib";
269 String version = "2.1-alpha-1";
270 String classifier = "sources";
271 String type = "java-source"; // oddball type-spec (should result in jar extension)
272 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
274 assertLayout( path, groupId, artifactId, version, classifier, type );
278 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
279 * @throws LayoutException
281 public void testGoodSnapshotMavenTest()
282 throws LayoutException
284 String groupId = "org.apache.archiva.test";
285 String artifactId = "redonkulous";
286 String version = "3.1-beta-1-20050831.101112-42";
287 String classifier = null;
289 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
291 assertLayout( path, groupId, artifactId, version, classifier, type );
295 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
296 * @throws LayoutException
298 public void testGoodLongSnapshotMavenTest()
299 throws LayoutException
301 String groupId = "a.group.id";
302 String artifactId = "artifact-id";
303 String version = "1.0-abc-1.1-20080221.062205-9";
304 String classifier = null;
306 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
308 assertLayout( path, groupId, artifactId, version, classifier, type );
312 * A timestamped versioned artifact but without release version part. Like on axiom trunk.
314 public void testBadSnapshotWithoutReleasePart()
316 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
317 "snapshot version without release part");
321 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
322 * @throws LayoutException
324 public void testClassifiedSnapshotMavenTest()
325 throws LayoutException
327 String groupId = "a.group.id";
328 String artifactId = "artifact-id";
329 String version = "1.0-20070219.171202-34";
330 String classifier = "test-sources";
332 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
334 assertLayout( path, groupId, artifactId, version, classifier, type );
338 * [MRM-519] version identifiers within filename cause misidentification of version.
339 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
341 public void testGoodVersionKeywordInArtifactId()
342 throws LayoutException
344 String groupId = "maven";
345 String artifactId = "maven-test-plugin";
346 String version = "1.8.2";
347 String classifier = null;
349 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
351 assertLayout( path, groupId, artifactId, version, classifier, type );
355 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
356 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
358 public void testGoodDetectMavenTestPlugin()
359 throws LayoutException
361 String groupId = "maven";
362 String artifactId = "maven-test-plugin";
363 String version = "1.8.2";
364 String classifier = null;
365 String type = "maven-plugin";
366 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
368 assertLayout( path, groupId, artifactId, version, classifier, type );
372 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
374 public void testGoodDetectCoberturaMavenPlugin()
375 throws LayoutException
377 String groupId = "org.codehaus.mojo";
378 String artifactId = "cobertura-maven-plugin";
379 String version = "2.1";
380 String classifier = null;
381 String type = "maven-plugin";
382 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
384 assertLayout( path, groupId, artifactId, version, classifier, type );
387 public void testToArtifactOnEmptyPath()
391 parser.toArtifactReference( "" );
392 fail( "Should have failed due to empty path." );
394 catch ( LayoutException e )
400 public void testToArtifactOnNullPath()
404 parser.toArtifactReference( null );
405 fail( "Should have failed due to null path." );
407 catch ( LayoutException e )
413 public void testToArtifactReferenceOnEmptyPath()
417 parser.toArtifactReference( "" );
418 fail( "Should have failed due to empty path." );
420 catch ( LayoutException e )
426 public void testToArtifactReferenceOnNullPath()
430 parser.toArtifactReference( null );
431 fail( "Should have failed due to null path." );
433 catch ( LayoutException e )
440 * Perform a path to artifact reference lookup, and verify the results.
442 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
444 throws LayoutException
446 // Path to Artifact Reference.
447 ArtifactReference testReference = parser.toArtifactReference( path );
448 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
451 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
452 String version, String classifier, String type )
454 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier
457 assertNotNull( expectedId + " - Should not be null.", actualReference );
459 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
460 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
461 if ( StringUtils.isNotBlank( classifier ) )
463 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
465 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
466 assertEquals( expectedId + " - Type", type, actualReference.getType() );
469 private void assertBadPath( String path, String reason )
473 parser.toArtifactReference( path );
474 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
476 catch ( LayoutException e )