]> source.dussan.org Git - archiva.git/blob
56ba649bbd22036e2830873f8c3fa67a29075481
[archiva.git] /
1 package org.apache.maven.archiva.repository.content;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
26
27 /**
28  * RepositoryRequestTest 
29  *
30  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
31  * @version $Id$
32  */
33 public class RepositoryRequestTest
34     extends AbstractRepositoryLayerTestCase
35 {
36     public void testInvalidRequestNoArtifactId()
37     {
38         assertInvalidRequest( "groupId/jars/-1.0.jar" );
39     }
40
41     public void testInvalidLegacyRequestBadLocation()
42     {
43         assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" );
44     }
45
46     public void testInvalidRequestTooShort()
47     {
48         assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
49     }
50
51     public void testInvalidDefaultRequestBadLocation()
52     {
53         assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
54     }
55
56     public void testValidLegacyGanymed()
57         throws Exception
58     {
59         assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
60                      null, "jar" );
61     }
62
63     public void testValidDefaultGanymed()
64         throws Exception
65     {
66         assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
67                      "ganymed-ssh2", "build210", null, "jar" );
68     }
69
70     public void testValidLegacyJavaxComm()
71         throws Exception
72     {
73         assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
74     }
75
76     public void testValidDefaultJavaxComm()
77         throws Exception
78     {
79         assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
80     }
81
82     public void testValidLegacyJavaxPersistence()
83         throws Exception
84     {
85         assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
86                      "3.0-public_review", null, "jar" );
87     }
88
89     public void testValidDefaultJavaxPersistence()
90         throws Exception
91     {
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" );
94     }
95
96     public void testValidLegacyMavenTestPlugin()
97         throws Exception
98     {
99         assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
100     }
101
102     public void testValidDefaultMavenTestPlugin()
103         throws Exception
104     {
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" );
107     }
108
109     public void testValidLegacyCommonsLangJavadoc()
110         throws Exception
111     {
112         assertValid( "commons-lang/jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1-javadoc",
113                      null, "javadoc" );
114     }
115
116     public void testValidDefaultCommonsLangJavadoc()
117         throws Exception
118     {
119         assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
120                      "2.1", "javadoc", "javadoc" );
121     }
122
123     public void testValidLegacyDerbyPom()
124         throws Exception
125     {
126         assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
127     }
128
129     public void testValidDefaultDerbyPom()
130         throws Exception
131     {
132         assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
133                      null, "pom" );
134     }
135
136     public void testValidLegacyGeronimoEjbSpec()
137         throws Exception
138     {
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" );
141     }
142
143     public void testValidDefaultGeronimoEjbSpec()
144         throws Exception
145     {
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" );
148     }
149
150     public void testValidLegacyLdapSnapshot()
151         throws Exception
152     {
153         assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
154                      "0.9.1-SNAPSHOT", null, "pom" );
155     }
156
157     public void testValidDefaultLdapSnapshot()
158         throws Exception
159     {
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" );
162     }
163
164     public void testValidLegacyTestArchSnapshot()
165         throws Exception
166     {
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" );
169     }
170
171     public void testValidDefaultTestArchSnapshot()
172         throws Exception
173     {
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" );
176     }
177
178     public void testValidLegacyOddDottedArtifactId()
179         throws Exception
180     {
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" );
183     }
184
185     public void testValidDefaultOddDottedArtifactId()
186         throws Exception
187     {
188         assertValid(
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" );
191     }
192
193     public void testValidLegacyTimestampedSnapshot()
194         throws Exception
195     {
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" );
198     }
199
200     public void testValidDefaultTimestampedSnapshot()
201         throws Exception
202     {
203         assertValid(
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" );
206     }
207
208     public void testIsArtifact()
209     {
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" ) );
213         
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" ));
220     }
221
222     private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
223                               String type )
224         throws Exception
225     {
226         String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":"
227             + ( classifier != null ? classifier + ":" : "" ) + type;
228
229         ArtifactReference reference = repoRequest.toArtifactReference( path );
230
231         assertNotNull( expectedId + " - Should not be null.", reference );
232
233         assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
234         assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
235         if ( StringUtils.isNotBlank( classifier ) )
236         {
237             assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
238         }
239         assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
240         assertEquals( expectedId + " - Type", type, reference.getType() );
241     }
242
243     private void assertInvalidRequest( String path )
244     {
245         try
246         {
247             repoRequest.toArtifactReference( path );
248             fail( "Expected a LayoutException on an invalid path [" + path + "]" );
249         }
250         catch ( LayoutException e )
251         {
252             /* expected path */
253         }
254     }
255
256     private RepositoryRequest repoRequest;
257
258     @Override
259     protected void setUp()
260         throws Exception
261     {
262         super.setUp();
263
264         repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class );
265     }
266 }