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