1 package org.apache.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.archiva.model.ArtifactReference;
23 import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
24 import org.apache.archiva.repository.layout.LayoutException;
25 import org.junit.Test;
27 import static org.junit.Assert.*;
30 * AbstractLegacyRepositoryContentTestCase
34 public abstract class AbstractLegacyRepositoryContentTestCase
35 extends AbstractRepositoryLayerTestCase
38 public void testBadPathArtifactIdMissingA()
40 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
44 public void testBadPathArtifactIdMissingB()
46 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
50 public void testBadPathMissingType()
52 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
56 public void testBadPathTooShort()
59 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
63 public void testBadPathWrongPackageExtension()
65 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
69 * [MRM-432] Oddball version spec.
70 * Example of an oddball / unusual version spec.
71 * @throws LayoutException
74 public void testGoodButOddVersionSpecGanymedSsh2()
75 throws LayoutException
77 String groupId = "ch.ethz.ganymed";
78 String artifactId = "ganymed-ssh2";
79 String version = "build210";
81 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
83 assertLayout( path, groupId, artifactId, version, null, type );
87 * [MRM-432] Oddball version spec.
88 * Example of an oddball / unusual version spec.
89 * @throws LayoutException
92 public void testGoodButOddVersionSpecJavaxComm()
93 throws LayoutException
95 String groupId = "javax";
96 String artifactId = "comm";
97 String version = "3.0-u1";
99 String path = "javax/jars/comm-3.0-u1.jar";
101 assertLayout( path, groupId, artifactId, version, null, type );
105 * [MRM-432] Oddball version spec.
106 * Example of an oddball / unusual version spec.
107 * @throws LayoutException
110 public void testGoodButOddVersionSpecJavaxPersistence()
111 throws LayoutException
113 String groupId = "javax.persistence";
114 String artifactId = "ejb";
115 String version = "3.0-public_review";
117 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
120 * The version id of "public_review" can cause problems. is it part of
121 * the version spec? or the classifier?
124 assertLayout( path, groupId, artifactId, version, null, type );
128 public void testGoodCommonsLang()
129 throws LayoutException
131 String groupId = "commons-lang";
132 String artifactId = "commons-lang";
133 String version = "2.1";
135 String path = "commons-lang/jars/commons-lang-2.1.jar";
137 assertLayout( path, groupId, artifactId, version, null, type );
141 public void testGoodDerby()
142 throws LayoutException
144 String groupId = "org.apache.derby";
145 String artifactId = "derby";
146 String version = "10.2.2.0";
148 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
150 assertLayout( path, groupId, artifactId, version, null, type );
154 * Test the ejb-client type spec.
155 * Type specs are not a 1 to 1 map to the extension.
156 * This tests that effect.
157 * @throws LayoutException
159 /* TODO: Re-enabled in the future.
160 public void testGoodFooEjbClient()
161 throws LayoutException
163 String groupId = "com.foo";
164 String artifactId = "foo-client";
165 String version = "1.0";
166 String type = "ejb"; // oddball type-spec (should result in jar extension)
167 String path = "com.foo/ejbs/foo-client-1.0.jar";
169 assertLayout( path, groupId, artifactId, version, classifier, type );
174 * Test the classifier.
175 * @throws LayoutException
178 public void testGoodFooLibJavadoc()
179 throws LayoutException
181 String groupId = "com.foo.lib";
182 String artifactId = "foo-lib";
183 String version = "2.1-alpha-1";
184 String type = "javadoc";
185 String classifier = "javadoc";
186 String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
188 assertLayout( path, groupId, artifactId, version, classifier, type );
192 * Test the classifier, and java-source type spec.
193 * @throws LayoutException
196 public void testGoodFooLibSources()
197 throws LayoutException
199 String groupId = "com.foo.lib";
200 String artifactId = "foo-lib";
201 String version = "2.1-alpha-1";
202 String type = "java-source"; // oddball type-spec (should result in jar extension)
203 String classifier = "sources";
204 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
206 assertLayout( path, groupId, artifactId, version, classifier, type );
210 public void testGoodFooTool()
211 throws LayoutException
213 String groupId = "com.foo";
214 String artifactId = "foo-tool";
215 String version = "1.0";
217 String path = "com.foo/jars/foo-tool-1.0.jar";
219 assertLayout( path, groupId, artifactId, version, null, type );
223 public void testGoodGeronimoEjbSpec()
224 throws LayoutException
226 String groupId = "org.apache.geronimo.specs";
227 String artifactId = "geronimo-ejb_2.1_spec";
228 String version = "1.0.1";
230 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
232 assertLayout( path, groupId, artifactId, version, null, type );
236 public void testGoodLdapClientsPom()
237 throws LayoutException
239 String groupId = "directory-clients";
240 String artifactId = "ldap-clients";
241 String version = "0.9.1-SNAPSHOT";
243 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
245 assertLayout( path, groupId, artifactId, version, null, type );
249 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
250 * @throws LayoutException
253 public void testGoodSnapshotMavenTest()
254 throws LayoutException
256 String groupId = "org.apache.archiva.test";
257 String artifactId = "redonkulous";
258 String version = "3.1-beta-1-20050831.101112-42";
260 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
262 assertLayout( path, groupId, artifactId, version, null, type );
266 * [MRM-519] version identifiers within filename cause misidentification of version.
267 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
270 public void testGoodVersionKeywordInArtifactId()
271 throws LayoutException
273 String groupId = "maven";
274 String artifactId = "maven-test-plugin";
275 String version = "1.8.2";
278 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
280 assertLayout( path, groupId, artifactId, version, null, type );
284 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
285 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
288 public void testGoodDetectPluginMavenTest()
289 throws LayoutException
291 String groupId = "maven";
292 String artifactId = "maven-test-plugin";
293 String version = "1.8.2";
294 String type = "maven-one-plugin";
295 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
297 assertLayout( path, groupId, artifactId, version, null, type );
301 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
304 public void testGoodDetectPluginAvalonMeta()
305 throws LayoutException
307 String groupId = "avalon-meta";
308 String artifactId = "avalon-meta-plugin";
309 String version = "1.1";
310 String type = "maven-one-plugin";
311 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
313 assertLayout( path, groupId, artifactId, version, null, type );
317 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
320 public void testGoodDetectPluginCactusMaven()
321 throws LayoutException
323 String groupId = "cactus";
324 String artifactId = "cactus-maven";
325 String version = "1.7dev-20040815";
326 String type = "maven-one-plugin";
327 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
329 assertLayout( path, groupId, artifactId, version, null, type );
333 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
336 public void testGoodDetectPluginGeronimoPackaging()
337 throws LayoutException
339 String groupId = "geronimo";
340 String artifactId = "geronimo-packaging-plugin";
341 String version = "1.0.1";
342 String type = "maven-one-plugin";
343 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
345 assertLayout( path, groupId, artifactId, version, null, type );
349 * [MRM-768] Artifact type "maven-plugin" does not distinguish maven1 and maven2 plugins.
350 * This produces conflicts when m2 plugins are stored in legacy-layout repository
353 public void testMaven1Maven2PluginTypeDistinc()
356 String groupId = "com.sun.tools.xjc.maven2";
357 String artifactId = "maven-jaxb-plugin";
358 String version = "1.1";
359 String type = "maven-plugin";
360 String path = "com.sun.tools.xjc.maven2/maven-plugins/maven-jaxb-plugin-1.1.jar";
362 assertLayout( path, groupId, artifactId, version, null, type );
366 * Perform a roundtrip through the layout routines to determine success.
367 * @param classifier TODO
369 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
370 throws LayoutException
372 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
374 // --- Artifact Tests.
376 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
378 // --- Artifact Reference Tests
380 // Path to Artifact Reference.
381 ArtifactReference testReference = toArtifactReference( path );
382 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
384 // And back again, using test Reference from previous step.
385 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
388 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
389 String version, String classifier, String type )
391 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
393 assertNotNull( expectedId + " - Should not be null.", actualReference );
395 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
396 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
397 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
398 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
399 assertEquals( expectedId + " - Type", type, actualReference.getType() );
402 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String classifier, String type )
404 ArtifactReference artifact = new ArtifactReference();
405 artifact.setGroupId( groupId );
406 artifact.setArtifactId( artifactId );
407 artifact.setVersion( version );
408 artifact.setClassifier( classifier );
409 artifact.setType( type );
410 assertNotNull( artifact );
414 private void assertBadPath( String path, String reason )
418 toArtifactReference( path );
419 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
421 catch ( LayoutException e )
428 protected abstract ArtifactReference toArtifactReference( String path )
429 throws LayoutException;
431 protected abstract String toPath( ArtifactReference reference );