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.AbstractRepositoryLayerTestCase;
24 import org.apache.archiva.repository.layout.LayoutException;
25 import org.apache.commons.lang.StringUtils;
26 import org.junit.Test;
28 import static org.junit.Assert.*;
31 * AbstractDefaultRepositoryContentTestCase
33 public abstract class AbstractDefaultRepositoryContentTestCase
34 extends AbstractRepositoryLayerTestCase
37 public void testBadPathMissingType()
39 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
43 public void testBadPathReleaseInSnapshotDir()
45 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar",
46 "non snapshot artifact inside of a snapshot dir" );
50 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
52 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
53 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
57 public void testBadPathTooShort()
59 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
63 public void testBadPathVersionMismatchA()
65 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
69 public void testBadPathVersionMismatchB()
71 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
75 public void testBadPathWrongArtifactId()
77 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
78 "wrong artifact id" );
82 * [MRM-432] Oddball version spec.
83 * Example of an oddball / unusual version spec.
85 * @throws org.apache.archiva.repository.layout.LayoutException
89 public void testGoodButOddVersionSpecGanymedSsh2()
90 throws LayoutException
92 String groupId = "ch.ethz.ganymed";
93 String artifactId = "ganymed-ssh2";
94 String version = "build210";
95 String classifier = null;
97 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
99 assertLayout( path, groupId, artifactId, version, classifier, type );
103 * [MRM-432] Oddball version spec.
104 * Example of an oddball / unusual version spec.
106 * @throws org.apache.archiva.repository.layout.LayoutException
110 public void testGoodButOddVersionSpecJavaxComm()
111 throws LayoutException
113 String groupId = "javax";
114 String artifactId = "comm";
115 String version = "3.0-u1";
116 String classifier = null;
118 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
120 assertLayout( path, groupId, artifactId, version, classifier, type );
124 * Test the ejb-client type spec.
125 * Type specs are not a 1 to 1 map to the extension.
126 * This tests that effect.
127 * @throws org.apache.archiva.repository.layout.LayoutException
129 /* TODO: Re-enabled in the future.
130 public void testGoodFooEjbClient()
131 throws LayoutException
133 String groupId = "com.foo";
134 String artifactId = "foo-client";
135 String version = "1.0";
136 String classifier = null;
137 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
138 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
140 assertLayout( path, groupId, artifactId, version, classifier, type );
145 * [MRM-432] Oddball version spec.
146 * Example of an oddball / unusual version spec.
148 * @throws org.apache.archiva.repository.layout.LayoutException
152 public void testGoodButOddVersionSpecJavaxPersistence()
153 throws LayoutException
155 String groupId = "javax.persistence";
156 String artifactId = "ejb";
157 String version = "3.0-public_review";
158 String classifier = null;
160 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
163 * The version id of "public_review" can cause problems. is it part of
164 * the version spec? or the classifier?
165 * Since the path spec below shows it in the path, then it is really
166 * part of the version spec.
169 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 );
187 public void testGoodCommonsLang()
188 throws LayoutException
190 String groupId = "commons-lang";
191 String artifactId = "commons-lang";
192 String version = "2.1";
193 String classifier = null;
195 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
197 assertLayout( path, groupId, artifactId, version, classifier, type );
201 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
204 public void testGoodDashedArtifactId()
205 throws LayoutException
207 String groupId = "test.maven-arch";
208 String artifactId = "test-arch";
209 String version = "2.0.3-SNAPSHOT";
210 String classifier = null;
212 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
214 assertLayout( path, groupId, artifactId, version, classifier, type );
218 * It may seem odd, but this is a valid artifact.
221 public void testGoodDotNotationArtifactId()
222 throws LayoutException
224 String groupId = "com.company.department";
225 String artifactId = "com.company.department";
226 String version = "0.2";
227 String classifier = null;
229 String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
231 assertLayout( path, groupId, artifactId, version, classifier, type );
235 * It may seem odd, but this is a valid artifact.
238 public void testGoodDotNotationSameGroupIdAndArtifactId()
239 throws LayoutException
241 String groupId = "com.company.department";
242 String artifactId = "com.company.department.project";
243 String version = "0.3";
244 String classifier = null;
247 "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
249 assertLayout( path, groupId, artifactId, version, classifier, type );
253 * Test the classifier, and java-source type spec.
255 * @throws org.apache.archiva.repository.layout.LayoutException
259 public void testGoodFooLibSources()
260 throws LayoutException
262 String groupId = "com.foo.lib";
263 String artifactId = "foo-lib";
264 String version = "2.1-alpha-1";
265 String classifier = "sources";
266 String type = "java-source"; // oddball type-spec (should result in jar extension)
267 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
269 assertLayout( path, groupId, artifactId, version, classifier, type );
273 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
275 * @throws org.apache.archiva.repository.layout.LayoutException
279 public void testGoodSnapshotMavenTest()
280 throws LayoutException
282 String groupId = "org.apache.archiva.test";
283 String artifactId = "redonkulous";
284 String version = "3.1-beta-1-20050831.101112-42";
285 String classifier = null;
288 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
290 assertLayout( path, groupId, artifactId, version, classifier, type );
294 * [MRM-519] version identifiers within filename cause misidentification of version.
295 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
298 public void testGoodVersionKeywordInArtifactId()
299 throws LayoutException
301 String groupId = "maven";
302 String artifactId = "maven-test-plugin";
303 String version = "1.8.2";
304 String classifier = null;
306 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
308 assertLayout( path, groupId, artifactId, version, classifier, type );
312 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
313 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
316 public void testGoodDetectMavenTestPlugin()
317 throws LayoutException
319 String groupId = "maven";
320 String artifactId = "maven-test-plugin";
321 String version = "1.8.2";
322 String classifier = null;
323 String type = "maven-plugin";
324 String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar";
326 assertLayout( path, groupId, artifactId, version, classifier, type );
330 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
333 public void testGoodDetectCoberturaMavenPlugin()
334 throws LayoutException
336 String groupId = "org.codehaus.mojo";
337 String artifactId = "cobertura-maven-plugin";
338 String version = "2.1";
339 String classifier = null;
340 String type = "maven-plugin";
341 String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar";
343 assertLayout( path, groupId, artifactId, version, classifier, type );
347 public void testToArtifactOnEmptyPath()
351 toArtifactReference( "" );
352 fail( "Should have failed due to empty path." );
354 catch ( LayoutException e )
361 public void testToArtifactOnNullPath()
365 toArtifactReference( null );
366 fail( "Should have failed due to null path." );
368 catch ( LayoutException e )
375 public void testToArtifactReferenceOnEmptyPath()
379 toArtifactReference( "" );
380 fail( "Should have failed due to empty path." );
382 catch ( LayoutException e )
389 public void testToArtifactReferenceOnNullPath()
393 toArtifactReference( null );
394 fail( "Should have failed due to null path." );
396 catch ( LayoutException e )
403 public void testToPathOnNullArtifactReference()
408 ArtifactReference reference = null;
410 fail( "Should have failed due to null artifact reference." );
412 catch ( IllegalArgumentException e )
418 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
419 String version, String classifier, String type )
422 "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
424 assertNotNull( expectedId + " - Should not be null.", actualReference );
426 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
427 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
428 if ( StringUtils.isNotBlank( classifier ) )
430 assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
432 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
433 assertEquals( expectedId + " - Type", type, actualReference.getType() );
436 private void assertBadPath( String path, String reason )
440 toArtifactReference( path );
442 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
444 catch ( LayoutException e )
451 * Perform a roundtrip through the layout routines to determine success.
453 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
455 throws LayoutException
457 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
459 // --- Artifact Tests.
462 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
464 // --- Artifact Reference Tests
466 // Path to Artifact Reference.
467 ArtifactReference testReference = toArtifactReference( path );
468 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
470 // And back again, using test Reference from previous step.
471 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
474 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier,
477 ArtifactReference artifact = new ArtifactReference();
478 artifact.setGroupId( groupId );
479 artifact.setArtifactId( artifactId );
480 artifact.setVersion( version );
481 artifact.setClassifier( classifier );
482 artifact.setType( type );
483 assertNotNull( artifact );
487 protected abstract ArtifactReference toArtifactReference( String path )
488 throws LayoutException;
490 protected abstract String toPath( ArtifactReference reference );