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