1 package org.apache.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.archiva.model.ArtifactReference;
24 import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
25 import org.apache.archiva.repository.layout.LayoutException;
26 import org.junit.Test;
28 import static org.junit.Assert.*;
31 * DefaultPathParserTest
33 * TODO: move to path translator tests
37 public class DefaultPathParserTest
38 extends AbstractRepositoryLayerTestCase
40 private PathParser parser = new DefaultPathParser();
43 public void testBadPathMissingType()
45 // TODO: should we allow this instead?
46 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
50 public void testBadPathReleaseInSnapshotDir()
52 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar",
53 "non snapshot artifact inside of a snapshot dir" );
57 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
59 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
60 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
64 public void testBadPathTooShort()
66 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
70 public void testBadPathVersionMismatchA()
72 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
76 public void testBadPathVersionMismatchB()
78 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
82 public void testBadPathWrongArtifactId()
84 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
85 "wrong artifact id" );
89 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
92 public void testGoodButDualExtensions()
93 throws LayoutException
95 String groupId = "org.project";
96 String artifactId = "example-presentation";
97 String version = "3.2";
98 String classifier = null;
99 String type = "xml.zip";
100 String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
102 assertLayout( path, groupId, artifactId, version, classifier, type );
106 public void testGoodButDualExtensionsWithClassifier()
107 throws LayoutException
109 String groupId = "org.project";
110 String artifactId = "example-presentation";
111 String version = "3.2";
112 String classifier = "extras";
113 String type = "xml.zip";
114 String path = "org/project/example-presentation/3.2/example-presentation-3.2-extras.xml.zip";
116 assertLayout( path, groupId, artifactId, version, classifier, type );
120 public void testGoodButDualExtensionsTarGz()
121 throws LayoutException
123 String groupId = "org.project";
124 String artifactId = "example-distribution";
125 String version = "1.3";
126 String classifier = null;
127 String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
128 String path = "org/project/example-distribution/1.3/example-distribution-1.3.tar.gz";
130 assertLayout( path, groupId, artifactId, version, classifier, type );
134 public void testGoodButDualExtensionsTarGzAndClassifier()
135 throws LayoutException
137 String groupId = "org.project";
138 String artifactId = "example-distribution";
139 String version = "1.3";
140 String classifier = "bin";
141 String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2
142 String path = "org/project/example-distribution/1.3/example-distribution-1.3-bin.tar.gz";
144 assertLayout( path, groupId, artifactId, version, classifier, type );
148 * [MRM-432] Oddball version spec.
149 * Example of an oddball / unusual version spec.
151 * @throws LayoutException
154 public void testGoodButOddVersionSpecGanymedSsh2()
155 throws LayoutException
157 String groupId = "ch.ethz.ganymed";
158 String artifactId = "ganymed-ssh2";
159 String version = "build210";
160 String classifier = null;
162 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
164 assertLayout( path, groupId, artifactId, version, classifier, type );
168 * [MRM-432] Oddball version spec.
169 * Example of an oddball / unusual version spec.
171 * @throws LayoutException
174 public void testGoodButOddVersionSpecJavaxComm()
175 throws LayoutException
177 String groupId = "javax";
178 String artifactId = "comm";
179 String version = "3.0-u1";
180 String classifier = null;
182 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
184 assertLayout( path, groupId, artifactId, version, classifier, type );
188 * Test the ejb-client type spec.
189 * Type specs are not a 1 to 1 map to the extension.
190 * This tests that effect.
191 * @throws LayoutException
193 /* TODO: Re-enabled in the future.
194 public void testGoodFooEjbClient()
195 throws LayoutException
197 String groupId = "com.foo";
198 String artifactId = "foo-client";
199 String version = "1.0";
200 String classifier = null;
201 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
202 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
204 assertLayout( path, groupId, artifactId, version, classifier, type );
209 * [MRM-432] Oddball version spec.
210 * Example of an oddball / unusual version spec.
212 * @throws LayoutException
215 public void testGoodButOddVersionSpecJavaxPersistence()
216 throws LayoutException
218 String groupId = "javax.persistence";
219 String artifactId = "ejb";
220 String version = "3.0-public_review";
221 String classifier = null;
223 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
226 * The version id of "public_review" can cause problems. is it part of
227 * the version spec? or the classifier?
228 * Since the path spec below shows it in the path, then it is really
229 * part of the version spec.
232 assertLayout( path, groupId, artifactId, version, classifier, type );
236 public void testGoodComFooTool()
237 throws LayoutException
239 String groupId = "com.foo";
240 String artifactId = "foo-tool";
241 String version = "1.0";
242 String classifier = null;
244 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
246 assertLayout( path, groupId, artifactId, version, classifier, type );
250 public void testGoodCommonsLang()
251 throws LayoutException
253 String groupId = "commons-lang";
254 String artifactId = "commons-lang";
255 String version = "2.1";
256 String classifier = null;
258 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
260 assertLayout( path, groupId, artifactId, version, classifier, type );
264 public void testWindowsPathSeparator()
265 throws LayoutException
267 String groupId = "commons-lang";
268 String artifactId = "commons-lang";
269 String version = "2.1";
270 String classifier = null;
272 String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar";
274 assertLayout( path, groupId, artifactId, version, classifier, type );
278 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
281 public void testGoodDashedArtifactId()
282 throws LayoutException
284 String groupId = "test.maven-arch";
285 String artifactId = "test-arch";
286 String version = "2.0.3-SNAPSHOT";
287 String classifier = null;
289 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
291 assertLayout( path, groupId, artifactId, version, classifier, type );
295 * It may seem odd, but this is a valid artifact.
298 public void testGoodDotNotationArtifactId()
299 throws LayoutException
301 String groupId = "com.company.department";
302 String artifactId = "com.company.department";
303 String version = "0.2";
304 String classifier = null;
306 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
308 assertLayout( path, groupId, artifactId, version, classifier, type );
312 * It may seem odd, but this is a valid artifact.
315 public void testGoodDotNotationSameGroupIdAndArtifactId()
316 throws LayoutException
318 String groupId = "com.company.department";
319 String artifactId = "com.company.department.project";
320 String version = "0.3";
321 String classifier = null;
324 "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
326 assertLayout( path, groupId, artifactId, version, classifier, type );
330 * Test the classifier, and java-source type spec.
332 * @throws LayoutException
335 public void testGoodFooLibSources()
336 throws LayoutException
338 String groupId = "com.foo.lib";
339 String artifactId = "foo-lib";
340 String version = "2.1-alpha-1";
341 String classifier = "sources";
342 String type = "java-source"; // oddball type-spec (should result in jar extension)
343 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
345 assertLayout( path, groupId, artifactId, version, classifier, type );
349 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
351 * @throws LayoutException
354 public void testGoodSnapshotMavenTest()
355 throws LayoutException
357 String groupId = "org.apache.archiva.test";
358 String artifactId = "redonkulous";
359 String version = "3.1-beta-1-20050831.101112-42";
360 String classifier = null;
363 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
365 assertLayout( path, groupId, artifactId, version, classifier, type );
369 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
371 * @throws LayoutException
374 public void testGoodLongSnapshotMavenTest()
375 throws LayoutException
377 String groupId = "a.group.id";
378 String artifactId = "artifact-id";
379 String version = "1.0-abc-1.1-20080221.062205-9";
380 String classifier = null;
382 String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
384 assertLayout( path, groupId, artifactId, version, classifier, type );
388 * A timestamped versioned artifact but without release version part. Like on axiom trunk.
391 public void testBadSnapshotWithoutReleasePart()
393 assertBadPath( "org/apache/ws/commons/axiom/axiom/SNAPSHOT/axiom-20070912.093446-2.pom",
394 "snapshot version without release part" );
398 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
400 * @throws LayoutException
403 public void testClassifiedSnapshotMavenTest()
404 throws LayoutException
406 String groupId = "a.group.id";
407 String artifactId = "artifact-id";
408 String version = "1.0-20070219.171202-34";
409 String classifier = "test-sources";
411 String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
413 assertLayout( path, groupId, artifactId, version, classifier, type );
417 * [MRM-519] version identifiers within filename cause misidentification of version.
418 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
421 public void testGoodVersionKeywordInArtifactId()
422 throws LayoutException
424 String groupId = "maven";
425 String artifactId = "maven-test-plugin";
426 String version = "1.8.2";
427 String classifier = null;
429 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
431 assertLayout( path, groupId, artifactId, version, classifier, type );
435 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
436 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
439 public void testGoodDetectMavenTestPlugin()
440 throws LayoutException
442 String groupId = "maven";
443 String artifactId = "maven-test-plugin";
444 String version = "1.8.2";
445 String classifier = null;
446 String type = "maven-plugin";
447 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
449 assertLayout( path, groupId, artifactId, version, classifier, type );
453 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
456 public void testGoodDetectCoberturaMavenPlugin()
457 throws LayoutException
459 String groupId = "org.codehaus.mojo";
460 String artifactId = "cobertura-maven-plugin";
461 String version = "2.1";
462 String classifier = null;
463 String type = "maven-plugin";
464 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
466 assertLayout( path, groupId, artifactId, version, classifier, type );
470 public void testToArtifactOnEmptyPath()
474 parser.toArtifactReference( "" );
475 fail( "Should have failed due to empty path." );
477 catch ( LayoutException e )
484 public void testToArtifactOnNullPath()
488 parser.toArtifactReference( null );
489 fail( "Should have failed due to null path." );
491 catch ( LayoutException e )
498 public void testToArtifactReferenceOnEmptyPath()
502 parser.toArtifactReference( "" );
503 fail( "Should have failed due to empty path." );
505 catch ( LayoutException e )
512 public void testToArtifactReferenceOnNullPath()
516 parser.toArtifactReference( null );
517 fail( "Should have failed due to null path." );
519 catch ( LayoutException e )
526 * Perform a path to artifact reference lookup, and verify the results.
528 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
530 throws LayoutException
532 // Path to Artifact Reference.
533 ArtifactReference testReference = parser.toArtifactReference( path );
534 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
537 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
538 String version, String classifier, String type )
541 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
543 assertNotNull( expectedId + " - Should not be null.", actualReference );
545 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
546 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
547 if ( StringUtils.isNotBlank( classifier ) )
549 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
551 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
552 assertEquals( expectedId + " - Type", type, actualReference.getType() );
555 private void assertBadPath( String path, String reason )
559 parser.toArtifactReference( path );
561 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
563 catch ( LayoutException e )