]> source.dussan.org Git - archiva.git/blob
b8580eaac020c762029d20077544c55109aa08f5
[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     // TODO: test snapshot, rest of artifacts
137     public void testGetArtifactMetadata()
138         throws Exception
139     {
140         Collection<ArtifactMetadata> springArtifacts = resolver.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus",
141                                                                               "plexus-spring", "1.2" );
142         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
143         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
144         {
145             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
146             {
147                 return o1.getId().compareTo( o2.getId() );
148             }
149         } );
150
151         assertEquals( 3, artifacts.size() );
152
153         ArtifactMetadata artifactMetadata = artifacts.get( 0 );
154         assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
155         MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
156         assertEquals( 0, facet.getBuildNumber() );
157         assertNull( facet.getTimestamp() );
158         assertEquals( "sources", facet.getClassifier() );
159         // TODO
160 //        assertEquals( "java-source", facet.getType() );
161
162         artifactMetadata = artifacts.get( 1 );
163         assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
164         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
165         assertEquals( 0, facet.getBuildNumber() );
166         assertNull( facet.getTimestamp() );
167         assertNull( facet.getClassifier() );
168         // TODO
169 //        assertEquals( "jar", facet.getType() );
170
171         artifactMetadata = artifacts.get( 2 );
172         assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
173         facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
174         assertEquals( 0, facet.getBuildNumber() );
175         assertNull( facet.getTimestamp() );
176         assertNull( facet.getClassifier() );
177         // TODO
178 //        assertEquals( "pom", facet.getType() );
179     }
180
181     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
182     {
183         assertDependency( dependency, groupId, artifactId, version, "compile" );
184     }
185
186     private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
187                                    String scope )
188     {
189         assertEquals( artifactId, dependency.getArtifactId() );
190         assertEquals( "jar", dependency.getType() );
191         assertEquals( version, dependency.getVersion() );
192         assertEquals( groupId, dependency.getGroupId() );
193         assertEquals( scope, dependency.getScope() );
194         assertNull( dependency.getClassifier() );
195         assertNull( dependency.getSystemPath() );
196     }
197
198     public void testGetProjectVersionMetadataForTimestampedSnapshot()
199         throws Exception
200     {
201         ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache",
202                                                                       "5-SNAPSHOT" );
203         MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
204         assertEquals( "pom", facet.getPackaging() );
205         assertEquals( "http://www.apache.org/", metadata.getUrl() );
206         assertNull( facet.getParent() );
207         assertEquals( "org.apache", facet.getGroupId() );
208         assertEquals( "apache", facet.getArtifactId() );
209         assertNull( metadata.getCiManagement() );
210         assertNotNull( metadata.getDescription() );
211         // TODO: this would be better
212 //        assertEquals(
213 //            "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
214 //                "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
215 //                "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
216 //                "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
217 //                "developers and users.", metadata.getDescription() );
218         assertEquals( "5-SNAPSHOT", metadata.getId() );
219         assertNull( metadata.getIssueManagement() );
220         checkApacheLicense( metadata );
221         assertEquals( "The Apache Software Foundation", metadata.getName() );
222         String path = "maven/pom/trunk/asf";
223         assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
224         assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
225         assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
226         checkOrganizationApache( metadata );
227         assertEquals( 1, metadata.getMailingLists().size() );
228         assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
229                            "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
230                            "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
231                            Collections.<String>emptyList(), true );
232         assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
233     }
234
235     public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
236         throws Exception
237     {
238         FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata",
239                                                                "1.0-SNAPSHOT" );
240         assertNull( metadata );
241     }
242
243     public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
244         throws Exception
245     {
246         FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata",
247                                                                "1.0-SNAPSHOT" );
248         assertNull( metadata );
249     }
250
251     public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
252         throws Exception
253     {
254         FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
255                                                                "1.0-SNAPSHOT" );
256         assertNull( metadata );
257     }
258
259     public void testGetProjectVersionMetadataForInvalidPom()
260         throws Exception
261     {
262         assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
263
264         try
265         {
266             resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
267             fail( "Should have received an exception due to invalid POM" );
268         }
269         catch ( MetadataResolutionException e )
270         {
271             assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID,
272                                                                RepositoryProblemFacet.FACET_ID ).isEmpty() );
273             RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
274                                                                                                          RepositoryProblemFacet.FACET_ID,
275                                                                                                          "com.example.test/invalid-pom/1.0" );
276             assertEquals( "invalid-pom", facet.getProblem() );
277         }
278     }
279
280     public void testGetProjectVersionMetadataForMislocatedPom()
281         throws Exception
282     {
283         assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
284
285         try
286         {
287             resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
288             fail( "Should have received an exception due to mislocated POM" );
289         }
290         catch ( MetadataResolutionException e )
291         {
292             assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID,
293                                                                RepositoryProblemFacet.FACET_ID ).isEmpty() );
294             RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
295                                                                                                          RepositoryProblemFacet.FACET_ID,
296                                                                                                          "com.example.test/mislocated-pom/1.0" );
297             assertEquals( "mislocated-pom", facet.getProblem() );
298         }
299     }
300
301     public void testGetProjectVersionMetadataForMissingPom()
302         throws Exception
303     {
304         assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
305
306         FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
307         assertNull( metadata );
308
309         assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
310         RepositoryProblemFacet facet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID,
311                                                                                                      RepositoryProblemFacet.FACET_ID,
312                                                                                                      "com.example.test/missing-pom/1.0" );
313         assertEquals( "missing-pom", facet.getProblem() );
314
315     }
316
317     public void testGetRootNamespaces()
318     {
319         assertEquals( Arrays.asList( "com", "org" ), resolver.getRootNamespaces( TEST_REPO_ID ) );
320     }
321
322     public void testGetNamespaces()
323     {
324         assertEquals( Arrays.asList( "example" ), resolver.getNamespaces( TEST_REPO_ID, "com" ) );
325         assertEquals( Arrays.asList( "test" ), resolver.getNamespaces( TEST_REPO_ID, "com.example" ) );
326         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "com.example.test" ) );
327
328         assertEquals( Arrays.asList( "apache", "codehaus" ), resolver.getNamespaces( TEST_REPO_ID, "org" ) );
329         assertEquals( Arrays.asList( "archiva", "maven" ), resolver.getNamespaces( TEST_REPO_ID, "org.apache" ) );
330         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) );
331         assertEquals( Arrays.asList( "plugins", "shared" ), resolver.getNamespaces( TEST_REPO_ID,
332                                                                                     "org.apache.maven" ) );
333         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
334                                                                                "org.apache.maven.plugins" ) );
335         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
336                                                                                "org.apache.maven.shared" ) );
337
338         assertEquals( Arrays.asList( "plexus" ), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus" ) );
339         assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) );
340     }
341
342     public void testGetProjects()
343     {
344         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com" ) );
345         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com.example" ) );
346         assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
347                                      "missing-metadata", "test-artifact" ), resolver.getProjects( TEST_REPO_ID,
348                                                                                                   "com.example.test" ) );
349
350         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org" ) );
351         assertEquals( Arrays.asList( "apache" ), resolver.getProjects( TEST_REPO_ID, "org.apache" ) );
352         assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
353                       resolver.getProjects( TEST_REPO_ID, "org.apache.archiva" ) );
354         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
355         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID,
356                                                                              "org.apache.maven.plugins" ) );
357         assertEquals( Arrays.asList( "maven-downloader" ), resolver.getProjects( TEST_REPO_ID,
358                                                                                  "org.apache.maven.shared" ) );
359     }
360
361     public void testGetProjectVersions()
362     {
363         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
364                                                                                     "incomplete-metadata" ) );
365         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
366                                                                                     "malformed-metadata" ) );
367         assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
368                                                                                     "missing-metadata" ) );
369         assertEquals( Arrays.asList( "1.0" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
370                                                                            "invalid-pom" ) );
371
372         assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache",
373                                                                                        "apache" ) );
374
375         assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
376                                                                              "archiva" ) );
377         assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
378                                                                              "archiva-base" ) );
379         assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
380                                                                              "archiva-common" ) );
381         assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
382                                                                              "archiva-modules" ) );
383         assertEquals( Arrays.asList( "3" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
384                                                                          "archiva-parent" ) );
385
386         assertEquals( Collections.<String>emptyList(), resolver.getProjectVersions( TEST_REPO_ID,
387                                                                                     "org.apache.maven.shared",
388                                                                                     "maven-downloader" ) );
389     }
390
391     public void testGetArtifacts()
392     {
393         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
394                                                                                                    "org.codehaus.plexus",
395                                                                                                    "plexus-spring",
396                                                                                                    "1.2" ) );
397         assertEquals( 3, artifacts.size() );
398         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
399         {
400             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
401             {
402                 return o1.getId().compareTo( o2.getId() );
403             }
404         } );
405
406         assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
407         assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
408         assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
409                         "f83aa25f016212a551a4b2249985effc" );
410     }
411
412     public void testGetArtifactsFiltered()
413     {
414         ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
415             "plexus-spring-1.2.pom" ) );
416         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
417                                                                                                    "org.codehaus.plexus",
418                                                                                                    "plexus-spring",
419                                                                                                    "1.2", filter ) );
420         assertEquals( 2, artifacts.size() );
421         Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
422         {
423             public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
424             {
425                 return o1.getId().compareTo( o2.getId() );
426             }
427         } );
428
429         assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
430         assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
431     }
432
433     public void testGetArtifactsTimestampedSnapshots()
434     {
435         List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
436                                                                                                    "com.example.test",
437                                                                                                    "missing-metadata",
438                                                                                                    "1.0-SNAPSHOT" ) );
439         assertEquals( 1, artifacts.size() );
440
441         ArtifactMetadata artifact = artifacts.get( 0 );
442         assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
443         assertEquals( "com.example.test", artifact.getNamespace() );
444         assertEquals( "missing-metadata", artifact.getProject() );
445         assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
446         assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
447     }
448
449     private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
450     {
451         assertEquals( id, artifact.getId() );
452         assertEquals( md5, artifact.getMd5() );
453         assertEquals( sha1, artifact.getSha1() );
454         assertEquals( size, artifact.getSize() );
455         assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
456         assertEquals( "plexus-spring", artifact.getProject() );
457         assertEquals( "1.2", artifact.getVersion() );
458         assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
459     }
460
461     private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
462                                     String unsubscribe, List<String> otherArchives, boolean allowPost )
463     {
464         assertEquals( archive, mailingList.getMainArchiveUrl() );
465         if ( allowPost )
466         {
467             assertEquals( post, mailingList.getPostAddress() );
468         }
469         else
470         {
471             assertNull( mailingList.getPostAddress() );
472         }
473         assertEquals( subscribe, mailingList.getSubscribeAddress() );
474         assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
475         assertEquals( name, mailingList.getName() );
476         assertEquals( otherArchives, mailingList.getOtherArchives() );
477     }
478
479     private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
480                                     String nabbleUrl )
481     {
482         List<String> otherArchives = new ArrayList<String>();
483         otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
484         if ( nabbleUrl != null )
485         {
486             otherArchives.add( nabbleUrl );
487         }
488         otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
489         assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
490                            prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
491                            prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
492     }
493
494     private void checkApacheLicense( ProjectVersionMetadata metadata )
495     {
496         assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
497                                                   "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
498                       metadata.getLicenses() );
499     }
500
501     private void checkOrganizationApache( ProjectVersionMetadata metadata )
502     {
503         assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
504         assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
505     }
506 }