1 package org.apache.maven.archiva.repository.layout;
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.ArchivaArtifact;
23 import org.apache.maven.archiva.model.ArtifactReference;
26 * DefaultBidirectionalRepositoryLayoutTest
28 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
31 public class DefaultBidirectionalRepositoryLayoutTest
32 extends AbstractBidirectionalRepositoryLayoutTestCase
34 private BidirectionalRepositoryLayout layout;
36 public void testBadPathMissingType()
38 assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
41 public void testBadPathReleaseInSnapshotDir()
43 assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
46 public void testBadPathTimestampedSnapshotNotInSnapshotDir()
48 assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
49 "Timestamped Snapshot artifact not inside of an Snapshot dir" );
52 public void testBadPathTooShort()
54 assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
57 public void testBadPathVersionMismatchA()
59 assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
62 public void testBadPathVersionMismatchB()
64 assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
67 public void testBadPathWrongArtifactId()
69 assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
70 "wrong artifact id" );
74 * [MRM-432] Oddball version spec.
75 * Example of an oddball / unusual version spec.
76 * @throws LayoutException
78 public void testGoodButOddVersionSpecGanymedSsh2()
79 throws LayoutException
81 String groupId = "ch.ethz.ganymed";
82 String artifactId = "ganymed-ssh2";
83 String version = "build210";
84 String classifier = null;
86 String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
88 assertLayout( path, groupId, artifactId, version, classifier, type );
92 * [MRM-432] Oddball version spec.
93 * Example of an oddball / unusual version spec.
94 * @throws LayoutException
96 public void testGoodButOddVersionSpecJavaxComm()
97 throws LayoutException
99 String groupId = "javax";
100 String artifactId = "comm";
101 String version = "3.0-u1";
102 String classifier = null;
104 String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
106 assertLayout( path, groupId, artifactId, version, classifier, type );
110 * [MRM-432] Oddball version spec.
111 * Example of an oddball / unusual version spec.
112 * @throws LayoutException
114 public void testGoodButOddVersionSpecJavaxPersistence()
115 throws LayoutException
117 String groupId = "javax.persistence";
118 String artifactId = "ejb";
119 String version = "3.0-public_review";
120 String classifier = null;
122 String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
125 * The version id of "public_review" can cause problems. is it part of
126 * the version spec? or the classifier?
127 * Since the path spec below shows it in the path, then it is really
128 * part of the version spec.
131 assertLayout( path, groupId, artifactId, version, classifier, type );
135 * [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
137 public void testGoodDashedArtifactId()
138 throws LayoutException
140 String groupId = "test.maven-arch";
141 String artifactId = "test-arch";
142 String version = "2.0.3-SNAPSHOT";
143 String classifier = null;
145 String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
147 assertLayout( path, groupId, artifactId, version, classifier, type );
150 public void testGoodComFooTool()
151 throws LayoutException
153 String groupId = "com.foo";
154 String artifactId = "foo-tool";
155 String version = "1.0";
156 String classifier = null;
158 String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
160 assertLayout( path, groupId, artifactId, version, classifier, type );
163 public void testGoodCommonsLang()
164 throws LayoutException
166 String groupId = "commons-lang";
167 String artifactId = "commons-lang";
168 String version = "2.1";
169 String classifier = null;
171 String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
173 assertLayout( path, groupId, artifactId, version, classifier, type );
177 * Test the ejb-client type spec.
178 * Type specs are not a 1 to 1 map to the extension.
179 * This tests that effect.
180 * @throws LayoutException
182 /* TODO: Re-enabled in the future.
183 public void testGoodFooEjbClient()
184 throws LayoutException
186 String groupId = "com.foo";
187 String artifactId = "foo-client";
188 String version = "1.0";
189 String classifier = null;
190 String type = "ejb-client"; // oddball type-spec (should result in jar extension)
191 String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
193 assertLayout( path, groupId, artifactId, version, classifier, type );
198 * Test the classifier, and java-source type spec.
199 * @throws LayoutException
201 public void testGoodFooLibSources()
202 throws LayoutException
204 String groupId = "com.foo.lib";
205 String artifactId = "foo-lib";
206 String version = "2.1-alpha-1";
207 String classifier = "sources";
208 String type = "java-source"; // oddball type-spec (should result in jar extension)
209 String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
211 assertLayout( path, groupId, artifactId, version, classifier, type );
215 * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
216 * @throws LayoutException
218 public void testGoodSnapshotMavenTest()
219 throws LayoutException
221 String groupId = "org.apache.archiva.test";
222 String artifactId = "redonkulous";
223 String version = "3.1-beta-1-20050831.101112-42";
224 String classifier = null;
226 String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
228 assertLayout( path, groupId, artifactId, version, classifier, type );
231 public void testToArtifactOnEmptyPath()
235 layout.toArtifact( "" );
236 fail( "Should have failed due to empty path." );
238 catch ( LayoutException e )
244 public void testToArtifactOnNullPath()
248 layout.toArtifact( null );
249 fail( "Should have failed due to null path." );
251 catch ( LayoutException e )
257 public void testToArtifactReferenceOnEmptyPath()
261 layout.toArtifactReference( "" );
262 fail( "Should have failed due to empty path." );
264 catch ( LayoutException e )
270 public void testToArtifactReferenceOnNullPath()
274 layout.toArtifactReference( null );
275 fail( "Should have failed due to null path." );
277 catch ( LayoutException e )
283 public void testToPathOnNullArtifactReference()
287 ArtifactReference reference = null;
288 layout.toPath( reference );
289 fail( "Should have failed due to null artifact reference." );
291 catch ( IllegalArgumentException e )
297 public void testToPathOnNullArtifact()
301 ArchivaArtifact artifact = null;
302 layout.toPath( artifact );
303 fail( "Should have failed due to null artifact." );
305 catch ( IllegalArgumentException e )
311 protected void assertBadPath( String path, String reason )
315 layout.toArtifact( path );
316 fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
318 catch ( LayoutException e )
325 * Perform a roundtrip through the layout routines to determine success.
327 private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
329 throws LayoutException
331 ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
333 // --- Artifact Tests.
335 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) );
338 ArchivaArtifact testArtifact = layout.toArtifact( path );
339 assertArtifact( testArtifact, groupId, artifactId, version, classifier, type );
341 // And back again, using test Artifact from previous step.
342 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) );
344 // --- Artifact Reference Tests
346 // Path to Artifact Reference.
347 ArtifactReference testReference = layout.toArtifactReference( path );
348 assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
350 // And back again, using test Reference from previous step.
351 assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) );
354 protected void setUp()
359 layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "default" );