1 package org.apache.archiva.metadata.repository.storage.maven2;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
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;
45 public class Maven2RepositoryMetadataResolverTest
46 extends PlexusInSpringTestCase
48 private Maven2RepositoryMetadataResolver resolver;
50 private static final String TEST_REPO_ID = "test";
52 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
54 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
56 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
58 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
60 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
62 private MetadataRepository metadataRepository;
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 );
77 resolver = (Maven2RepositoryMetadataResolver) lookup( StorageMetadataResolver.class, "maven2" );
78 metadataRepository = (MetadataRepository) lookup( MetadataRepository.class );
79 metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID );
82 public void testGetProjectVersionMetadata()
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
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 );
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" );
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" );
136 public void testGetArtifactMetadata()
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>()
144 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
146 return o1.getId().compareTo( o2.getId() );
150 assertEquals( 3, artifacts.size() );
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() );
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() );
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() );
177 public void testGetArtifactMetadataSnapshots()
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>()
185 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
187 return o1.getId().compareTo( o2.getId() );
191 assertEquals( 6, artifacts.size() );
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() );
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() );
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() );
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() );
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() );
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() );
242 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
244 assertDependency( dependency, groupId, artifactId, version, "compile" );
247 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
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() );
259 public void testGetProjectVersionMetadataForTimestampedSnapshot()
262 ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache",
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
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() );
296 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
299 FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata",
301 assertNull( metadata );
304 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
307 FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata",
309 assertNull( metadata );
312 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
315 FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
317 assertNull( metadata );
320 public void testGetProjectVersionMetadataForInvalidPom()
323 assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
327 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
328 fail( "Should have received an exception due to invalid POM" );
330 catch ( MetadataResolutionException e )
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() );
341 public void testGetProjectVersionMetadataForMislocatedPom()
344 assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
348 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
349 fail( "Should have received an exception due to mislocated POM" );
351 catch ( MetadataResolutionException e )
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() );
362 public void testGetProjectVersionMetadataForMissingPom()
365 assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
367 FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
368 assertNull( metadata );
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() );
378 public void testGetRootNamespaces()
380 assertEquals( Arrays.asList( "com", "org" ), resolver.getRootNamespaces( TEST_REPO_ID ) );
383 public void testGetNamespaces()
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" ) );
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" ) );
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" ) );
403 public void testGetProjects()
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" ) );
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" ) );
422 public void testGetProjectVersions()
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",
433 assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache",
436 assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
438 assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
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" ) );
447 assertEquals( Collections.<String>emptyList(), resolver.getProjectVersions( TEST_REPO_ID,
448 "org.apache.maven.shared",
449 "maven-downloader" ) );
452 public void testGetArtifacts()
454 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
455 "org.codehaus.plexus",
458 assertEquals( 3, artifacts.size() );
459 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
461 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
463 return o1.getId().compareTo( o2.getId() );
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" );
473 public void testGetArtifactsFiltered()
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",
481 assertEquals( 2, artifacts.size() );
482 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
484 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
486 return o1.getId().compareTo( o2.getId() );
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 );
494 public void testGetArtifactsTimestampedSnapshots()
496 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
500 assertEquals( 1, artifacts.size() );
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() );
510 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
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() );
522 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
523 String unsubscribe, List<String> otherArchives, boolean allowPost )
525 assertEquals( archive, mailingList.getMainArchiveUrl() );
528 assertEquals( post, mailingList.getPostAddress() );
532 assertNull( mailingList.getPostAddress() );
534 assertEquals( subscribe, mailingList.getSubscribeAddress() );
535 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
536 assertEquals( name, mailingList.getName() );
537 assertEquals( otherArchives, mailingList.getOtherArchives() );
540 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
543 List<String> otherArchives = new ArrayList<String>();
544 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
545 if ( nabbleUrl != null )
547 otherArchives.add( nabbleUrl );
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 );
555 private void checkApacheLicense( ProjectVersionMetadata metadata )
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() );
562 private void checkOrganizationApache( ProjectVersionMetadata metadata )
564 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
565 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );