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.layout.LayoutException;
28 * RepositoryRequestTest
30 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
33 public class RepositoryRequestTest
34 extends AbstractRepositoryLayerTestCase
36 public void testInvalidRequestNoArtifactId()
38 assertInvalidRequest( "groupId/jars/-1.0.jar" );
41 public void testInvalidLegacyRequestBadLocation()
43 assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" );
46 public void testInvalidRequestTooShort()
48 assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
51 public void testInvalidDefaultRequestBadLocation()
53 assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
56 public void testValidLegacyGanymed()
59 assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
63 public void testValidDefaultGanymed()
66 assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
67 "ganymed-ssh2", "build210", null, "jar" );
70 public void testValidLegacyJavaxComm()
73 assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
76 public void testValidDefaultJavaxComm()
79 assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
82 public void testValidLegacyJavaxPersistence()
85 assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
86 "3.0-public_review", null, "jar" );
89 public void testValidDefaultJavaxPersistence()
92 assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
93 "3.0-public_review", null, "jar" );
96 public void testValidLegacyMavenTestPlugin()
99 assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
102 public void testValidDefaultMavenTestPlugin()
105 assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin",
106 "1.8.2", null, "pom" );
109 public void testValidLegacyCommonsLangJavadoc()
112 assertValid( "commons-lang/jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1-javadoc",
116 public void testValidDefaultCommonsLangJavadoc()
119 assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
120 "2.1", "javadoc", "javadoc" );
123 public void testValidLegacyDerbyPom()
126 assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
129 public void testValidDefaultDerbyPom()
132 assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
136 public void testValidLegacyGeronimoEjbSpec()
139 assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
140 "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
143 public void testValidDefaultGeronimoEjbSpec()
146 assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
147 "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
150 public void testValidLegacyLdapSnapshot()
153 assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
154 "0.9.1-SNAPSHOT", null, "pom" );
157 public void testValidDefaultLdapSnapshot()
160 assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
161 "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
164 public void testValidLegacyTestArchSnapshot()
167 assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
168 "2.0.3-SNAPSHOT", null, "pom" );
171 public void testValidDefaultTestArchSnapshot()
174 assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
175 "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
178 public void testValidLegacyOddDottedArtifactId()
181 assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
182 "com.company.department.project", "0.2", null, "pom" );
185 public void testValidDefaultOddDottedArtifactId()
189 "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
190 "com.company.department", "com.company.department.project", "0.2", null, "pom" );
193 public void testValidLegacyTimestampedSnapshot()
196 assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
197 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
200 public void testValidDefaultTimestampedSnapshot()
204 "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
205 "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
208 public void testIsArtifact()
210 assertTrue( repoRequest.isArtifact( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
211 assertTrue( repoRequest.isArtifact( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
212 assertTrue( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
214 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ));
215 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ));
216 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ));
217 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ));
218 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
219 assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/maven-metadata.xml" ));
222 private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
226 String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":"
227 + ( classifier != null ? classifier + ":" : "" ) + type;
229 ArtifactReference reference = repoRequest.toArtifactReference( path );
231 assertNotNull( expectedId + " - Should not be null.", reference );
233 assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
234 assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
235 if ( StringUtils.isNotBlank( classifier ) )
237 assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
239 assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
240 assertEquals( expectedId + " - Type", type, reference.getType() );
243 private void assertInvalidRequest( String path )
247 repoRequest.toArtifactReference( path );
248 fail( "Expected a LayoutException on an invalid path [" + path + "]" );
250 catch ( LayoutException e )
256 private RepositoryRequest repoRequest;
259 protected void setUp()
264 repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class );