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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.model.ArtifactReference;
24 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
25 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
26 import org.apache.maven.archiva.repository.layout.LayoutException;
31 * RepositoryRequestTest
33 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 public class RepositoryRequestTest
37 extends AbstractRepositoryLayerTestCase
39 public void testInvalidRequestNoArtifactId()
41 assertInvalidRequest( "groupId/jars/-1.0.jar" );
44 public void testInvalidLegacyRequestBadLocation()
46 assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" );
49 public void testInvalidRequestTooShort()
51 assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
54 public void testInvalidDefaultRequestBadLocation()
56 assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
59 public void testValidLegacyGanymed()
62 assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
66 public void testValidDefaultGanymed()
69 assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
70 "ganymed-ssh2", "build210", null, "jar" );
73 public void testValidLegacyJavaxComm()
76 assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
79 public void testValidDefaultJavaxComm()
82 assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
85 public void testValidLegacyJavaxPersistence()
88 assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
89 "3.0-public_review", null, "jar" );
92 public void testValidDefaultJavaxPersistence()
95 assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
96 "3.0-public_review", null, "jar" );
99 public void testValidLegacyMavenTestPlugin()
102 assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
105 public void testValidDefaultMavenTestPlugin()
108 assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin",
109 "1.8.2", null, "pom" );
112 public void testValidLegacyCommonsLangJavadoc()
115 assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
116 "javadoc", "javadoc" );
119 public void testValidDefaultCommonsLangJavadoc()
122 assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
123 "2.1", "javadoc", "javadoc" );
126 public void testValidLegacyDerbyPom()
129 assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
130 // Starting slash should not prevent detection.
131 assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
134 public void testValidDefaultDerbyPom()
137 assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
141 public void testValidLegacyGeronimoEjbSpec()
144 assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
145 "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
148 public void testValidDefaultGeronimoEjbSpec()
151 assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
152 "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
155 public void testValidLegacyLdapSnapshot()
158 assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
159 "0.9.1-SNAPSHOT", null, "pom" );
162 public void testValidDefaultLdapSnapshot()
165 assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
166 "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
169 public void testValidLegacyTestArchSnapshot()
172 assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
173 "2.0.3-SNAPSHOT", null, "pom" );
176 public void testValidDefaultTestArchSnapshot()
179 assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
180 "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
183 public void testValidLegacyOddDottedArtifactId()
186 assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
187 "com.company.department.project", "0.2", null, "pom" );
190 public void testValidDefaultOddDottedArtifactId()
193 assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
194 "com.company.department", "com.company.department.project", "0.2", null, "pom" );
197 public void testValidLegacyTimestampedSnapshot()
200 assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
201 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
204 public void testValidDefaultTimestampedSnapshot()
208 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
209 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
212 public void testIsArtifact()
214 assertTrue( repoRequest.isArtifact( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
215 assertTrue( repoRequest.isArtifact( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
216 assertTrue( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
218 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
219 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
220 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
221 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
222 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
223 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/maven-metadata.xml" ) );
226 public void testIsSupportFile()
228 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
229 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
230 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
231 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
232 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
233 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
235 assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
236 assertFalse( repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
237 assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
238 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
239 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
240 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
243 public void testIsMetadata()
245 assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
246 assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ));
248 assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
249 assertFalse( repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
250 assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
251 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
252 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
253 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
256 public void testIsDefault()
258 assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
259 assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
260 assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
262 assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
263 assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
264 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
265 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
266 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
268 assertFalse( repoRequest.isDefault( null ) );
269 assertFalse( repoRequest.isDefault( "" ) );
270 assertFalse( repoRequest.isDefault( "foo" ) );
271 assertFalse( repoRequest.isDefault( "some.short/path" ) );
274 public void testIsLegacy()
276 assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
277 assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
278 assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
280 assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
281 assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
282 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
283 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
284 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
286 assertFalse( repoRequest.isLegacy( null ) );
287 assertFalse( repoRequest.isLegacy( "" ) );
288 assertFalse( repoRequest.isLegacy( "some.short/path" ) );
291 private ManagedRepositoryContent createManagedRepo( String layout )
294 File repoRoot = getTestFile( "target/test-repo" );
295 return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
299 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
301 public void testToNativePathArtifactDefaultToDefaultDualExtension()
304 ManagedRepositoryContent repository = createManagedRepo( "default" );
306 // Test (artifact) default to default - dual extension
307 assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest
308 .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) );
312 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
314 public void testToNativePathArtifactLegacyToDefaultDualExtension()
317 ManagedRepositoryContent repository = createManagedRepo( "default" );
319 // Test (artifact) legacy to default - dual extension
320 // NOTE: The detection of a dual extension is flawed.
321 assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
322 .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) );
325 public void testToNativePathMetadataDefaultToDefault()
328 ManagedRepositoryContent repository = createManagedRepo( "default" );
330 // Test (metadata) default to default
331 assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repoRequest
332 .toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repository ) );
335 public void testNativePathPomLegacyToDefault()
338 ManagedRepositoryContent repository = createManagedRepo( "default" );
340 // Test (pom) legacy to default
341 assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repoRequest
342 .toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) );
345 public void testNativePathSupportFileLegacyToDefault()
348 ManagedRepositoryContent repository = createManagedRepo( "default" );
350 // Test (supportfile) legacy to default
351 assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repoRequest
352 .toNativePath( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repository ) );
355 public void testNativePathBadRequestTooShort()
358 ManagedRepositoryContent repository = createManagedRepo( "default" );
360 // Test bad request path (too short)
363 repoRequest.toNativePath( "org.apache.derby/license.txt", repository );
364 fail( "Should have thrown an exception about a too short path." );
366 catch ( LayoutException e )
372 public void testNativePathBadRequestBlank()
375 ManagedRepositoryContent repository = createManagedRepo( "default" );
377 // Test bad request path (too short)
380 repoRequest.toNativePath( "", repository );
381 fail( "Should have thrown an exception about an blank request." );
383 catch ( LayoutException e )
389 public void testNativePathBadRequestNull()
392 ManagedRepositoryContent repository = createManagedRepo( "default" );
394 // Test bad request path (too short)
397 repoRequest.toNativePath( null, repository );
398 fail( "Should have thrown an exception about an null request." );
400 catch ( LayoutException e )
406 public void testNativePathBadRequestUnknownType()
409 ManagedRepositoryContent repository = createManagedRepo( "default" );
411 // Test bad request path (too short)
414 repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt", repository );
415 fail( "Should have thrown an exception about an invalid type." );
417 catch ( LayoutException e )
423 public void testToNativePathLegacyMetadataDefaultToLegacy()
426 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
428 // Test (metadata) default to legacy
430 // Special Case: This direction is not supported, should throw a LayoutException.
433 repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml", repository );
434 fail("Should have thrown a LayoutException, can't translate a maven-metadata.xml to a legacy layout.");
436 catch(LayoutException e)
442 public void testNativePathPomDefaultToLegacy()
445 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
447 // Test (pom) default to legacy
448 assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest
449 .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) );
452 public void testNativePathSupportFileDefaultToLegacy()
455 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
457 // Test (supportfile) default to legacy
458 assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repoRequest
459 .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) );
462 private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
466 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":"
467 + ( classifier != null ? classifier + ":" : "" ) + type;
469 ArtifactReference reference = repoRequest.toArtifactReference( path );
471 assertNotNull( expectedId + " - Should not be null.", reference );
473 assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
474 assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
475 if ( StringUtils.isNotBlank( classifier ) )
477 assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
479 assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
480 assertEquals( expectedId + " - Type", type, reference.getType() );
483 private void assertInvalidRequest( String path )
487 repoRequest.toArtifactReference( path );
488 fail( "Expected a LayoutException on an invalid path [" + path + "]" );
490 catch ( LayoutException e )
496 private RepositoryRequest repoRequest;
499 protected void setUp()
504 repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class );