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, 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, 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, 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, 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, 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-javadoc";
171 String type = "javadoc";
172 String path = "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar";
174 assertLayout( path, groupId, artifactId, version, type );
178 * Test the classifier, and java-source type spec.
179 * @throws LayoutException
181 public void testGoodFooLibSources()
182 throws LayoutException
184 String groupId = "com.foo.lib";
185 String artifactId = "foo-lib";
186 String version = "2.1-alpha-1-sources";
187 String type = "java-source"; // oddball type-spec (should result in jar extension)
188 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
190 assertLayout( path, groupId, artifactId, version, type );
193 public void testGoodFooTool()
194 throws LayoutException
196 String groupId = "com.foo";
197 String artifactId = "foo-tool";
198 String version = "1.0";
200 String path = "com.foo/jars/foo-tool-1.0.jar";
202 assertLayout( path, groupId, artifactId, version, type );
205 public void testGoodGeronimoEjbSpec()
206 throws LayoutException
208 String groupId = "org.apache.geronimo.specs";
209 String artifactId = "geronimo-ejb_2.1_spec";
210 String version = "1.0.1";
212 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
214 assertLayout( path, groupId, artifactId, version, type );
217 public void testGoodLdapClientsPom()
218 throws LayoutException
220 String groupId = "directory-clients";
221 String artifactId = "ldap-clients";
222 String version = "0.9.1-SNAPSHOT";
224 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
226 assertLayout( path, groupId, artifactId, version, type );
230 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
231 * @throws LayoutException
233 public void testGoodSnapshotMavenTest()
234 throws LayoutException
236 String groupId = "org.apache.archiva.test";
237 String artifactId = "redonkulous";
238 String version = "3.1-beta-1-20050831.101112-42";
240 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
242 assertLayout( path, groupId, artifactId, version, type );
246 * [MRM-519] version identifiers within filename cause misidentification of version.
247 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
249 public void testGoodVersionKeywordInArtifactId()
250 throws LayoutException
252 String groupId = "maven";
253 String artifactId = "maven-test-plugin";
254 String version = "1.8.2";
257 String path = "maven/jars/maven-test-plugin-1.8.2.jar";
259 assertLayout( path, groupId, artifactId, version, type );
263 * Perform a roundtrip through the layout routines to determine success.
265 private void assertLayout( String path, String groupId, String artifactId, String version, String type )
266 throws LayoutException
268 ArtifactReference expectedArtifact = createArtifact( groupId, artifactId, version, type );
270 // --- Artifact Tests.
272 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( expectedArtifact ) );
274 // --- Artifact Reference Tests
276 // Path to Artifact Reference.
277 ArtifactReference testReference = toArtifactReference( path );
278 assertArtifactReference( testReference, groupId, artifactId, version, type );
280 // And back again, using test Reference from previous step.
281 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, toPath( testReference ) );
284 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
285 String version, String type )
287 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
289 assertNotNull( expectedId + " - Should not be null.", actualReference );
291 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
292 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
293 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
294 assertEquals( expectedId + " - Type", type, actualReference.getType() );
295 // legacy has no classifier.
296 assertNull( expectedId + " - classifier", actualReference.getClassifier() );
299 protected ArtifactReference createArtifact( String groupId, String artifactId, String version, String type )
301 ArtifactReference artifact = new ArtifactReference();
302 artifact.setGroupId( groupId );
303 artifact.setArtifactId( artifactId );
304 artifact.setVersion( version );
305 artifact.setType( type );
306 assertNotNull( artifact );
310 private void assertBadPath( String path, String reason )
314 toArtifactReference( path );
315 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
317 catch ( LayoutException e )
324 protected abstract ArtifactReference toArtifactReference( String path )
325 throws LayoutException;
327 protected abstract String toPath( ArtifactReference reference );