]> source.dussan.org Git - archiva.git/blob
65002297eb8ee58a2ead4ac517903dc6b603340e
[archiva.git] /
1 package org.apache.archiva.metadata.repository.storage.maven2;
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 junit.framework.TestCase;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.Dependency;
25 import org.apache.archiva.metadata.model.License;
26 import org.apache.archiva.metadata.model.MailingList;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.repository.filter.AllFilter;
29 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
30 import org.apache.archiva.metadata.repository.filter.Filter;
31 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
32 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
33 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
34 import org.apache.maven.archiva.configuration.Configuration;
35 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41
42 import javax.inject.Inject;
43 import javax.inject.Named;
44 import java.io.File;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Collection;
48 import java.util.Collections;
49 import java.util.Comparator;
50 import java.util.List;
51
52 @RunWith( SpringJUnit4ClassRunner.class )
53 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
54 public class Maven2RepositoryMetadataResolverTest
55     extends TestCase
56 {
57     private static final Filter<String> ALL = new AllFilter<String>();
58
59     @Inject
60     @Named(value = "repositoryStorage#maven2")
61     private Maven2RepositoryStorage storage;
62
63     private static final String TEST_REPO_ID = "test";
64
65     private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
66
67     private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
68
69     private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
70
71     private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
72
73     private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
74
75     @Inject
76     private ArchivaConfiguration configuration;
77
78     @Before
79     public void setUp()
80         throws Exception
81     {
82         super.setUp();
83
84         //ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
85         Configuration c = new Configuration();
86         ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
87         testRepo.setId( TEST_REPO_ID );
88         testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
89         c.addManagedRepository( testRepo );
90         configuration.save( c );
91
92         //storage = (Maven2RepositoryStorage) lookup( RepositoryStorage.class, "maven2" );
93     }
94
95     @Test
96     public void testGetProjectVersionMetadata()
97         throws Exception
98     {
99         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva",
100                                                                               "archiva-common", "1.2.1" );
101         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
102         assertEquals( "jar", facet.getPackaging() );
103         assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
104         assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
105         assertEquals( "archiva-base", facet.getParent().getArtifactId() );
106         assertEquals( "1.2.1", facet.getParent().getVersion() );
107         assertEquals( "archiva-common", facet.getArtifactId() );
108         assertEquals( "org.apache.archiva", facet.getGroupId() );
109         assertEquals( "continuum", metadata.getCiManagement().getSystem() );
110         assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
111         assertNotNull( metadata.getDescription() );
112         // TODO: this would be better
113 //        assertEquals(
114 //            "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
115 //            metadata.getDescription() );
116         assertEquals( "1.2.1", metadata.getId() );
117         assertEquals( "jira", metadata.getIssueManagement().getSystem() );
118         assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
119         checkApacheLicense( metadata );
120         assertEquals( "Archiva Base :: Common", metadata.getName() );
121         String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
122         assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
123         assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
124         assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
125         checkOrganizationApache( metadata );
126
127         assertEquals( 4, metadata.getMailingLists().size() );
128         assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
129                            "http://www.nabble.com/archiva-users-f16426.html" );
130         assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
131                            "http://www.nabble.com/archiva-dev-f16427.html" );
132         assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
133         assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
134                            "http://www.nabble.com/Archiva---Issues-f29617.html" );
135
136         List<Dependency> dependencies = metadata.getDependencies();
137         assertEquals( 10, dependencies.size() );
138         assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
139         assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
140         assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
141         assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
142         assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
143         assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
144         assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
145         assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
146         assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
147         assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
148     }
149
150     @Test
151     public void testGetArtifactMetadata()
152         throws Exception
153     {
154         Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID,
155                                                                                       "org.codehaus.plexus",
156                                                                                       "plexus-spring", "1.2", ALL );
157         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
158         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
159         {
160             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
161             {
162                 return o1.getId().compareTo( o2.getId() );
163             }
164         } );
165
166         assertEquals( 3, artifacts.size() );
167
168         ArtifactMetadata artifactMetadata = artifacts.get( 0 );
169         assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
170         MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
171         assertEquals( 0, facet.getBuildNumber() );
172         assertNull( facet.getTimestamp() );
173         assertEquals( "sources", facet.getClassifier() );
174         assertEquals( "java-source", facet.getType() );
175
176         artifactMetadata = artifacts.get( 1 );
177         assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
178         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
179         assertEquals( 0, facet.getBuildNumber() );
180         assertNull( facet.getTimestamp() );
181         assertNull( facet.getClassifier() );
182         assertEquals( "jar", facet.getType() );
183
184         artifactMetadata = artifacts.get( 2 );
185         assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
186         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
187         assertEquals( 0, facet.getBuildNumber() );
188         assertNull( facet.getTimestamp() );
189         assertNull( facet.getClassifier() );
190         assertEquals( "pom", facet.getType() );
191     }
192
193     @Test
194     public void testGetArtifactMetadataSnapshots()
195         throws Exception
196     {
197         Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test",
198                                                                                     "test-artifact", "1.0-SNAPSHOT",
199                                                                                     ALL );
200         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
201         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
202         {
203             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
204             {
205                 return o1.getId().compareTo( o2.getId() );
206             }
207         } );
208
209         assertEquals( 6, artifacts.size() );
210
211         ArtifactMetadata artifactMetadata = artifacts.get( 0 );
212         assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
213         MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
214         assertEquals( 1, facet.getBuildNumber() );
215         assertEquals( "20100308.230825", facet.getTimestamp() );
216         assertNull( facet.getClassifier() );
217         assertEquals( "jar", facet.getType() );
218
219         artifactMetadata = artifacts.get( 1 );
220         assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
221         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
222         assertEquals( 1, facet.getBuildNumber() );
223         assertEquals( "20100308.230825", facet.getTimestamp() );
224         assertNull( facet.getClassifier() );
225         assertEquals( "pom", facet.getType() );
226
227         artifactMetadata = artifacts.get( 2 );
228         assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
229         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
230         assertEquals( 2, facet.getBuildNumber() );
231         assertEquals( "20100310.014828", facet.getTimestamp() );
232         assertEquals( "javadoc", facet.getClassifier() );
233         assertEquals( "javadoc", facet.getType() );
234
235         artifactMetadata = artifacts.get( 3 );
236         assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
237         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
238         assertEquals( 2, facet.getBuildNumber() );
239         assertEquals( "20100310.014828", facet.getTimestamp() );
240         assertEquals( "sources", facet.getClassifier() );
241         assertEquals( "java-source", facet.getType() );
242
243         artifactMetadata = artifacts.get( 4 );
244         assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
245         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
246         assertEquals( 2, facet.getBuildNumber() );
247         assertEquals( "20100310.014828", facet.getTimestamp() );
248         assertNull( facet.getClassifier() );
249         assertEquals( "jar", facet.getType() );
250
251         artifactMetadata = artifacts.get( 5 );
252         assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
253         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
254         assertEquals( 2, facet.getBuildNumber() );
255         assertEquals( "20100310.014828", facet.getTimestamp() );
256         assertNull( facet.getClassifier() );
257         assertEquals( "pom", facet.getType() );
258     }
259
260     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
261     {
262         assertDependency( dependency, groupId, artifactId, version, "compile" );
263     }
264
265     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
266                                    String scope )
267     {
268         assertEquals( artifactId, dependency.getArtifactId() );
269         assertEquals( "jar", dependency.getType() );
270         assertEquals( version, dependency.getVersion() );
271         assertEquals( groupId, dependency.getGroupId() );
272         assertEquals( scope, dependency.getScope() );
273         assertNull( dependency.getClassifier() );
274         assertNull( dependency.getSystemPath() );
275     }
276
277     @Test
278     public void testGetProjectVersionMetadataForTimestampedSnapshot()
279         throws Exception
280     {
281         ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache",
282                                                                               "5-SNAPSHOT" );
283         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
284         assertEquals( "pom", facet.getPackaging() );
285         assertEquals( "http://www.apache.org/", metadata.getUrl() );
286         assertNull( facet.getParent() );
287         assertEquals( "org.apache", facet.getGroupId() );
288         assertEquals( "apache", facet.getArtifactId() );
289         assertNull( metadata.getCiManagement() );
290         assertNotNull( metadata.getDescription() );
291         // TODO: this would be better
292 //        assertEquals(
293 //            "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
294 //                "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
295 //                "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
296 //                "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
297 //                "developers and users.", metadata.getDescription() );
298         assertEquals( "5-SNAPSHOT", metadata.getId() );
299         assertNull( metadata.getIssueManagement() );
300         checkApacheLicense( metadata );
301         assertEquals( "The Apache Software Foundation", metadata.getName() );
302         String path = "maven/pom/trunk/asf";
303         assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
304         assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
305         assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
306         checkOrganizationApache( metadata );
307         assertEquals( 1, metadata.getMailingLists().size() );
308         assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
309                            "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
310                            "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
311                            Collections.<String>emptyList(), true );
312         assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
313     }
314
315     @Test
316     public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
317         throws Exception
318     {
319         try
320         {
321             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
322             fail( "Should not be found" );
323         }
324         catch ( RepositoryStorageMetadataNotFoundException e )
325         {
326             assertEquals( "missing-pom", e.getId() );
327         }
328     }
329
330     @Test
331     public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
332         throws Exception
333     {
334         try
335         {
336             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
337                                                 "1.0-SNAPSHOT" );
338             fail( "Should not be found" );
339         }
340         catch ( RepositoryStorageMetadataNotFoundException e )
341         {
342             assertEquals( "missing-pom", e.getId() );
343         }
344     }
345
346     @Test
347     public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
348         throws Exception
349     {
350         try
351         {
352             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
353                                                 "1.0-SNAPSHOT" );
354             fail( "Should not be found" );
355         }
356         catch ( RepositoryStorageMetadataNotFoundException e )
357         {
358             assertEquals( "missing-pom", e.getId() );
359         }
360     }
361
362     @Test
363     public void testGetProjectVersionMetadataForInvalidPom()
364         throws Exception
365     {
366         try
367         {
368             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
369             fail( "Should have received an exception due to invalid POM" );
370         }
371         catch ( RepositoryStorageMetadataInvalidException e )
372         {
373             assertEquals( "invalid-pom", e.getId() );
374         }
375     }
376
377     @Test
378     public void testGetProjectVersionMetadataForMislocatedPom()
379         throws Exception
380     {
381         try
382         {
383             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
384             fail( "Should have received an exception due to mislocated POM" );
385         }
386         catch ( RepositoryStorageMetadataInvalidException e )
387         {
388             assertEquals( "mislocated-pom", e.getId() );
389         }
390     }
391
392     @Test
393     public void testGetProjectVersionMetadataForMissingPom()
394         throws Exception
395     {
396         try
397         {
398             storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
399             fail( "Should not be found" );
400         }
401         catch ( RepositoryStorageMetadataNotFoundException e )
402         {
403             assertEquals( "missing-pom", e.getId() );
404         }
405     }
406
407     @Test
408     public void testGetRootNamespaces()
409     {
410         assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
411     }
412
413     @Test
414     public void testGetNamespaces()
415     {
416         assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
417         assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
418         assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "com.example.test",
419                                                                                ALL ) );
420
421         assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
422         assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
423         assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva",
424                                                                                ALL ) );
425         assertEquals( Arrays.asList( "plugins", "shared" ), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven",
426                                                                                     ALL ) );
427         assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins",
428                                                                                ALL ) );
429         assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared",
430                                                                                ALL ) );
431
432         assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
433         assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus",
434                                                                                ALL ) );
435     }
436
437     @Test
438     public void testGetProjects()
439     {
440         assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
441         assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
442         assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
443                                      "missing-metadata", "test-artifact" ), storage.listProjects( TEST_REPO_ID,
444                                                                                                   "com.example.test",
445                                                                                                   ALL ) );
446
447         assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
448         assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
449         assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
450                       storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
451         assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
452         assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins",
453                                                                              ALL ) );
454         assertEquals( Arrays.asList( "maven-downloader" ), storage.listProjects( TEST_REPO_ID,
455                                                                                  "org.apache.maven.shared", ALL ) );
456     }
457
458     @Test
459     public void testGetProjectVersions()
460     {
461         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
462                                                                                     "incomplete-metadata", ALL ) );
463         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
464                                                                                     "malformed-metadata", ALL ) );
465         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
466                                                                                     "missing-metadata", ALL ) );
467         assertEquals( Arrays.asList( "1.0" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
468                                                                            "invalid-pom", ALL ) );
469
470         assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache",
471                                                                                        "apache", ALL ) );
472
473         assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), storage.listProjectVersions( TEST_REPO_ID,
474                                                                                       "org.apache.archiva", "archiva",
475                                                                                       ALL ) );
476         assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
477                                                                              "archiva-base", ALL ) );
478         assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
479                                                                              "archiva-common", ALL ) );
480         assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
481                                                                              "archiva-modules", ALL ) );
482         assertEquals( Arrays.asList( "3" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
483                                                                          "archiva-parent", ALL ) );
484
485         assertEquals( Collections.<String>emptyList(), storage.listProjectVersions( TEST_REPO_ID,
486                                                                                     "org.apache.maven.shared",
487                                                                                     "maven-downloader", ALL ) );
488     }
489
490     @Test
491     public void testGetArtifacts()
492     {
493         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
494                                                                                                            "org.codehaus.plexus",
495                                                                                                            "plexus-spring",
496                                                                                                            "1.2",
497                                                                                                            ALL ) );
498         assertEquals( 3, artifacts.size() );
499         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
500         {
501             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
502             {
503                 return o1.getId().compareTo( o2.getId() );
504             }
505         } );
506
507         assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
508         assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
509         assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
510                         "f83aa25f016212a551a4b2249985effc" );
511     }
512
513     @Test
514     public void testGetArtifactsFiltered()
515     {
516         ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
517             "plexus-spring-1.2.pom" ) );
518         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
519                                                                                                            "org.codehaus.plexus",
520                                                                                                            "plexus-spring",
521                                                                                                            "1.2",
522                                                                                                            filter ) );
523         assertEquals( 2, artifacts.size() );
524         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
525         {
526             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
527             {
528                 return o1.getId().compareTo( o2.getId() );
529             }
530         } );
531
532         assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
533         assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
534     }
535
536     @Test
537     public void testGetArtifactsTimestampedSnapshots()
538     {
539         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
540                                                                                                            "com.example.test",
541                                                                                                            "missing-metadata",
542                                                                                                            "1.0-SNAPSHOT",
543                                                                                                            ALL ) );
544         assertEquals( 1, artifacts.size() );
545
546         ArtifactMetadata artifact = artifacts.get( 0 );
547         assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
548         assertEquals( "com.example.test", artifact.getNamespace() );
549         assertEquals( "missing-metadata", artifact.getProject() );
550         assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
551         assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
552     }
553
554     private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
555     {
556         assertEquals( id, artifact.getId() );
557         assertEquals( md5, artifact.getMd5() );
558         assertEquals( sha1, artifact.getSha1() );
559         assertEquals( size, artifact.getSize() );
560         assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
561         assertEquals( "plexus-spring", artifact.getProject() );
562         assertEquals( "1.2", artifact.getVersion() );
563         assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
564     }
565
566     private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
567                                     String unsubscribe, List<String> otherArchives, boolean allowPost )
568     {
569         assertEquals( archive, mailingList.getMainArchiveUrl() );
570         if ( allowPost )
571         {
572             assertEquals( post, mailingList.getPostAddress() );
573         }
574         else
575         {
576             assertNull( mailingList.getPostAddress() );
577         }
578         assertEquals( subscribe, mailingList.getSubscribeAddress() );
579         assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
580         assertEquals( name, mailingList.getName() );
581         assertEquals( otherArchives, mailingList.getOtherArchives() );
582     }
583
584     private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
585                                     String nabbleUrl )
586     {
587         List<String> otherArchives = new ArrayList<String>();
588         otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
589         if ( nabbleUrl != null )
590         {
591             otherArchives.add( nabbleUrl );
592         }
593         otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
594         assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
595                            prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
596                            prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
597     }
598
599     private void checkApacheLicense( ProjectVersionMetadata metadata )
600     {
601         assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
602                                                   "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
603                       metadata.getLicenses() );
604     }
605
606     private void checkOrganizationApache( ProjectVersionMetadata metadata )
607     {
608         assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
609         assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
610     }
611 }