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
36 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
37 @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
38 public abstract class AbstractLegacyRepositoryContentTestCase
41 public void testBadPathArtifactIdMissingA()
43 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
47 public void testBadPathArtifactIdMissingB()
49 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
53 public void testBadPathMissingType()
55 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
59 public void testBadPathTooShort()
62 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
66 public void testBadPathWrongPackageExtension()
68 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
72 * [MRM-432] Oddball version spec.
73 * Example of an oddball / unusual version spec.
74 * @throws org.apache.archiva.repository.layout.LayoutException
77 public void testGoodButOddVersionSpecGanymedSsh2()
78 throws LayoutException
80 String groupId = "ch.ethz.ganymed";
81 String artifactId = "ganymed-ssh2";
82 String version = "build210";
84 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
86 assertLayout( path, groupId, artifactId, version, null, type );
90 * [MRM-432] Oddball version spec.
91 * Example of an oddball / unusual version spec.
92 * @throws org.apache.archiva.repository.layout.LayoutException
95 public void testGoodButOddVersionSpecJavaxComm()
96 throws LayoutException
98 String groupId = "javax";
99 String artifactId = "comm";
100 String version = "3.0-u1";
102 String path = "javax/jars/comm-3.0-u1.jar";
104 assertLayout( path, groupId, artifactId, version, null, type );
108 * [MRM-432] Oddball version spec.
109 * Example of an oddball / unusual version spec.
110 * @throws org.apache.archiva.repository.layout.LayoutException
113 public void testGoodButOddVersionSpecJavaxPersistence()
114 throws LayoutException
116 String groupId = "javax.persistence";
117 String artifactId = "ejb";
118 String version = "3.0-public_review";
120 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
123 * The version id of "public_review" can cause problems. is it part of
124 * the version spec? or the classifier?
127 assertLayout( path, groupId, artifactId, version, null, type );
131 public void testGoodCommonsLang()
132 throws LayoutException
134 String groupId = "commons-lang";
135 String artifactId = "commons-lang";
136 String version = "2.1";
138 String path = "commons-lang/jars/commons-lang-2.1.jar";
140 assertLayout( path, groupId, artifactId, version, null, type );
144 public void testGoodDerby()
145 throws LayoutException
147 String groupId = "org.apache.derby";
148 String artifactId = "derby";
149 String version = "10.2.2.0";
151 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
153 assertLayout( path, groupId, artifactId, version, null, type );
157 * Test the ejb-client type spec.
158 * Type specs are not a 1 to 1 map to the extension.
159 * This tests that effect.
160 * @throws org.apache.archiva.repository.layout.LayoutException
162 /* TODO: Re-enabled in the future.
163 public void testGoodFooEjbClient()
164 throws LayoutException
166 String groupId = "com.foo";
167 String artifactId = "foo-client";
168 String version = "1.0";
169 String type = "ejb"; // oddball type-spec (should result in jar extension)
170 String path = "com.foo/ejbs/foo-client-1.0.jar";
172 assertLayout( path, groupId, artifactId, version, classifier, type );
177 * Test the classifier.
178 * @throws org.apache.archiva.repository.layout.LayoutException
181 public void testGoodFooLibJavadoc()
182 throws LayoutException
184 String groupId = "com.foo.lib";
185 String artifactId = "foo-lib";
186 String version = "2.1-alpha-1";
187 String type = "javadoc";
188 String classifier = "javadoc";
189 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
191 assertLayout( path, groupId, artifactId, version, classifier, type );
195 * Test the classifier, and java-source type spec.
196 * @throws org.apache.archiva.repository.layout.LayoutException
199 public void testGoodFooLibSources()
200 throws LayoutException
202 String groupId = "com.foo.lib";
203 String artifactId = "foo-lib";
204 String version = "2.1-alpha-1";
205 String type = "java-source"; // oddball type-spec (should result in jar extension)
206 String classifier = "sources";
207 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
209 assertLayout( path, groupId, artifactId, version, classifier, type );
213 public void testGoodFooTool()
214 throws LayoutException
216 String groupId = "com.foo";
217 String artifactId = "foo-tool";
218 String version = "1.0";
220 String path = "com.foo/jars/foo-tool-1.0.jar";
222 assertLayout( path, groupId, artifactId, version, null, type );
226 public void testGoodGeronimoEjbSpec()
227 throws LayoutException
229 String groupId = "org.apache.geronimo.specs";
230 String artifactId = "geronimo-ejb_2.1_spec";
231 String version = "1.0.1";
233 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
235 assertLayout( path, groupId, artifactId, version, null, type );
239 public void testGoodLdapClientsPom()
240 throws LayoutException
242 String groupId = "directory-clients";
243 String artifactId = "ldap-clients";
244 String version = "0.9.1-SNAPSHOT";
246 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
248 assertLayout( path, groupId, artifactId, version, null, type );
252 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
253 * @throws org.apache.archiva.repository.layout.LayoutException
256 public void testGoodSnapshotMavenTest()
257 throws LayoutException
259 String groupId = "org.apache.archiva.test";
260 String artifactId = "redonkulous";
261 String version = "3.1-beta-1-20050831.101112-42";
263 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
265 assertLayout( path, groupId, artifactId, version, null, type );
269 * [MRM-519] version identifiers within filename cause misidentification of version.
270 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
273 public void testGoodVersionKeywordInArtifactId()
274 throws LayoutException
276 String groupId = "maven";
277 String artifactId = "maven-test-plugin";
278 String version = "1.8.2";
281 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
283 assertLayout( path, groupId, artifactId, version, null, type );
287 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
288 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
291 public void testGoodDetectPluginMavenTest()
292 throws LayoutException
294 String groupId = "maven";
295 String artifactId = "maven-test-plugin";
296 String version = "1.8.2";
297 String type = "maven-one-plugin";
298 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
300 assertLayout( path, groupId, artifactId, version, null, type );
304 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
307 public void testGoodDetectPluginAvalonMeta()
308 throws LayoutException
310 String groupId = "avalon-meta";
311 String artifactId = "avalon-meta-plugin";
312 String version = "1.1";
313 String type = "maven-one-plugin";
314 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
316 assertLayout( path, groupId, artifactId, version, null, type );
320 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
323 public void testGoodDetectPluginCactusMaven()
324 throws LayoutException
326 String groupId = "cactus";
327 String artifactId = "cactus-maven";
328 String version = "1.7dev-20040815";
329 String type = "maven-one-plugin";
330 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
332 assertLayout( path, groupId, artifactId, version, null, type );
336 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
339 public void testGoodDetectPluginGeronimoPackaging()
340 throws LayoutException
342 String groupId = "geronimo";
343 String artifactId = "geronimo-packaging-plugin";
344 String version = "1.0.1";
345 String type = "maven-one-plugin";
346 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
348 assertLayout( path, groupId, artifactId, version, null, type );
352 * [MRM-768] Artifact type "maven-plugin" does not distinguish maven1 and maven2 plugins.
353 * This produces conflicts when m2 plugins are stored in legacy-layout repository
356 public void testMaven1Maven2PluginTypeDistinc()
359 String groupId = "com.sun.tools.xjc.maven2";
360 String artifactId = "maven-jaxb-plugin";
361 String version = "1.1";
362 String type = "maven-plugin";
363 String path = "com.sun.tools.xjc.maven2/maven-plugins/maven-jaxb-plugin-1.1.jar";
365 assertLayout( path, groupId, artifactId, version, null, type );
369 * Perform a roundtrip through the layout routines to determine success.
370 * @param classifier TODO
372 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
373 throws LayoutException
375 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
377 // --- Artifact Tests.
379 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
381 // --- Artifact Reference Tests
383 // Path to Artifact Reference.
384 ArtifactReference testReference = toArtifactReference( path );
385 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
387 // And back again, using test Reference from previous step.
388 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
391 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
392 String version, String classifier, String type )
394 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
396 assertNotNull( expectedId + " - Should not be null.", actualReference );
398 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
399 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
400 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
401 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
402 assertEquals( expectedId + " - Type", type, actualReference.getType() );
405 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
407 ArtifactReference artifact = new ArtifactReference();
408 artifact.setGroupId( groupId );
409 artifact.setArtifactId( artifactId );
410 artifact.setVersion( version );
411 artifact.setClassifier( classifier );
412 artifact.setType( type );
413 assertNotNull( artifact );
417 private void assertBadPath( String path, String reason )
421 toArtifactReference( path );
422 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
424 catch ( LayoutException e )
431 protected abstract ArtifactReference toArtifactReference( String path )
432 throws LayoutException;
434 protected abstract String toPath( ArtifactReference reference );