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;
26 import org.junit.Test;
29 * DefaultPathParserTest
31 * TODO: move to path translator tests
35 public class DefaultPathParserTest
36 extends AbstractRepositoryLayerTestCase
38 private PathParser parser = new DefaultPathParser();
41 public void testBadPathMissingType()
43 // TODO: should we allow this instead?
44 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
48 public void testBadPathReleaseInSnapshotDir()
50 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar",
51 "non snapshot artifact inside of a snapshot dir" );
55 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
57 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
58 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
62 public void testBadPathTooShort()
64 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
68 public void testBadPathVersionMismatchA()
70 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
74 public void testBadPathVersionMismatchB()
76 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
80 public void testBadPathWrongArtifactId()
82 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
83 "wrong artifact id" );
87 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
90 public void testGoodButDualExtensions()
91 throws LayoutException
93 String groupId = "org.project";
94 String artifactId = "example-presentation";
95 String version = "3.2";
96 String classifier = null;
97 String type = "xml.zip";
98 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
100 assertLayout( path, groupId, artifactId, version, classifier, type );
104 public void testGoodButDualExtensionsWithClassifier()
105 throws LayoutException
107 String groupId = "org.project";
108 String artifactId = "example-presentation";
109 String version = "3.2";
110 String classifier = "extras";
111 String type = "xml.zip";
112 String path = "org/project/example-presentation/3.2/example-presentation-3.2-extras.xml.zip";
114 assertLayout( path, groupId, artifactId, version, classifier, type );
118 public void testGoodButDualExtensionsTarGz()
119 throws LayoutException
121 String groupId = "org.project";
122 String artifactId = "example-distribution";
123 String version = "1.3";
124 String classifier = null;
125 String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
126 String path = "org/project/example-distribution/1.3/example-distribution-1.3.tar.gz";
128 assertLayout( path, groupId, artifactId, version, classifier, type );
132 public void testGoodButDualExtensionsTarGzAndClassifier()
133 throws LayoutException
135 String groupId = "org.project";
136 String artifactId = "example-distribution";
137 String version = "1.3";
138 String classifier = "bin";
139 String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
140 String path = "org/project/example-distribution/1.3/example-distribution-1.3-bin.tar.gz";
142 assertLayout( path, groupId, artifactId, version, classifier, type );
146 * [MRM-432] Oddball version spec.
147 * Example of an oddball / unusual version spec.
149 * @throws LayoutException
152 public void testGoodButOddVersionSpecGanymedSsh2()
153 throws LayoutException
155 String groupId = "ch.ethz.ganymed";
156 String artifactId = "ganymed-ssh2";
157 String version = "build210";
158 String classifier = null;
160 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
162 assertLayout( path, groupId, artifactId, version, classifier, type );
166 * [MRM-432] Oddball version spec.
167 * Example of an oddball / unusual version spec.
169 * @throws LayoutException
172 public void testGoodButOddVersionSpecJavaxComm()
173 throws LayoutException
175 String groupId = "javax";
176 String artifactId = "comm";
177 String version = "3.0-u1";
178 String classifier = null;
180 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
182 assertLayout( path, groupId, artifactId, version, classifier, type );
186 * Test the ejb-client type spec.
187 * Type specs are not a 1 to 1 map to the extension.
188 * This tests that effect.
189 * @throws LayoutException
191 /* TODO: Re-enabled in the future.
192 public void testGoodFooEjbClient()
193 throws LayoutException
195 String groupId = "com.foo";
196 String artifactId = "foo-client";
197 String version = "1.0";
198 String classifier = null;
199 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
200 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
202 assertLayout( path, groupId, artifactId, version, classifier, type );
207 * [MRM-432] Oddball version spec.
208 * Example of an oddball / unusual version spec.
210 * @throws LayoutException
213 public void testGoodButOddVersionSpecJavaxPersistence()
214 throws LayoutException
216 String groupId = "javax.persistence";
217 String artifactId = "ejb";
218 String version = "3.0-public_review";
219 String classifier = null;
221 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
224 * The version id of "public_review" can cause problems. is it part of
225 * the version spec? or the classifier?
226 * Since the path spec below shows it in the path, then it is really
227 * part of the version spec.
230 assertLayout( path, groupId, artifactId, version, classifier, type );
234 public void testGoodComFooTool()
235 throws LayoutException
237 String groupId = "com.foo";
238 String artifactId = "foo-tool";
239 String version = "1.0";
240 String classifier = null;
242 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
244 assertLayout( path, groupId, artifactId, version, classifier, type );
248 public void testGoodCommonsLang()
249 throws LayoutException
251 String groupId = "commons-lang";
252 String artifactId = "commons-lang";
253 String version = "2.1";
254 String classifier = null;
256 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
258 assertLayout( path, groupId, artifactId, version, classifier, type );
262 public void testWindowsPathSeparator()
263 throws LayoutException
265 String groupId = "commons-lang";
266 String artifactId = "commons-lang";
267 String version = "2.1";
268 String classifier = null;
270 String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar";
272 assertLayout( path, groupId, artifactId, version, classifier, type );
276 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
279 public void testGoodDashedArtifactId()
280 throws LayoutException
282 String groupId = "test.maven-arch";
283 String artifactId = "test-arch";
284 String version = "2.0.3-SNAPSHOT";
285 String classifier = null;
287 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
289 assertLayout( path, groupId, artifactId, version, classifier, type );
293 * It may seem odd, but this is a valid artifact.
296 public void testGoodDotNotationArtifactId()
297 throws LayoutException
299 String groupId = "com.company.department";
300 String artifactId = "com.company.department";
301 String version = "0.2";
302 String classifier = null;
304 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
306 assertLayout( path, groupId, artifactId, version, classifier, type );
310 * It may seem odd, but this is a valid artifact.
313 public void testGoodDotNotationSameGroupIdAndArtifactId()
314 throws LayoutException
316 String groupId = "com.company.department";
317 String artifactId = "com.company.department.project";
318 String version = "0.3";
319 String classifier = null;
322 "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
324 assertLayout( path, groupId, artifactId, version, classifier, type );
328 * Test the classifier, and java-source type spec.
330 * @throws LayoutException
333 public void testGoodFooLibSources()
334 throws LayoutException
336 String groupId = "com.foo.lib";
337 String artifactId = "foo-lib";
338 String version = "2.1-alpha-1";
339 String classifier = "sources";
340 String type = "java-source"; // oddball type-spec (should result in jar extension)
341 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
343 assertLayout( path, groupId, artifactId, version, classifier, type );
347 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
349 * @throws LayoutException
352 public void testGoodSnapshotMavenTest()
353 throws LayoutException
355 String groupId = "org.apache.archiva.test";
356 String artifactId = "redonkulous";
357 String version = "3.1-beta-1-20050831.101112-42";
358 String classifier = null;
361 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
363 assertLayout( path, groupId, artifactId, version, classifier, type );
367 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
369 * @throws LayoutException
372 public void testGoodLongSnapshotMavenTest()
373 throws LayoutException
375 String groupId = "a.group.id";
376 String artifactId = "artifact-id";
377 String version = "1.0-abc-1.1-20080221.062205-9";
378 String classifier = null;
380 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
382 assertLayout( path, groupId, artifactId, version, classifier, type );
386 * A timestamped versioned artifact but without release version part. Like on axiom trunk.
389 public void testBadSnapshotWithoutReleasePart()
391 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
392 "snapshot version without release part" );
396 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
398 * @throws LayoutException
401 public void testClassifiedSnapshotMavenTest()
402 throws LayoutException
404 String groupId = "a.group.id";
405 String artifactId = "artifact-id";
406 String version = "1.0-20070219.171202-34";
407 String classifier = "test-sources";
409 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
411 assertLayout( path, groupId, artifactId, version, classifier, type );
415 * [MRM-519] version identifiers within filename cause misidentification of version.
416 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
419 public void testGoodVersionKeywordInArtifactId()
420 throws LayoutException
422 String groupId = "maven";
423 String artifactId = "maven-test-plugin";
424 String version = "1.8.2";
425 String classifier = null;
427 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
429 assertLayout( path, groupId, artifactId, version, classifier, type );
433 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
434 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
437 public void testGoodDetectMavenTestPlugin()
438 throws LayoutException
440 String groupId = "maven";
441 String artifactId = "maven-test-plugin";
442 String version = "1.8.2";
443 String classifier = null;
444 String type = "maven-plugin";
445 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
447 assertLayout( path, groupId, artifactId, version, classifier, type );
451 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
454 public void testGoodDetectCoberturaMavenPlugin()
455 throws LayoutException
457 String groupId = "org.codehaus.mojo";
458 String artifactId = "cobertura-maven-plugin";
459 String version = "2.1";
460 String classifier = null;
461 String type = "maven-plugin";
462 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
464 assertLayout( path, groupId, artifactId, version, classifier, type );
468 public void testToArtifactOnEmptyPath()
472 parser.toArtifactReference( "" );
473 fail( "Should have failed due to empty path." );
475 catch ( LayoutException e )
482 public void testToArtifactOnNullPath()
486 parser.toArtifactReference( null );
487 fail( "Should have failed due to null path." );
489 catch ( LayoutException e )
496 public void testToArtifactReferenceOnEmptyPath()
500 parser.toArtifactReference( "" );
501 fail( "Should have failed due to empty path." );
503 catch ( LayoutException e )
510 public void testToArtifactReferenceOnNullPath()
514 parser.toArtifactReference( null );
515 fail( "Should have failed due to null path." );
517 catch ( LayoutException e )
524 * Perform a path to artifact reference lookup, and verify the results.
526 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
528 throws LayoutException
530 // Path to Artifact Reference.
531 ArtifactReference testReference = parser.toArtifactReference( path );
532 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
535 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
536 String version, String classifier, String type )
539 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
541 assertNotNull( expectedId + " - Should not be null.", actualReference );
543 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
544 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
545 if ( StringUtils.isNotBlank( classifier ) )
547 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
549 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
550 assertEquals( expectedId + " - Type", type, actualReference.getType() );
553 private void assertBadPath( String path, String reason )
557 parser.toArtifactReference( path );
559 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
561 catch ( LayoutException e )