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-432] Oddball version spec.
64 * Example of an oddball / unusual version spec.
65 * @throws LayoutException
67 public void testGoodButOddVersionSpecGanymedSsh2()
68 throws LayoutException
70 String groupId = "ch.ethz.ganymed";
71 String artifactId = "ganymed-ssh2";
72 String version = "build210";
74 String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
76 assertLayout( path, groupId, artifactId, version, type );
80 * [MRM-432] Oddball version spec.
81 * Example of an oddball / unusual version spec.
82 * @throws LayoutException
84 public void testGoodButOddVersionSpecJavaxComm()
85 throws LayoutException
87 String groupId = "javax";
88 String artifactId = "comm";
89 String version = "3.0-u1";
91 String path = "javax/jars/comm-3.0-u1.jar";
93 assertLayout( path, groupId, artifactId, version, type );
97 * [MRM-432] Oddball version spec.
98 * Example of an oddball / unusual version spec.
99 * @throws LayoutException
101 public void testGoodButOddVersionSpecJavaxPersistence()
102 throws LayoutException
104 String groupId = "javax.persistence";
105 String artifactId = "ejb";
106 String version = "3.0-public_review";
108 String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
111 * The version id of "public_review" can cause problems. is it part of
112 * the version spec? or the classifier?
115 assertLayout( path, groupId, artifactId, version, type );
118 public void testGoodCommonsLang()
119 throws LayoutException
121 String groupId = "commons-lang";
122 String artifactId = "commons-lang";
123 String version = "2.1";
125 String path = "commons-lang/jars/commons-lang-2.1.jar";
127 assertLayout( path, groupId, artifactId, version, type );
130 public void testGoodDerby()
131 throws LayoutException
133 String groupId = "org.apache.derby";
134 String artifactId = "derby";
135 String version = "10.2.2.0";
137 String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
139 assertLayout( path, groupId, artifactId, version, type );
143 * Test the ejb-client type spec.
144 * Type specs are not a 1 to 1 map to the extension.
145 * This tests that effect.
146 * @throws LayoutException
148 /* TODO: Re-enabled in the future.
149 public void testGoodFooEjbClient()
150 throws LayoutException
152 String groupId = "com.foo";
153 String artifactId = "foo-client";
154 String version = "1.0";
155 String type = "ejb"; // oddball type-spec (should result in jar extension)
156 String path = "com.foo/ejbs/foo-client-1.0.jar";
158 assertLayout( path, groupId, artifactId, version, classifier, type );
163 * Test the classifier.
164 * @throws LayoutException
166 public void testGoodFooLibJavadoc()
167 throws LayoutException
169 String groupId = "com.foo.lib";
170 String artifactId = "foo-lib";
171 String version = "2.1-alpha-1-javadoc";
172 String type = "javadoc";
173 String path = "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar";
175 assertLayout( path, groupId, artifactId, version, 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-sources";
188 String type = "java-source"; // oddball type-spec (should result in jar extension)
189 String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
191 assertLayout( path, groupId, artifactId, version, type );
194 public void testGoodFooTool()
195 throws LayoutException
197 String groupId = "com.foo";
198 String artifactId = "foo-tool";
199 String version = "1.0";
201 String path = "com.foo/jars/foo-tool-1.0.jar";
203 assertLayout( path, groupId, artifactId, version, type );
206 public void testGoodGeronimoEjbSpec()
207 throws LayoutException
209 String groupId = "org.apache.geronimo.specs";
210 String artifactId = "geronimo-ejb_2.1_spec";
211 String version = "1.0.1";
213 String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
215 assertLayout( path, groupId, artifactId, version, type );
218 public void testGoodLdapClientsPom()
219 throws LayoutException
221 String groupId = "directory-clients";
222 String artifactId = "ldap-clients";
223 String version = "0.9.1-SNAPSHOT";
225 String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
227 assertLayout( path, groupId, artifactId, version, type );
231 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
232 * @throws LayoutException
234 public void testGoodSnapshotMavenTest()
235 throws LayoutException
237 String groupId = "org.apache.archiva.test";
238 String artifactId = "redonkulous";
239 String version = "3.1-beta-1-20050831.101112-42";
241 String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
243 assertLayout( path, groupId, artifactId, version, type );
247 * [MRM-519] version identifiers within filename cause misidentification of version.
248 * Example uses "test" in artifact Id, which is also part of the versionKeyword list.
250 public void testGoodVersionKeywordInArtifactId()
251 throws LayoutException
253 String groupId = "maven";
254 String artifactId = "maven-test-plugin";
255 String version = "1.8.2";
258 String path = "maven/jars/maven-test-plugin-1.8.2.jar";
260 assertLayout( path, groupId, artifactId, version, type );
264 * Perform a path to artifact reference lookup, and verify the results.
266 private void assertLayout( String path, String groupId, String artifactId, String version, String type )
267 throws LayoutException
269 // Path to Artifact Reference.
270 ArtifactReference testReference = LegacyPathParser.toArtifactReference( path );
271 assertArtifactReference( testReference, groupId, artifactId, version, type );
274 private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
275 String version, String type )
277 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type;
279 assertNotNull( expectedId + " - Should not be null.", actualReference );
281 assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
282 assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
283 assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
284 assertEquals( expectedId + " - Type", type, actualReference.getType() );
285 // legacy has no classifier.
286 assertNull( expectedId + " - classifier", actualReference.getClassifier() );
289 protected void assertBadPath( String path, String reason )
293 LegacyPathParser.toArtifactReference( path );
294 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
296 catch ( LayoutException e )