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.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.springframework.test.context.ContextConfiguration;
29 import static org.junit.Assert.*;
32 * AbstractLegacyRepositoryContentTestCase
34 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
35 @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
36 public abstract class AbstractLegacyRepositoryContentTestCase
37 extends AbstractRepositoryLayerTestCase
40 public void testBadPathArtifactIdMissingA()
42 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
46 public void testBadPathArtifactIdMissingB()
48 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
52 public void testBadPathMissingType()
54 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
58 public void testBadPathTooShort()
61 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
65 public void testBadPathWrongPackageExtension()
67 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
71 * [MRM-432] Oddball version spec.
72 * Example of an oddball / unusual version spec.
74 * @throws org.apache.archiva.repository.layout.LayoutException
78 public void testGoodButOddVersionSpecGanymedSsh2()
79 throws LayoutException
81 String groupId = "ch.ethz.ganymed";
82 String artifactId = "ganymed-ssh2";
83 String version = "build210";
85 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
87 assertLayout( path, groupId, artifactId, version, null, type );
91 * [MRM-432] Oddball version spec.
92 * Example of an oddball / unusual version spec.
94 * @throws org.apache.archiva.repository.layout.LayoutException
98 public void testGoodButOddVersionSpecJavaxComm()
99 throws LayoutException
101 String groupId = "javax";
102 String artifactId = "comm";
103 String version = "3.0-u1";
105 String path = "javax/jars/comm-3.0-u1.jar";
107 assertLayout( path, groupId, artifactId, version, null, type );
111 * [MRM-432] Oddball version spec.
112 * Example of an oddball / unusual version spec.
114 * @throws org.apache.archiva.repository.layout.LayoutException
118 public void testGoodButOddVersionSpecJavaxPersistence()
119 throws LayoutException
121 String groupId = "javax.persistence";
122 String artifactId = "ejb";
123 String version = "3.0-public_review";
125 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
128 * The version id of "public_review" can cause problems. is it part of
129 * the version spec? or the classifier?
132 assertLayout( path, groupId, artifactId, version, null, type );
136 public void testGoodCommonsLang()
137 throws LayoutException
139 String groupId = "commons-lang";
140 String artifactId = "commons-lang";
141 String version = "2.1";
143 String path = "commons-lang/jars/commons-lang-2.1.jar";
145 assertLayout( path, groupId, artifactId, version, null, type );
149 public void testGoodDerby()
150 throws LayoutException
152 String groupId = "org.apache.derby";
153 String artifactId = "derby";
154 String version = "10.2.2.0";
156 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
158 assertLayout( path, groupId, artifactId, version, null, type );
162 * Test the ejb-client type spec.
163 * Type specs are not a 1 to 1 map to the extension.
164 * This tests that effect.
165 * @throws org.apache.archiva.repository.layout.LayoutException
167 /* TODO: Re-enabled in the future.
168 public void testGoodFooEjbClient()
169 throws LayoutException
171 String groupId = "com.foo";
172 String artifactId = "foo-client";
173 String version = "1.0";
174 String type = "ejb"; // oddball type-spec (should result in jar extension)
175 String path = "com.foo/ejbs/foo-client-1.0.jar";
177 assertLayout( path, groupId, artifactId, version, classifier, type );
182 * Test the classifier.
184 * @throws org.apache.archiva.repository.layout.LayoutException
188 public void testGoodFooLibJavadoc()
189 throws LayoutException
191 String groupId = "com.foo.lib";
192 String artifactId = "foo-lib";
193 String version = "2.1-alpha-1";
194 String type = "javadoc";
195 String classifier = "javadoc";
196 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
198 assertLayout( path, groupId, artifactId, version, classifier, type );
202 * Test the classifier, and java-source type spec.
204 * @throws org.apache.archiva.repository.layout.LayoutException
208 public void testGoodFooLibSources()
209 throws LayoutException
211 String groupId = "com.foo.lib";
212 String artifactId = "foo-lib";
213 String version = "2.1-alpha-1";
214 String type = "java-source"; // oddball type-spec (should result in jar extension)
215 String classifier = "sources";
216 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
218 assertLayout( path, groupId, artifactId, version, classifier, type );
222 public void testGoodFooTool()
223 throws LayoutException
225 String groupId = "com.foo";
226 String artifactId = "foo-tool";
227 String version = "1.0";
229 String path = "com.foo/jars/foo-tool-1.0.jar";
231 assertLayout( path, groupId, artifactId, version, null, type );
235 public void testGoodGeronimoEjbSpec()
236 throws LayoutException
238 String groupId = "org.apache.geronimo.specs";
239 String artifactId = "geronimo-ejb_2.1_spec";
240 String version = "1.0.1";
242 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
244 assertLayout( path, groupId, artifactId, version, null, type );
248 public void testGoodLdapClientsPom()
249 throws LayoutException
251 String groupId = "directory-clients";
252 String artifactId = "ldap-clients";
253 String version = "0.9.1-SNAPSHOT";
255 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
257 assertLayout( path, groupId, artifactId, version, null, type );
261 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
263 * @throws org.apache.archiva.repository.layout.LayoutException
267 public void testGoodSnapshotMavenTest()
268 throws LayoutException
270 String groupId = "org.apache.archiva.test";
271 String artifactId = "redonkulous";
272 String version = "3.1-beta-1-20050831.101112-42";
274 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
276 assertLayout( path, groupId, artifactId, version, null, type );
280 * [MRM-519] version identifiers within filename cause misidentification of version.
281 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
284 public void testGoodVersionKeywordInArtifactId()
285 throws LayoutException
287 String groupId = "maven";
288 String artifactId = "maven-test-plugin";
289 String version = "1.8.2";
292 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
294 assertLayout( path, groupId, artifactId, version, null, type );
298 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
299 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
302 public void testGoodDetectPluginMavenTest()
303 throws LayoutException
305 String groupId = "maven";
306 String artifactId = "maven-test-plugin";
307 String version = "1.8.2";
308 String type = "maven-one-plugin";
309 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
311 assertLayout( path, groupId, artifactId, version, null, type );
315 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
318 public void testGoodDetectPluginAvalonMeta()
319 throws LayoutException
321 String groupId = "avalon-meta";
322 String artifactId = "avalon-meta-plugin";
323 String version = "1.1";
324 String type = "maven-one-plugin";
325 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
327 assertLayout( path, groupId, artifactId, version, null, type );
331 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
334 public void testGoodDetectPluginCactusMaven()
335 throws LayoutException
337 String groupId = "cactus";
338 String artifactId = "cactus-maven";
339 String version = "1.7dev-20040815";
340 String type = "maven-one-plugin";
341 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
343 assertLayout( path, groupId, artifactId, version, null, type );
347 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
350 public void testGoodDetectPluginGeronimoPackaging()
351 throws LayoutException
353 String groupId = "geronimo";
354 String artifactId = "geronimo-packaging-plugin";
355 String version = "1.0.1";
356 String type = "maven-one-plugin";
357 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
359 assertLayout( path, groupId, artifactId, version, null, type );
363 * [MRM-768] Artifact type "maven-plugin" does not distinguish maven1 and maven2 plugins.
364 * This produces conflicts when m2 plugins are stored in legacy-layout repository
367 public void testMaven1Maven2PluginTypeDistinc()
370 String groupId = "com.sun.tools.xjc.maven2";
371 String artifactId = "maven-jaxb-plugin";
372 String version = "1.1";
373 String type = "maven-plugin";
374 String path = "com.sun.tools.xjc.maven2/maven-plugins/maven-jaxb-plugin-1.1.jar";
376 assertLayout( path, groupId, artifactId, version, null, type );
380 * Perform a roundtrip through the layout routines to determine success.
382 * @param classifier TODO
384 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
386 throws LayoutException
388 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
390 // --- Artifact Tests.
392 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
394 // --- Artifact Reference Tests
396 // Path to Artifact Reference.
397 ArtifactReference testReference = toArtifactReference( path );
398 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
400 // And back again, using test Reference from previous step.
401 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
404 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
405 String version, String classifier, String type )
407 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
409 assertNotNull( expectedId + " - Should not be null.", actualReference );
411 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
412 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
413 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
414 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
415 assertEquals( expectedId + " - Type", type, actualReference.getType() );
418 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier,
421 ArtifactReference artifact = new ArtifactReference();
422 artifact.setGroupId( groupId );
423 artifact.setArtifactId( artifactId );
424 artifact.setVersion( version );
425 artifact.setClassifier( classifier );
426 artifact.setType( type );
427 assertNotNull( artifact );
431 private void assertBadPath( String path, String reason )
435 toArtifactReference( path );
437 "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
439 catch ( LayoutException e )
446 protected abstract ArtifactReference toArtifactReference( String path )
447 throws LayoutException;
449 protected abstract String toPath( ArtifactReference reference );