1 package org.apache.archiva.metadata.repository.storage.maven2;
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.archiva.model.ArtifactReference;
23 import org.apache.archiva.repository.layout.LayoutException;
24 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
25 import org.apache.commons.lang.StringUtils;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.springframework.test.context.ContextConfiguration;
30 import static org.junit.Assert.*;
33 * AbstractDefaultRepositoryContentTestCase
35 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
36 @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
37 public abstract class AbstractDefaultRepositoryContentTestCase
38 extends AbstractRepositoryLayerTestCase
41 public void testBadPathMissingType()
43 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
47 public void testBadPathReleaseInSnapshotDir()
49 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar",
50 "non snapshot artifact inside of a snapshot dir" );
54 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
56 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
57 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
61 public void testBadPathTooShort()
63 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
67 public void testBadPathVersionMismatchA()
69 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
73 public void testBadPathVersionMismatchB()
75 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
79 public void testBadPathWrongArtifactId()
81 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
82 "wrong artifact id" );
86 * [MRM-432] Oddball version spec.
87 * Example of an oddball / unusual version spec.
89 * @throws org.apache.archiva.repository.layout.LayoutException
93 public void testGoodButOddVersionSpecGanymedSsh2()
94 throws LayoutException
96 String groupId = "ch.ethz.ganymed";
97 String artifactId = "ganymed-ssh2";
98 String version = "build210";
99 String classifier = null;
101 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
103 assertLayout( path, groupId, artifactId, version, classifier, type );
107 * [MRM-432] Oddball version spec.
108 * Example of an oddball / unusual version spec.
110 * @throws org.apache.archiva.repository.layout.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 org.apache.archiva.repository.layout.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.
152 * @throws org.apache.archiva.repository.layout.LayoutException
156 public void testGoodButOddVersionSpecJavaxPersistence()
157 throws LayoutException
159 String groupId = "javax.persistence";
160 String artifactId = "ejb";
161 String version = "3.0-public_review";
162 String classifier = null;
164 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
167 * The version id of "public_review" can cause problems. is it part of
168 * the version spec? or the classifier?
169 * Since the path spec below shows it in the path, then it is really
170 * part of the version spec.
173 assertLayout( path, groupId, artifactId, version, classifier, type );
177 public void testGoodComFooTool()
178 throws LayoutException
180 String groupId = "com.foo";
181 String artifactId = "foo-tool";
182 String version = "1.0";
183 String classifier = null;
185 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
187 assertLayout( path, groupId, artifactId, version, classifier, type );
191 public void testGoodCommonsLang()
192 throws LayoutException
194 String groupId = "commons-lang";
195 String artifactId = "commons-lang";
196 String version = "2.1";
197 String classifier = null;
199 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
201 assertLayout( path, groupId, artifactId, version, classifier, type );
205 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
208 public void testGoodDashedArtifactId()
209 throws LayoutException
211 String groupId = "test.maven-arch";
212 String artifactId = "test-arch";
213 String version = "2.0.3-SNAPSHOT";
214 String classifier = null;
216 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
218 assertLayout( path, groupId, artifactId, version, classifier, type );
222 * It may seem odd, but this is a valid artifact.
225 public void testGoodDotNotationArtifactId()
226 throws LayoutException
228 String groupId = "com.company.department";
229 String artifactId = "com.company.department";
230 String version = "0.2";
231 String classifier = null;
233 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
235 assertLayout( path, groupId, artifactId, version, classifier, type );
239 * It may seem odd, but this is a valid artifact.
242 public void testGoodDotNotationSameGroupIdAndArtifactId()
243 throws LayoutException
245 String groupId = "com.company.department";
246 String artifactId = "com.company.department.project";
247 String version = "0.3";
248 String classifier = null;
251 "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
253 assertLayout( path, groupId, artifactId, version, classifier, type );
257 * Test the classifier, and java-source type spec.
259 * @throws org.apache.archiva.repository.layout.LayoutException
263 public void testGoodFooLibSources()
264 throws LayoutException
266 String groupId = "com.foo.lib";
267 String artifactId = "foo-lib";
268 String version = "2.1-alpha-1";
269 String classifier = "sources";
270 String type = "java-source"; // oddball type-spec (should result in jar extension)
271 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
273 assertLayout( path, groupId, artifactId, version, classifier, type );
277 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
279 * @throws org.apache.archiva.repository.layout.LayoutException
283 public void testGoodSnapshotMavenTest()
284 throws LayoutException
286 String groupId = "org.apache.archiva.test";
287 String artifactId = "redonkulous";
288 String version = "3.1-beta-1-20050831.101112-42";
289 String classifier = null;
292 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
294 assertLayout( path, groupId, artifactId, version, classifier, type );
298 * [MRM-519] version identifiers within filename cause misidentification of version.
299 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
302 public void testGoodVersionKeywordInArtifactId()
303 throws LayoutException
305 String groupId = "maven";
306 String artifactId = "maven-test-plugin";
307 String version = "1.8.2";
308 String classifier = null;
310 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
312 assertLayout( path, groupId, artifactId, version, classifier, type );
316 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
317 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
320 public void testGoodDetectMavenTestPlugin()
321 throws LayoutException
323 String groupId = "maven";
324 String artifactId = "maven-test-plugin";
325 String version = "1.8.2";
326 String classifier = null;
327 String type = "maven-plugin";
328 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
330 assertLayout( path, groupId, artifactId, version, classifier, type );
334 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
337 public void testGoodDetectCoberturaMavenPlugin()
338 throws LayoutException
340 String groupId = "org.codehaus.mojo";
341 String artifactId = "cobertura-maven-plugin";
342 String version = "2.1";
343 String classifier = null;
344 String type = "maven-plugin";
345 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
347 assertLayout( path, groupId, artifactId, version, classifier, type );
351 public void testToArtifactOnEmptyPath()
355 toArtifactReference( "" );
356 fail( "Should have failed due to empty path." );
358 catch ( LayoutException e )
365 public void testToArtifactOnNullPath()
369 toArtifactReference( null );
370 fail( "Should have failed due to null path." );
372 catch ( LayoutException e )
379 public void testToArtifactReferenceOnEmptyPath()
383 toArtifactReference( "" );
384 fail( "Should have failed due to empty path." );
386 catch ( LayoutException e )
393 public void testToArtifactReferenceOnNullPath()
397 toArtifactReference( null );
398 fail( "Should have failed due to null path." );
400 catch ( LayoutException e )
407 public void testToPathOnNullArtifactReference()
412 ArtifactReference reference = null;
414 fail( "Should have failed due to null artifact reference." );
416 catch ( IllegalArgumentException e )
422 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
423 String version, String classifier, String type )
426 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
428 assertNotNull( expectedId + " - Should not be null.", actualReference );
430 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
431 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
432 if ( StringUtils.isNotBlank( classifier ) )
434 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
436 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
437 assertEquals( expectedId + " - Type", type, actualReference.getType() );
440 private void assertBadPath( String path, String reason )
444 toArtifactReference( path );
446 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
448 catch ( LayoutException e )
455 * Perform a roundtrip through the layout routines to determine success.
457 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
459 throws LayoutException
461 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
463 // --- Artifact Tests.
466 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
468 // --- Artifact Reference Tests
470 // Path to Artifact Reference.
471 ArtifactReference testReference = toArtifactReference( path );
472 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
474 // And back again, using test Reference from previous step.
475 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
478 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier,
481 ArtifactReference artifact = new ArtifactReference();
482 artifact.setGroupId( groupId );
483 artifact.setArtifactId( artifactId );
484 artifact.setVersion( version );
485 artifact.setClassifier( classifier );
486 artifact.setType( type );
487 assertNotNull( artifact );
491 protected abstract ArtifactReference toArtifactReference( String path )
492 throws LayoutException;
494 protected abstract String toPath( ArtifactReference reference );