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 junit.framework.TestCase;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.Dependency;
25 import org.apache.archiva.metadata.model.License;
26 import org.apache.archiva.metadata.model.MailingList;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.repository.filter.AllFilter;
29 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
30 import org.apache.archiva.metadata.repository.filter.Filter;
31 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
32 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
33 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
34 import org.apache.maven.archiva.configuration.Configuration;
35 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
42 import javax.inject.Inject;
43 import javax.inject.Named;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Collection;
48 import java.util.Collections;
49 import java.util.Comparator;
50 import java.util.List;
52 @RunWith( SpringJUnit4ClassRunner.class )
53 @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
54 public class Maven2RepositoryMetadataResolverTest
57 private static final Filter<String> ALL = new AllFilter<String>();
60 @Named(value = "repositoryStorage#maven2")
61 private Maven2RepositoryStorage storage;
63 private static final String TEST_REPO_ID = "test";
65 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
67 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
69 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
71 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
73 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
76 private ArchivaConfiguration configuration;
84 //ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
85 Configuration c = new Configuration();
86 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
87 testRepo.setId( TEST_REPO_ID );
88 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
89 c.addManagedRepository( testRepo );
90 configuration.save( c );
92 //storage = (Maven2RepositoryStorage) lookup( RepositoryStorage.class, "maven2" );
96 public void testGetProjectVersionMetadata()
99 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva",
100 "archiva-common", "1.2.1" );
101 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
102 assertEquals( "jar", facet.getPackaging() );
103 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
104 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
105 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
106 assertEquals( "1.2.1", facet.getParent().getVersion() );
107 assertEquals( "archiva-common", facet.getArtifactId() );
108 assertEquals( "org.apache.archiva", facet.getGroupId() );
109 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
110 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
111 assertNotNull( metadata.getDescription() );
112 // TODO: this would be better
114 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
115 // metadata.getDescription() );
116 assertEquals( "1.2.1", metadata.getId() );
117 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
118 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
119 checkApacheLicense( metadata );
120 assertEquals( "Archiva Base :: Common", metadata.getName() );
121 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
122 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
123 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
124 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
125 checkOrganizationApache( metadata );
127 assertEquals( 4, metadata.getMailingLists().size() );
128 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
129 "http://www.nabble.com/archiva-users-f16426.html" );
130 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
131 "http://www.nabble.com/archiva-dev-f16427.html" );
132 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
133 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
134 "http://www.nabble.com/Archiva---Issues-f29617.html" );
136 List<Dependency> dependencies = metadata.getDependencies();
137 assertEquals( 10, dependencies.size() );
138 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
139 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
140 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
141 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
142 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
143 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
144 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
145 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
146 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
147 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
151 public void testGetArtifactMetadata()
154 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID,
155 "org.codehaus.plexus",
156 "plexus-spring", "1.2", ALL );
157 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
158 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
160 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
162 return o1.getId().compareTo( o2.getId() );
166 assertEquals( 3, artifacts.size() );
168 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
169 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
170 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
171 assertEquals( 0, facet.getBuildNumber() );
172 assertNull( facet.getTimestamp() );
173 assertEquals( "sources", facet.getClassifier() );
174 assertEquals( "java-source", facet.getType() );
176 artifactMetadata = artifacts.get( 1 );
177 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
178 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
179 assertEquals( 0, facet.getBuildNumber() );
180 assertNull( facet.getTimestamp() );
181 assertNull( facet.getClassifier() );
182 assertEquals( "jar", facet.getType() );
184 artifactMetadata = artifacts.get( 2 );
185 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
186 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
187 assertEquals( 0, facet.getBuildNumber() );
188 assertNull( facet.getTimestamp() );
189 assertNull( facet.getClassifier() );
190 assertEquals( "pom", facet.getType() );
194 public void testGetArtifactMetadataSnapshots()
197 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test",
198 "test-artifact", "1.0-SNAPSHOT",
200 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
201 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
203 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
205 return o1.getId().compareTo( o2.getId() );
209 assertEquals( 6, artifacts.size() );
211 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
212 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
213 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
214 assertEquals( 1, facet.getBuildNumber() );
215 assertEquals( "20100308.230825", facet.getTimestamp() );
216 assertNull( facet.getClassifier() );
217 assertEquals( "jar", facet.getType() );
219 artifactMetadata = artifacts.get( 1 );
220 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
221 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
222 assertEquals( 1, facet.getBuildNumber() );
223 assertEquals( "20100308.230825", facet.getTimestamp() );
224 assertNull( facet.getClassifier() );
225 assertEquals( "pom", facet.getType() );
227 artifactMetadata = artifacts.get( 2 );
228 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
229 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
230 assertEquals( 2, facet.getBuildNumber() );
231 assertEquals( "20100310.014828", facet.getTimestamp() );
232 assertEquals( "javadoc", facet.getClassifier() );
233 assertEquals( "javadoc", facet.getType() );
235 artifactMetadata = artifacts.get( 3 );
236 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
237 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
238 assertEquals( 2, facet.getBuildNumber() );
239 assertEquals( "20100310.014828", facet.getTimestamp() );
240 assertEquals( "sources", facet.getClassifier() );
241 assertEquals( "java-source", facet.getType() );
243 artifactMetadata = artifacts.get( 4 );
244 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
245 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
246 assertEquals( 2, facet.getBuildNumber() );
247 assertEquals( "20100310.014828", facet.getTimestamp() );
248 assertNull( facet.getClassifier() );
249 assertEquals( "jar", facet.getType() );
251 artifactMetadata = artifacts.get( 5 );
252 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
253 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
254 assertEquals( 2, facet.getBuildNumber() );
255 assertEquals( "20100310.014828", facet.getTimestamp() );
256 assertNull( facet.getClassifier() );
257 assertEquals( "pom", facet.getType() );
260 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
262 assertDependency( dependency, groupId, artifactId, version, "compile" );
265 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
268 assertEquals( artifactId, dependency.getArtifactId() );
269 assertEquals( "jar", dependency.getType() );
270 assertEquals( version, dependency.getVersion() );
271 assertEquals( groupId, dependency.getGroupId() );
272 assertEquals( scope, dependency.getScope() );
273 assertNull( dependency.getClassifier() );
274 assertNull( dependency.getSystemPath() );
278 public void testGetProjectVersionMetadataForTimestampedSnapshot()
281 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache",
283 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
284 assertEquals( "pom", facet.getPackaging() );
285 assertEquals( "http://www.apache.org/", metadata.getUrl() );
286 assertNull( facet.getParent() );
287 assertEquals( "org.apache", facet.getGroupId() );
288 assertEquals( "apache", facet.getArtifactId() );
289 assertNull( metadata.getCiManagement() );
290 assertNotNull( metadata.getDescription() );
291 // TODO: this would be better
293 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
294 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
295 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
296 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
297 // "developers and users.", metadata.getDescription() );
298 assertEquals( "5-SNAPSHOT", metadata.getId() );
299 assertNull( metadata.getIssueManagement() );
300 checkApacheLicense( metadata );
301 assertEquals( "The Apache Software Foundation", metadata.getName() );
302 String path = "maven/pom/trunk/asf";
303 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
304 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
305 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
306 checkOrganizationApache( metadata );
307 assertEquals( 1, metadata.getMailingLists().size() );
308 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
309 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
310 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
311 Collections.<String>emptyList(), true );
312 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
316 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
321 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
322 fail( "Should not be found" );
324 catch ( RepositoryStorageMetadataNotFoundException e )
326 assertEquals( "missing-pom", e.getId() );
331 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
336 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
338 fail( "Should not be found" );
340 catch ( RepositoryStorageMetadataNotFoundException e )
342 assertEquals( "missing-pom", e.getId() );
347 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
352 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
354 fail( "Should not be found" );
356 catch ( RepositoryStorageMetadataNotFoundException e )
358 assertEquals( "missing-pom", e.getId() );
363 public void testGetProjectVersionMetadataForInvalidPom()
368 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
369 fail( "Should have received an exception due to invalid POM" );
371 catch ( RepositoryStorageMetadataInvalidException e )
373 assertEquals( "invalid-pom", e.getId() );
378 public void testGetProjectVersionMetadataForMislocatedPom()
383 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
384 fail( "Should have received an exception due to mislocated POM" );
386 catch ( RepositoryStorageMetadataInvalidException e )
388 assertEquals( "mislocated-pom", e.getId() );
393 public void testGetProjectVersionMetadataForMissingPom()
398 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
399 fail( "Should not be found" );
401 catch ( RepositoryStorageMetadataNotFoundException e )
403 assertEquals( "missing-pom", e.getId() );
408 public void testGetRootNamespaces()
410 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
414 public void testGetNamespaces()
416 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
417 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
418 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "com.example.test",
421 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
422 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
423 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva",
425 assertEquals( Arrays.asList( "plugins", "shared" ), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven",
427 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins",
429 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared",
432 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
433 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus",
438 public void testGetProjects()
440 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
441 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
442 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
443 "missing-metadata", "test-artifact" ), storage.listProjects( TEST_REPO_ID,
447 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
448 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
449 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
450 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
451 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
452 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins",
454 assertEquals( Arrays.asList( "maven-downloader" ), storage.listProjects( TEST_REPO_ID,
455 "org.apache.maven.shared", ALL ) );
459 public void testGetProjectVersions()
461 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
462 "incomplete-metadata", ALL ) );
463 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
464 "malformed-metadata", ALL ) );
465 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
466 "missing-metadata", ALL ) );
467 assertEquals( Arrays.asList( "1.0" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
468 "invalid-pom", ALL ) );
470 assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache",
473 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), storage.listProjectVersions( TEST_REPO_ID,
474 "org.apache.archiva", "archiva",
476 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
477 "archiva-base", ALL ) );
478 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
479 "archiva-common", ALL ) );
480 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
481 "archiva-modules", ALL ) );
482 assertEquals( Arrays.asList( "3" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
483 "archiva-parent", ALL ) );
485 assertEquals( Collections.<String>emptyList(), storage.listProjectVersions( TEST_REPO_ID,
486 "org.apache.maven.shared",
487 "maven-downloader", ALL ) );
491 public void testGetArtifacts()
493 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
494 "org.codehaus.plexus",
498 assertEquals( 3, artifacts.size() );
499 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
501 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
503 return o1.getId().compareTo( o2.getId() );
507 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
508 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
509 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
510 "f83aa25f016212a551a4b2249985effc" );
514 public void testGetArtifactsFiltered()
516 ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
517 "plexus-spring-1.2.pom" ) );
518 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
519 "org.codehaus.plexus",
523 assertEquals( 2, artifacts.size() );
524 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
526 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
528 return o1.getId().compareTo( o2.getId() );
532 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
533 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
537 public void testGetArtifactsTimestampedSnapshots()
539 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
544 assertEquals( 1, artifacts.size() );
546 ArtifactMetadata artifact = artifacts.get( 0 );
547 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
548 assertEquals( "com.example.test", artifact.getNamespace() );
549 assertEquals( "missing-metadata", artifact.getProject() );
550 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
551 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
554 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
556 assertEquals( id, artifact.getId() );
557 assertEquals( md5, artifact.getMd5() );
558 assertEquals( sha1, artifact.getSha1() );
559 assertEquals( size, artifact.getSize() );
560 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
561 assertEquals( "plexus-spring", artifact.getProject() );
562 assertEquals( "1.2", artifact.getVersion() );
563 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
566 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
567 String unsubscribe, List<String> otherArchives, boolean allowPost )
569 assertEquals( archive, mailingList.getMainArchiveUrl() );
572 assertEquals( post, mailingList.getPostAddress() );
576 assertNull( mailingList.getPostAddress() );
578 assertEquals( subscribe, mailingList.getSubscribeAddress() );
579 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
580 assertEquals( name, mailingList.getName() );
581 assertEquals( otherArchives, mailingList.getOtherArchives() );
584 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
587 List<String> otherArchives = new ArrayList<String>();
588 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
589 if ( nabbleUrl != null )
591 otherArchives.add( nabbleUrl );
593 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
594 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
595 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
596 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
599 private void checkApacheLicense( ProjectVersionMetadata metadata )
601 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
602 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
603 metadata.getLicenses() );
606 private void checkOrganizationApache( ProjectVersionMetadata metadata )
608 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
609 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );