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
23 import org.apache.maven.archiva.model.ArtifactReference;
24 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
25 import org.apache.maven.archiva.repository.layout.LayoutException;
28 * LegacyPathParserTest
30 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
33 public class LegacyPathParserTest
34 extends AbstractRepositoryLayerTestCase
36 public void testBadPathArtifactIdMissingA()
38 assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
41 public void testBadPathArtifactIdMissingB()
43 assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
46 public void testBadPathMissingType()
48 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
51 public void testBadPathTooShort()
54 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
57 public void testBadPathWrongPackageExtension()
59 assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
63 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
65 public void testGoodButDualExtensions()
66 throws LayoutException
68 String groupId = "org.project";
69 String artifactId = "example-presentation";
70 String version = "3.2.xml";
71 String type = "distribution-zip";
72 String path = "org.project/zips/example-presentation-3.2.xml.zip";
74 assertLayout( path, groupId, artifactId, version, null, type );
78 * [MRM-432] Oddball version spec.
79 * Example of an oddball / unusual version spec.
80 * @throws LayoutException
82 public void testGoodButOddVersionSpecGanymedSsh2()
83 throws LayoutException
85 String groupId = "ch.ethz.ganymed";
86 String artifactId = "ganymed-ssh2";
87 String version = "build210";
89 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
91 assertLayout( path, groupId, artifactId, version, null, type );
95 * [MRM-432] Oddball version spec.
96 * Example of an oddball / unusual version spec.
97 * @throws LayoutException
99 public void testGoodButOddVersionSpecJavaxComm()
100 throws LayoutException
102 String groupId = "javax";
103 String artifactId = "comm";
104 String version = "3.0-u1";
106 String path = "javax/jars/comm-3.0-u1.jar";
108 assertLayout( path, groupId, artifactId, version, null, type );
112 * [MRM-432] Oddball version spec.
113 * Example of an oddball / unusual version spec.
114 * @throws LayoutException
116 public void testGoodButOddVersionSpecJavaxPersistence()
117 throws LayoutException
119 String groupId = "javax.persistence";
120 String artifactId = "ejb";
121 String version = "3.0-public_review";
123 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
126 * The version id of "public_review" can cause problems. is it part of
127 * the version spec? or the classifier?
130 assertLayout( path, groupId, artifactId, version, null, type );
133 public void testGoodCommonsLang()
134 throws LayoutException
136 String groupId = "commons-lang";
137 String artifactId = "commons-lang";
138 String version = "2.1";
140 String path = "commons-lang/jars/commons-lang-2.1.jar";
142 assertLayout( path, groupId, artifactId, version, null, type );
145 public void testGoodDerby()
146 throws LayoutException
148 String groupId = "org.apache.derby";
149 String artifactId = "derby";
150 String version = "10.2.2.0";
152 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
154 assertLayout( path, groupId, artifactId, version, null, type );
158 * Test the ejb-client type spec.
159 * Type specs are not a 1 to 1 map to the extension.
160 * This tests that effect.
161 * @throws LayoutException
163 /* TODO: Re-enabled in the future.
164 public void testGoodFooEjbClient()
165 throws LayoutException
167 String groupId = "com.foo";
168 String artifactId = "foo-client";
169 String version = "1.0";
170 String type = "ejb"; // oddball type-spec (should result in jar extension)
171 String path = "com.foo/ejbs/foo-client-1.0.jar";
173 assertLayout( path, groupId, artifactId, version, classifier, type );
178 * Test the classifier.
179 * @throws 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 LayoutException
198 public void testGoodFooLibSources()
199 throws LayoutException
201 String groupId = "com.foo.lib";
202 String artifactId = "foo-lib";
203 String version = "2.1-alpha-1";
204 String type = "java-source"; // oddball type-spec (should result in jar extension)
205 String classifier= "sources";
206 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
208 assertLayout( path, groupId, artifactId, version, classifier, type );
211 public void testGoodFooTool()
212 throws LayoutException
214 String groupId = "com.foo";
215 String artifactId = "foo-tool";
216 String version = "1.0";
218 String path = "com.foo/jars/foo-tool-1.0.jar";
220 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 );
235 public void testGoodLdapClientsPom()
236 throws LayoutException
238 String groupId = "directory-clients";
239 String artifactId = "ldap-clients";
240 String version = "0.9.1-SNAPSHOT";
242 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
244 assertLayout( path, groupId, artifactId, version, null, type );
248 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
249 * @throws LayoutException
251 public void testGoodSnapshotMavenTest()
252 throws LayoutException
254 String groupId = "org.apache.archiva.test";
255 String artifactId = "redonkulous";
256 String version = "3.1-beta-1-20050831.101112-42";
258 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
260 assertLayout( path, groupId, artifactId, version, null, type );
264 * [MRM-519] version identifiers within filename cause misidentification of version.
265 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
267 public void testGoodVersionKeywordInArtifactId()
268 throws LayoutException
270 String groupId = "maven";
271 String artifactId = "maven-test-plugin";
272 String version = "1.8.2";
275 String path = "maven/poms/maven-test-plugin-1.8.2.pom";
277 assertLayout( path, groupId, artifactId, version, null, type );
281 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
282 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
284 public void testGoodDetectPluginMavenTest()
285 throws LayoutException
287 String groupId = "maven";
288 String artifactId = "maven-test-plugin";
289 String version = "1.8.2";
290 String type = "maven-plugin";
291 String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
293 assertLayout( path, groupId, artifactId, version, null, type );
297 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
299 public void testGoodDetectPluginAvalonMeta()
300 throws LayoutException
302 String groupId = "avalon-meta";
303 String artifactId = "avalon-meta-plugin";
304 String version = "1.1";
305 String type = "maven-plugin";
306 String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
308 assertLayout( path, groupId, artifactId, version, null, type );
312 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
314 public void testGoodDetectPluginCactusMaven()
315 throws LayoutException
317 String groupId = "cactus";
318 String artifactId = "cactus-maven";
319 String version = "1.7dev-20040815";
320 String type = "maven-plugin";
321 String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
323 assertLayout( path, groupId, artifactId, version, null, type );
327 * [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
329 public void testGoodDetectPluginGeronimoPackaging()
330 throws LayoutException
332 String groupId = "geronimo";
333 String artifactId = "geronimo-packaging-plugin";
334 String version = "1.0.1";
335 String type = "maven-plugin";
336 String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
338 assertLayout( path, groupId, artifactId, version, null, type );
342 * Perform a path to artifact reference lookup, and verify the results.
343 * @param classifier TODO
345 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type )
346 throws LayoutException
348 // Path to Artifact Reference.
349 ArtifactReference testReference = LegacyPathParser.toArtifactReference( path );
350 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
353 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
354 String version, String classifier, String type )
356 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
358 assertNotNull( expectedId + " - Should not be null.", actualReference );
360 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
361 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
362 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
363 assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
364 assertEquals( expectedId + " - Type", type, actualReference.getType() );
367 protected void assertBadPath( String path, String reason )
371 LegacyPathParser.toArtifactReference( path );
372 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
374 catch ( LayoutException e )