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.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
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 * AbstractLegacyRepositoryContentTestCase
35 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
36 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
37 public abstract class AbstractLegacyRepositoryContentTestCase
38 extends AbstractRepositoryLayerTestCase
42 public void testBadPathArtifactIdMissingA()
44 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
48 public void testBadPathArtifactIdMissingB()
50 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
55 public void testBadPathMissingType()
57 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
61 public void testBadPathTooShort()
64 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
69 public void testBadPathWrongPackageExtension()
71 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
75 * [MRM-432] Oddball version spec.
76 * Example of an oddball / unusual version spec.
78 * @throws org.apache.archiva.repository.layout.LayoutException
82 public void testGoodButOddVersionSpecGanymedSsh2()
83 throws LayoutException
85 String groupId = "ch.ethz.ganymed";
86 String artifactId = "ganymed-ssh2";
87 String version = "build210";
89 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
91 assertLayout( path, groupId, artifactId, version, null, type );
95 * [MRM-432] Oddball version spec.
96 * Example of an oddball / unusual version spec.
98 * @throws org.apache.archiva.repository.layout.LayoutException
102 public void testGoodButOddVersionSpecJavaxComm()
103 throws LayoutException
105 String groupId = "javax";
106 String artifactId = "comm";
107 String version = "3.0-u1";
109 String path = "javax/jars/comm-3.0-u1.jar";
111 assertLayout( path, groupId, artifactId, version, null, type );
115 * [MRM-432] Oddball version spec.
116 * Example of an oddball / unusual version spec.
118 * @throws org.apache.archiva.repository.layout.LayoutException
122 public void testGoodButOddVersionSpecJavaxPersistence()
123 throws LayoutException
125 String groupId = "javax.persistence";
126 String artifactId = "ejb";
127 String version = "3.0-public_review";
129 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
132 * The version id of "public_review" can cause problems. is it part of
133 * the version spec? or the classifier?
136 assertLayout( path, groupId, artifactId, version, null, type );
140 public void testGoodCommonsLang()
141 throws LayoutException
143 String groupId = "commons-lang";
144 String artifactId = "commons-lang";
145 String version = "2.1";
147 String path = "commons-lang/jars/commons-lang-2.1.jar";
149 assertLayout( path, groupId, artifactId, version, null, type );
153 public void testGoodDerby()
154 throws LayoutException
156 String groupId = "org.apache.derby";
157 String artifactId = "derby";
158 String version = "10.2.2.0";
160 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
162 assertLayout( path, groupId, artifactId, version, null, type );
166 * Test the ejb-client type spec.
167 * Type specs are not a 1 to 1 map to the extension.
168 * This tests that effect.
169 * @throws org.apache.archiva.repository.layout.LayoutException
171 /* TODO: Re-enabled in the future.
172 public void testGoodFooEjbClient()
173 throws LayoutException
175 String groupId = "com.foo";
176 String artifactId = "foo-client";
177 String version = "1.0";
178 String type = "ejb"; // oddball type-spec (should result in jar extension)
179 String path = "com.foo/ejbs/foo-client-1.0.jar";
181 assertLayout( path, groupId, artifactId, version, classifier, type );
186 * Test the classifier.
188 * @throws org.apache.archiva.repository.layout.LayoutException
192 public void testGoodFooLibJavadoc()
193 throws LayoutException
195 String groupId = "com.foo.lib";
196 String artifactId = "foo-lib";
197 String version = "2.1-alpha-1";
198 String type = "javadoc";
199 String classifier = "javadoc";
200 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
202 assertLayout( path, groupId, artifactId, version, classifier, type );
206 * Test the classifier, and java-source type spec.
208 * @throws org.apache.archiva.repository.layout.LayoutException
212 public void testGoodFooLibSources()
213 throws LayoutException
215 String groupId = "com.foo.lib";
216 String artifactId = "foo-lib";
217 String version = "2.1-alpha-1";
218 String type = "java-source"; // oddball type-spec (should result in jar extension)
219 String classifier = "sources";
220 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
222 assertLayout( path, groupId, artifactId, version, classifier, type );
226 public void testGoodFooTool()
227 throws LayoutException
229 String groupId = "com.foo";
230 String artifactId = "foo-tool";
231 String version = "1.0";
233 String path = "com.foo/jars/foo-tool-1.0.jar";
235 assertLayout( path, groupId, artifactId, version, null, type );
239 public void testGoodGeronimoEjbSpec()
240 throws LayoutException
242 String groupId = "org.apache.geronimo.specs";
243 String artifactId = "geronimo-ejb_2.1_spec";
244 String version = "1.0.1";
246 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
248 assertLayout( path, groupId, artifactId, version, null, type );
252 public void testGoodLdapClientsPom()
253 throws LayoutException
255 String groupId = "directory-clients";
256 String artifactId = "ldap-clients";
257 String version = "0.9.1-SNAPSHOT";
259 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
261 assertLayout( path, groupId, artifactId, version, null, type );
265 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
267 * @throws org.apache.archiva.repository.layout.LayoutException
271 public void testGoodSnapshotMavenTest()
272 throws LayoutException
274 String groupId = "org.apache.archiva.test";
275 String artifactId = "redonkulous";
276 String version = "3.1-beta-1-20050831.101112-42";
278 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
280 assertLayout( path, groupId, artifactId, version, null, type );
284 * [MRM-519] version identifiers within filename cause misidentification of version.
285 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
288 public void testGoodVersionKeywordInArtifactId()
289 throws LayoutException
291 String groupId = "maven";
292 String artifactId = "maven-test-plugin";
293 String version = "1.8.2";
296 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
298 assertLayout( path, groupId, artifactId, version, null, type );
302 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
303 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
306 public void testGoodDetectPluginMavenTest()
307 throws LayoutException
309 String groupId = "maven";
310 String artifactId = "maven-test-plugin";
311 String version = "1.8.2";
312 String type = "maven-one-plugin";
313 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
315 assertLayout( path, groupId, artifactId, version, null, type );
319 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
322 public void testGoodDetectPluginAvalonMeta()
323 throws LayoutException
325 String groupId = "avalon-meta";
326 String artifactId = "avalon-meta-plugin";
327 String version = "1.1";
328 String type = "maven-one-plugin";
329 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
331 assertLayout( path, groupId, artifactId, version, null, type );
335 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
338 public void testGoodDetectPluginCactusMaven()
339 throws LayoutException
341 String groupId = "cactus";
342 String artifactId = "cactus-maven";
343 String version = "1.7dev-20040815";
344 String type = "maven-one-plugin";
345 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
347 assertLayout( path, groupId, artifactId, version, null, type );
351 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
354 public void testGoodDetectPluginGeronimoPackaging()
355 throws LayoutException
357 String groupId = "geronimo";
358 String artifactId = "geronimo-packaging-plugin";
359 String version = "1.0.1";
360 String type = "maven-one-plugin";
361 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
363 assertLayout( path, groupId, artifactId, version, null, type );
367 * [MRM-768] Artifact type "maven-plugin" does not distinguish maven1 and maven2 plugins.
368 * This produces conflicts when m2 plugins are stored in legacy-layout repository
371 public void testMaven1Maven2PluginTypeDistinc()
374 String groupId = "com.sun.tools.xjc.maven2";
375 String artifactId = "maven-jaxb-plugin";
376 String version = "1.1";
377 String type = "maven-plugin";
378 String path = "com.sun.tools.xjc.maven2/maven-plugins/maven-jaxb-plugin-1.1.jar";
380 assertLayout( path, groupId, artifactId, version, null, type );
384 * Perform a roundtrip through the layout routines to determine success.
386 * @param classifier TODO
388 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
390 throws LayoutException
392 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
394 // --- Artifact Tests.
396 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
398 // --- Artifact Reference Tests
400 // Path to Artifact Reference.
401 ArtifactReference testReference = toArtifactReference( path );
402 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
404 // And back again, using test Reference from previous step.
405 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
408 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
409 String version, String classifier, String type )
411 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
413 assertNotNull( expectedId + " - Should not be null.", actualReference );
415 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
416 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
417 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
418 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
419 assertEquals( expectedId + " - Type", type, actualReference.getType() );
422 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier,
425 ArtifactReference artifact = new ArtifactReference();
426 artifact.setGroupId( groupId );
427 artifact.setArtifactId( artifactId );
428 artifact.setVersion( version );
429 artifact.setClassifier( classifier );
430 artifact.setType( type );
431 assertNotNull( artifact );
435 private void assertBadPath( String path, String reason )
439 toArtifactReference( path );
441 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
443 catch ( LayoutException e )
450 protected abstract ArtifactReference toArtifactReference( String path )
451 throws LayoutException;
453 protected abstract String toPath( ArtifactReference reference );