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
35 public class RepositoryRequestTest
36 extends AbstractRepositoryLayerTestCase
38 public void testInvalidRequestEmptyPath()
40 assertInvalidRequest( "" );
43 public void testInvalidRequestSlashOnly()
45 assertInvalidRequest( "//" );
48 public void testInvalidRequestNoArtifactId()
50 assertInvalidRequest( "groupId/jars/-1.0.jar" );
53 public void testInvalidLegacyRequestBadLocation()
55 assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" );
58 public void testInvalidRequestTooShort()
60 assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
63 public void testInvalidDefaultRequestBadLocation()
65 assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
68 public void testValidLegacyGanymed()
71 assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
75 public void testValidDefaultGanymed()
78 assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
79 "ganymed-ssh2", "build210", null, "jar" );
82 public void testValidLegacyJavaxComm()
85 assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
88 public void testValidDefaultJavaxComm()
91 assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
94 public void testValidLegacyJavaxPersistence()
97 assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
98 "3.0-public_review", null, "jar" );
101 public void testValidDefaultJavaxPersistence()
104 assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
105 "3.0-public_review", null, "jar" );
108 public void testValidLegacyMavenTestPlugin()
111 assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
114 public void testValidDefaultMavenTestPlugin()
117 assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin",
118 "1.8.2", null, "pom" );
121 public void testValidLegacyCommonsLangJavadoc()
124 assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
125 "javadoc", "javadoc" );
128 public void testValidDefaultCommonsLangJavadoc()
131 assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
132 "2.1", "javadoc", "javadoc" );
135 public void testValidLegacyDerbyPom()
138 assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
139 // Starting slash should not prevent detection.
140 assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
143 public void testValidDefaultDerbyPom()
146 assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
150 public void testValidLegacyGeronimoEjbSpec()
153 assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
154 "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
157 public void testValidDefaultGeronimoEjbSpec()
160 assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
161 "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
164 public void testValidLegacyLdapSnapshot()
167 assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
168 "0.9.1-SNAPSHOT", null, "pom" );
171 public void testValidDefaultLdapSnapshot()
174 assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
175 "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
178 public void testValidLegacyTestArchSnapshot()
181 assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
182 "2.0.3-SNAPSHOT", null, "pom" );
185 public void testValidDefaultTestArchSnapshot()
188 assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
189 "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
192 public void testValidLegacyOddDottedArtifactId()
195 assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
196 "com.company.department.project", "0.2", null, "pom" );
199 public void testValidDefaultOddDottedArtifactId()
202 assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
203 "com.company.department", "com.company.department.project", "0.2", null, "pom" );
206 public void testValidLegacyTimestampedSnapshot()
209 assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
210 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
213 public void testValidDefaultTimestampedSnapshot()
217 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
218 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
221 public void testIsSupportFile()
223 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
224 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
225 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
226 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
227 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
228 assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
230 assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
231 assertFalse( repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
232 assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
233 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
234 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
235 assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
238 public void testIsMetadata()
240 assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
241 assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ));
243 assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
244 assertFalse( repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
245 assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
246 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
247 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
248 assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
251 public void testIsMetadataSupportFile()
253 assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
254 assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ));
255 assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ));
256 assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ));
258 assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
259 assertFalse( repoRequest.isMetadataSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
260 assertFalse( repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
261 assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
262 assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
263 assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
264 assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
267 public void testIsDefault()
269 assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
270 assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
271 assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
273 assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
274 assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
275 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
276 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
277 assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
278 assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml" ) );
279 assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.sha1" ) );
280 assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.md5" ) );
282 assertFalse( repoRequest.isDefault( null ) );
283 assertFalse( repoRequest.isDefault( "" ) );
284 assertFalse( repoRequest.isDefault( "foo" ) );
285 assertFalse( repoRequest.isDefault( "some.short/path" ) );
288 public void testIsLegacy()
290 assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
291 assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
292 assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
294 assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
295 assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
296 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
297 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
298 assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
300 assertFalse( repoRequest.isLegacy( null ) );
301 assertFalse( repoRequest.isLegacy( "" ) );
302 assertFalse( repoRequest.isLegacy( "some.short/path" ) );
305 private ManagedRepositoryContent createManagedRepo( String layout )
308 File repoRoot = getTestFile( "target/test-repo" );
309 return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
313 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
315 public void testToNativePathArtifactDefaultToDefaultDualExtension()
318 ManagedRepositoryContent repository = createManagedRepo( "default" );
320 // Test (artifact) default to default - dual extension
321 assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest
322 .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) );
326 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
328 public void testToNativePathArtifactLegacyToDefaultDualExtension()
331 ManagedRepositoryContent repository = createManagedRepo( "default" );
333 // Test (artifact) legacy to default - dual extension
334 // NOTE: The detection of a dual extension is flawed.
335 assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
336 .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) );
339 public void testToNativePathMetadataDefaultToDefault()
342 ManagedRepositoryContent repository = createManagedRepo( "default" );
344 // Test (metadata) default to default
345 assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repoRequest
346 .toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repository ) );
349 public void testNativePathPomLegacyToDefault()
352 ManagedRepositoryContent repository = createManagedRepo( "default" );
354 // Test (pom) legacy to default
355 assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom",
356 repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) );
359 public void testNativePathPomLegacyToLegacy()
362 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
364 // Test (pom) legacy to default
365 assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom",
366 repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) );
369 public void testNativePathPomLegacyToDefaultEjb()
372 ManagedRepositoryContent repository = createManagedRepo( "default" );
374 // Test (pom) legacy to default
375 assertEquals( "mygroup/myejb/1.0/myejb-1.0.jar",
376 repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) );
379 public void testNativePathPomLegacyToLegacyEjb()
382 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
384 // Test (pom) legacy to default
385 assertEquals( "mygroup/ejbs/myejb-1.0.jar",
386 repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) );
389 public void testNativePathPomLegacyToLegacyStrutsModule()
392 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
394 // Test (pom) legacy to default
395 assertEquals( "WebPortal/struts-modules/eventsDB-1.2.3.struts-module",
396 repoRequest.toNativePath( "WebPortal/struts-modules/eventsDB-1.2.3.struts-module", repository ) );
399 public void testNativePathSupportFileLegacyToDefault()
402 ManagedRepositoryContent repository = createManagedRepo( "default" );
404 // Test (supportfile) legacy to default
405 assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repoRequest
406 .toNativePath( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repository ) );
409 public void testNativePathBadRequestTooShort()
412 ManagedRepositoryContent repository = createManagedRepo( "default" );
414 // Test bad request path (too short)
417 repoRequest.toNativePath( "org.apache.derby/license.txt", repository );
418 fail( "Should have thrown an exception about a too short path." );
420 catch ( LayoutException e )
426 public void testNativePathBadRequestBlank()
429 ManagedRepositoryContent repository = createManagedRepo( "default" );
431 // Test bad request path (too short)
434 repoRequest.toNativePath( "", repository );
435 fail( "Should have thrown an exception about an blank request." );
437 catch ( LayoutException e )
443 public void testNativePathBadRequestNull()
446 ManagedRepositoryContent repository = createManagedRepo( "default" );
448 // Test bad request path (too short)
451 repoRequest.toNativePath( null, repository );
452 fail( "Should have thrown an exception about an null request." );
454 catch ( LayoutException e )
460 public void testNativePathBadRequestUnknownType()
463 ManagedRepositoryContent repository = createManagedRepo( "default" );
465 // Test bad request path (too short)
468 repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt", repository );
469 fail( "Should have thrown an exception about an invalid type." );
471 catch ( LayoutException e )
477 public void testToNativePathLegacyMetadataDefaultToLegacy()
480 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
482 // Test (metadata) default to legacy
484 // Special Case: This direction is not supported, should throw a LayoutException.
487 repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml", repository );
488 fail("Should have thrown a LayoutException, can't translate a maven-metadata.xml to a legacy layout.");
490 catch(LayoutException e)
496 public void testNativePathPomDefaultToLegacy()
499 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
501 // Test (pom) default to legacy
502 assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest
503 .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) );
506 public void testNativePathSupportFileDefaultToLegacy()
509 ManagedRepositoryContent repository = createManagedRepo( "legacy" );
511 // Test (supportfile) default to legacy
512 assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repoRequest
513 .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) );
516 private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
520 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":"
521 + ( classifier != null ? classifier + ":" : "" ) + type;
523 ArtifactReference reference = repoRequest.toArtifactReference( path );
525 assertNotNull( expectedId + " - Should not be null.", reference );
527 assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
528 assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
529 if ( StringUtils.isNotBlank( classifier ) )
531 assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
533 assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
534 assertEquals( expectedId + " - Type", type, reference.getType() );
537 private void assertInvalidRequest( String path )
541 repoRequest.toArtifactReference( path );
542 fail( "Expected a LayoutException on an invalid path [" + path + "]" );
544 catch ( LayoutException e )
550 private RepositoryRequest repoRequest;
553 protected void setUp()
558 repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class );