1 package org.apache.maven.archiva.repository.content;
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.maven.archiva.model.ArtifactReference;
23 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
24 import org.apache.maven.archiva.repository.layout.LayoutException;
27 * AbstractLegacyRepositoryContentTestCase
29 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
32 public abstract class AbstractLegacyRepositoryContentTestCase
33 extends AbstractRepositoryLayerTestCase
35 public void testBadPathArtifactIdMissingA()
37 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
40 public void testBadPathArtifactIdMissingB()
42 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
45 public void testBadPathMissingType()
47 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
50 public void testBadPathTooShort()
53 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
56 public void testBadPathWrongPackageExtension()
58 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
62 * [MRM-432] Oddball version spec.
63 * Example of an oddball / unusual version spec.
64 * @throws LayoutException
66 public void testGoodButOddVersionSpecGanymedSsh2()
67 throws LayoutException
69 String groupId = "ch.ethz.ganymed";
70 String artifactId = "ganymed-ssh2";
71 String version = "build210";
73 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
75 assertLayout( path, groupId, artifactId, version, null, type );
79 * [MRM-432] Oddball version spec.
80 * Example of an oddball / unusual version spec.
81 * @throws LayoutException
83 public void testGoodButOddVersionSpecJavaxComm()
84 throws LayoutException
86 String groupId = "javax";
87 String artifactId = "comm";
88 String version = "3.0-u1";
90 String path = "javax/jars/comm-3.0-u1.jar";
92 assertLayout( path, groupId, artifactId, version, null, type );
96 * [MRM-432] Oddball version spec.
97 * Example of an oddball / unusual version spec.
98 * @throws LayoutException
100 public void testGoodButOddVersionSpecJavaxPersistence()
101 throws LayoutException
103 String groupId = "javax.persistence";
104 String artifactId = "ejb";
105 String version = "3.0-public_review";
107 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
110 * The version id of "public_review" can cause problems. is it part of
111 * the version spec? or the classifier?
114 assertLayout( path, groupId, artifactId, version, null, type );
117 public void testGoodCommonsLang()
118 throws LayoutException
120 String groupId = "commons-lang";
121 String artifactId = "commons-lang";
122 String version = "2.1";
124 String path = "commons-lang/jars/commons-lang-2.1.jar";
126 assertLayout( path, groupId, artifactId, version, null, type );
129 public void testGoodDerby()
130 throws LayoutException
132 String groupId = "org.apache.derby";
133 String artifactId = "derby";
134 String version = "10.2.2.0";
136 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
138 assertLayout( path, groupId, artifactId, version, null, type );
142 * Test the ejb-client type spec.
143 * Type specs are not a 1 to 1 map to the extension.
144 * This tests that effect.
145 * @throws LayoutException
147 /* TODO: Re-enabled in the future.
148 public void testGoodFooEjbClient()
149 throws LayoutException
151 String groupId = "com.foo";
152 String artifactId = "foo-client";
153 String version = "1.0";
154 String type = "ejb"; // oddball type-spec (should result in jar extension)
155 String path = "com.foo/ejbs/foo-client-1.0.jar";
157 assertLayout( path, groupId, artifactId, version, classifier, type );
162 * Test the classifier.
163 * @throws LayoutException
165 public void testGoodFooLibJavadoc()
166 throws LayoutException
168 String groupId = "com.foo.lib";
169 String artifactId = "foo-lib";
170 String version = "2.1-alpha-1";
171 String type = "javadoc";
172 String classifier = "javadoc";
173 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
175 assertLayout( path, groupId, artifactId, version, classifier, type );
179 * Test the classifier, and java-source type spec.
180 * @throws LayoutException
182 public void testGoodFooLibSources()
183 throws LayoutException
185 String groupId = "com.foo.lib";
186 String artifactId = "foo-lib";
187 String version = "2.1-alpha-1";
188 String type = "java-source"; // oddball type-spec (should result in jar extension)
189 String classifier = "sources";
190 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
192 assertLayout( path, groupId, artifactId, version, classifier, type );
195 public void testGoodFooTool()
196 throws LayoutException
198 String groupId = "com.foo";
199 String artifactId = "foo-tool";
200 String version = "1.0";
202 String path = "com.foo/jars/foo-tool-1.0.jar";
204 assertLayout( path, groupId, artifactId, version, null, type );
207 public void testGoodGeronimoEjbSpec()
208 throws LayoutException
210 String groupId = "org.apache.geronimo.specs";
211 String artifactId = "geronimo-ejb_2.1_spec";
212 String version = "1.0.1";
214 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
216 assertLayout( path, groupId, artifactId, version, null, type );
219 public void testGoodLdapClientsPom()
220 throws LayoutException
222 String groupId = "directory-clients";
223 String artifactId = "ldap-clients";
224 String version = "0.9.1-SNAPSHOT";
226 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
228 assertLayout( path, groupId, artifactId, version, null, type );
232 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
233 * @throws LayoutException
235 public void testGoodSnapshotMavenTest()
236 throws LayoutException
238 String groupId = "org.apache.archiva.test";
239 String artifactId = "redonkulous";
240 String version = "3.1-beta-1-20050831.101112-42";
242 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
244 assertLayout( path, groupId, artifactId, version, null, type );
248 * [MRM-519] version identifiers within filename cause misidentification of version.
249 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
251 public void testGoodVersionKeywordInArtifactId()
252 throws LayoutException
254 String groupId = "maven";
255 String artifactId = "maven-test-plugin";
256 String version = "1.8.2";
259 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
261 assertLayout( path, groupId, artifactId, version, null, type );
265 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
266 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
268 public void testGoodDetectPluginMavenTest()
269 throws LayoutException
271 String groupId = "maven";
272 String artifactId = "maven-test-plugin";
273 String version = "1.8.2";
274 String type = "maven-plugin";
275 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
277 assertLayout( path, groupId, artifactId, version, null, type );
281 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
283 public void testGoodDetectPluginAvalonMeta()
284 throws LayoutException
286 String groupId = "avalon-meta";
287 String artifactId = "avalon-meta-plugin";
288 String version = "1.1";
289 String type = "maven-plugin";
290 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
292 assertLayout( path, groupId, artifactId, version, null, type );
296 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
298 public void testGoodDetectPluginCactusMaven()
299 throws LayoutException
301 String groupId = "cactus";
302 String artifactId = "cactus-maven";
303 String version = "1.7dev-20040815";
304 String type = "maven-plugin";
305 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
307 assertLayout( path, groupId, artifactId, version, null, type );
311 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
313 public void testGoodDetectPluginGeronimoPackaging()
314 throws LayoutException
316 String groupId = "geronimo";
317 String artifactId = "geronimo-packaging-plugin";
318 String version = "1.0.1";
319 String type = "maven-plugin";
320 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
322 assertLayout( path, groupId, artifactId, version, null, type );
326 * Perform a roundtrip through the layout routines to determine success.
327 * @param classifier TODO
329 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
330 throws LayoutException
332 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
334 // --- Artifact Tests.
336 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
338 // --- Artifact Reference Tests
340 // Path to Artifact Reference.
341 ArtifactReference testReference = toArtifactReference( path );
342 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
344 // And back again, using test Reference from previous step.
345 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
348 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
349 String version, String classifier, String type )
351 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
353 assertNotNull( expectedId + " - Should not be null.", actualReference );
355 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
356 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
357 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
358 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
359 assertEquals( expectedId + " - Type", type, actualReference.getType() );
362 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
364 ArtifactReference artifact = new ArtifactReference();
365 artifact.setGroupId( groupId );
366 artifact.setArtifactId( artifactId );
367 artifact.setVersion( version );
368 artifact.setClassifier( classifier );
369 artifact.setType( type );
370 assertNotNull( artifact );
374 private void assertBadPath( String path, String reason )
378 toArtifactReference( path );
379 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
381 catch ( LayoutException e )
388 protected abstract ArtifactReference toArtifactReference( String path )
389 throws LayoutException;
391 protected abstract String toPath( ArtifactReference reference );