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.common.utils.FileUtil;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
28 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
30 import org.apache.archiva.metadata.model.Dependency;
31 import org.apache.archiva.metadata.model.License;
32 import org.apache.archiva.metadata.model.MailingList;
33 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
34 import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
35 import org.apache.archiva.metadata.repository.filter.AllFilter;
36 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
37 import org.apache.archiva.metadata.repository.filter.Filter;
38 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
39 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
40 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
41 import org.apache.archiva.proxy.common.WagonFactory;
42 import org.apache.archiva.proxy.common.WagonFactoryRequest;
43 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
44 import org.apache.commons.io.FileUtils;
45 import org.apache.maven.wagon.Wagon;
46 import org.junit.Before;
47 import org.junit.Test;
48 import org.junit.runner.RunWith;
49 import org.springframework.test.context.ContextConfiguration;
51 import javax.inject.Inject;
52 import javax.inject.Named;
54 import java.io.IOException;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.Collection;
58 import java.util.Collections;
59 import java.util.Comparator;
60 import java.util.List;
62 import static org.mockito.Mockito.mock;
63 import static org.mockito.Mockito.when;
65 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
66 @ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
67 public class Maven2RepositoryMetadataResolverTest
70 private static final Filter<String> ALL = new AllFilter<String>();
73 @Named ( value = "repositoryStorage#maven2" )
74 private Maven2RepositoryStorage storage;
76 private static final String TEST_REPO_ID = "test";
78 private static final String TEST_REMOTE_REPO_ID = "central";
80 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
82 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
84 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
86 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
88 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
90 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
92 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
94 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
97 private ArchivaConfiguration configuration;
99 private WagonFactory wagonFactory;
101 ManagedRepositoryConfiguration testRepo;
112 c = new Configuration();
113 testRepo = new ManagedRepositoryConfiguration();
114 testRepo.setId( TEST_REPO_ID );
115 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
116 testRepo.setReleases( true );
117 testRepo.setSnapshots( true );
118 c.addManagedRepository( testRepo );
120 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
121 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
122 testRemoteRepo.setLayout( "default" );
123 testRemoteRepo.setName( "Central Repository" );
124 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
125 testRemoteRepo.setTimeout( 10 );
126 c.addRemoteRepository( testRemoteRepo );
128 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
129 proxyConnector.setSourceRepoId( TEST_REPO_ID );
130 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
131 proxyConnector.setDisabled( false );
132 c.addProxyConnector( proxyConnector );
134 configuration.save( c );
136 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
137 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
139 wagonFactory = mock( WagonFactory.class );
141 storage.setWagonFactory( wagonFactory );
143 Wagon wagon = new MockWagon();
144 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
148 public void testModelWithJdkProfileActivation()
151 ReadMetadataRequest readMetadataRequest =
152 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
153 "maven-archiver" ).projectVersion( "2.4.1" );
154 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
155 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
159 public void testGetProjectVersionMetadata()
162 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
163 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
164 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
165 assertEquals( "jar", facet.getPackaging() );
166 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
167 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
168 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
169 assertEquals( "1.2.1", facet.getParent().getVersion() );
170 assertEquals( "archiva-common", facet.getArtifactId() );
171 assertEquals( "org.apache.archiva", facet.getGroupId() );
172 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
173 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
174 assertNotNull( metadata.getDescription() );
175 // TODO: this would be better
177 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
178 // metadata.getDescription() );
179 assertEquals( "1.2.1", metadata.getId() );
180 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
181 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
182 checkApacheLicense( metadata );
183 assertEquals( "Archiva Base :: Common", metadata.getName() );
184 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
185 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
186 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
187 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
188 checkOrganizationApache( metadata );
190 assertEquals( 4, metadata.getMailingLists().size() );
191 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
192 "http://www.nabble.com/archiva-users-f16426.html" );
193 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
194 "http://www.nabble.com/archiva-dev-f16427.html" );
195 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
196 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
197 "http://www.nabble.com/Archiva---Issues-f29617.html" );
199 List<Dependency> dependencies = metadata.getDependencies();
200 assertEquals( 10, dependencies.size() );
201 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
202 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
203 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
204 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
205 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
206 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
207 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
208 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
209 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
210 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
214 public void testGetArtifactMetadata()
217 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
218 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
219 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
220 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
222 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
224 return o1.getId().compareTo( o2.getId() );
228 assertEquals( 3, artifacts.size() );
230 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
231 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
232 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
233 assertEquals( 0, facet.getBuildNumber() );
234 assertNull( facet.getTimestamp() );
235 assertEquals( "sources", facet.getClassifier() );
236 assertEquals( "java-source", facet.getType() );
238 artifactMetadata = artifacts.get( 1 );
239 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
240 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
241 assertEquals( 0, facet.getBuildNumber() );
242 assertNull( facet.getTimestamp() );
243 assertNull( facet.getClassifier() );
244 assertEquals( "jar", facet.getType() );
246 artifactMetadata = artifacts.get( 2 );
247 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
248 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
249 assertEquals( 0, facet.getBuildNumber() );
250 assertNull( facet.getTimestamp() );
251 assertNull( facet.getClassifier() );
252 assertEquals( "pom", facet.getType() );
256 public void testGetArtifactMetadataSnapshots()
259 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
260 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
261 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
262 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
264 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
266 return o1.getId().compareTo( o2.getId() );
270 assertEquals( 6, artifacts.size() );
272 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
273 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
274 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
275 assertEquals( 1, facet.getBuildNumber() );
276 assertEquals( "20100308.230825", facet.getTimestamp() );
277 assertNull( facet.getClassifier() );
278 assertEquals( "jar", facet.getType() );
280 artifactMetadata = artifacts.get( 1 );
281 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
282 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
283 assertEquals( 1, facet.getBuildNumber() );
284 assertEquals( "20100308.230825", facet.getTimestamp() );
285 assertNull( facet.getClassifier() );
286 assertEquals( "pom", facet.getType() );
288 artifactMetadata = artifacts.get( 2 );
289 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
290 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
291 assertEquals( 2, facet.getBuildNumber() );
292 assertEquals( "20100310.014828", facet.getTimestamp() );
293 assertEquals( "javadoc", facet.getClassifier() );
294 assertEquals( "javadoc", facet.getType() );
296 artifactMetadata = artifacts.get( 3 );
297 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
298 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
299 assertEquals( 2, facet.getBuildNumber() );
300 assertEquals( "20100310.014828", facet.getTimestamp() );
301 assertEquals( "sources", facet.getClassifier() );
302 assertEquals( "java-source", facet.getType() );
304 artifactMetadata = artifacts.get( 4 );
305 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
306 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
307 assertEquals( 2, facet.getBuildNumber() );
308 assertEquals( "20100310.014828", facet.getTimestamp() );
309 assertNull( facet.getClassifier() );
310 assertEquals( "jar", facet.getType() );
312 artifactMetadata = artifacts.get( 5 );
313 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
314 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
315 assertEquals( 2, facet.getBuildNumber() );
316 assertEquals( "20100310.014828", facet.getTimestamp() );
317 assertNull( facet.getClassifier() );
318 assertEquals( "pom", facet.getType() );
321 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
323 assertDependency( dependency, groupId, artifactId, version, "compile" );
326 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
329 assertEquals( artifactId, dependency.getArtifactId() );
330 assertEquals( "jar", dependency.getType() );
331 assertEquals( version, dependency.getVersion() );
332 assertEquals( groupId, dependency.getGroupId() );
333 assertEquals( scope, dependency.getScope() );
334 assertNull( dependency.getClassifier() );
335 assertNull( dependency.getSystemPath() );
339 public void testGetProjectVersionMetadataForTimestampedSnapshot()
342 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
343 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
344 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
345 assertEquals( "pom", facet.getPackaging() );
346 assertEquals( "http://www.apache.org/", metadata.getUrl() );
347 assertNull( facet.getParent() );
348 assertEquals( "org.apache", facet.getGroupId() );
349 assertEquals( "apache", facet.getArtifactId() );
350 assertNull( metadata.getCiManagement() );
351 assertNotNull( metadata.getDescription() );
352 // TODO: this would be better
354 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
355 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
356 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
357 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
358 // "developers and users.", metadata.getDescription() );
359 assertEquals( "5-SNAPSHOT", metadata.getId() );
360 assertNull( metadata.getIssueManagement() );
361 checkApacheLicense( metadata );
362 assertEquals( "The Apache Software Foundation", metadata.getName() );
363 String path = "maven/pom/trunk/asf";
364 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
365 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
366 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
367 checkOrganizationApache( metadata );
368 assertEquals( 1, metadata.getMailingLists().size() );
369 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
370 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
371 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
372 Collections.<String>emptyList(), true );
373 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
377 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
382 storage.readProjectVersionMetadata(
383 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
384 fail( "Should not be found" );
386 catch ( RepositoryStorageMetadataNotFoundException e )
388 assertEquals( "missing-pom", e.getId() );
393 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
398 storage.readProjectVersionMetadata(
399 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
400 fail( "Should not be found" );
402 catch ( RepositoryStorageMetadataNotFoundException e )
404 assertEquals( "missing-pom", e.getId() );
409 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
414 storage.readProjectVersionMetadata(
415 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
416 fail( "Should not be found" );
418 catch ( RepositoryStorageMetadataNotFoundException e )
420 assertEquals( "missing-pom", e.getId() );
425 public void testGetProjectVersionMetadataForInvalidPom()
430 storage.readProjectVersionMetadata(
431 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
432 fail( "Should have received an exception due to invalid POM" );
434 catch ( RepositoryStorageMetadataInvalidException e )
436 assertEquals( "invalid-pom", e.getId() );
441 public void testGetProjectVersionMetadataForMislocatedPom()
446 storage.readProjectVersionMetadata(
447 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
448 fail( "Should have received an exception due to mislocated POM" );
450 catch ( RepositoryStorageMetadataInvalidException e )
452 assertEquals( "mislocated-pom", e.getId() );
457 public void testGetProjectVersionMetadataForMissingPom()
462 storage.readProjectVersionMetadata(
463 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
464 fail( "Should not be found" );
466 catch ( RepositoryStorageMetadataNotFoundException e )
468 assertEquals( "missing-pom", e.getId() );
473 public void testGetRootNamespaces()
476 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
480 public void testGetNamespaces()
483 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
484 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
485 assertEquals( Collections.<String>emptyList(),
486 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
488 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
489 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
490 assertEquals( Collections.<String>emptyList(),
491 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
492 assertEquals( Arrays.asList( "plugins", "shared" ),
493 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
494 assertEquals( Collections.<String>emptyList(),
495 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
496 assertEquals( Collections.<String>emptyList(),
497 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
499 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
500 assertEquals( Collections.<String>emptyList(),
501 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
505 public void testGetProjects()
508 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
509 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
510 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
511 "missing-metadata", "missing-parent", "test-artifact" ),
512 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
514 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
515 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
516 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
517 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
518 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
519 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
520 assertEquals( Collections.<String>emptyList(),
521 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
522 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
523 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
527 public void testGetProjectVersions()
530 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
531 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
532 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
533 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
534 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
535 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
536 assertEquals( Arrays.asList( "1.0" ),
537 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
539 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
540 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
542 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
543 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
544 assertEquals( Arrays.asList( "1.2.1" ),
545 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
546 assertEquals( Arrays.asList( "1.2.1" ),
547 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
548 assertEquals( Arrays.asList( "1.2.1" ),
549 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
550 assertEquals( Arrays.asList( "3" ),
551 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
553 assertEquals( Collections.<String>emptyList(),
554 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
558 public void testGetArtifacts()
561 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
562 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
563 assertEquals( 3, artifacts.size() );
564 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
566 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
568 return o1.getId().compareTo( o2.getId() );
572 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
573 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
574 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
575 "f83aa25f016212a551a4b2249985effc" );
579 public void testGetArtifactsFiltered()
582 ExcludesFilter<String> filter =
583 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
584 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
585 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
586 assertEquals( 2, artifacts.size() );
587 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
589 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
591 return o1.getId().compareTo( o2.getId() );
595 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
596 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
600 public void testGetArtifactsTimestampedSnapshots()
603 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
604 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
605 assertEquals( 1, artifacts.size() );
607 ArtifactMetadata artifact = artifacts.get( 0 );
608 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
609 assertEquals( "com.example.test", artifact.getNamespace() );
610 assertEquals( "missing-metadata", artifact.getProject() );
611 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
612 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
615 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
617 assertEquals( id, artifact.getId() );
618 assertEquals( md5, artifact.getMd5() );
619 assertEquals( sha1, artifact.getSha1() );
620 assertEquals( size, artifact.getSize() );
621 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
622 assertEquals( "plexus-spring", artifact.getProject() );
623 assertEquals( "1.2", artifact.getVersion() );
624 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
627 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
628 String unsubscribe, List<String> otherArchives, boolean allowPost )
630 assertEquals( archive, mailingList.getMainArchiveUrl() );
633 assertEquals( post, mailingList.getPostAddress() );
637 assertNull( mailingList.getPostAddress() );
639 assertEquals( subscribe, mailingList.getSubscribeAddress() );
640 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
641 assertEquals( name, mailingList.getName() );
642 assertEquals( otherArchives, mailingList.getOtherArchives() );
645 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
648 List<String> otherArchives = new ArrayList<String>();
649 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
650 if ( nabbleUrl != null )
652 otherArchives.add( nabbleUrl );
654 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
655 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
656 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
657 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
660 private void checkApacheLicense( ProjectVersionMetadata metadata )
662 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
663 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
664 metadata.getLicenses() );
667 private void checkOrganizationApache( ProjectVersionMetadata metadata )
669 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
670 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
673 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
676 for ( String path : pathsToBeDeleted )
678 File dir = new File( FileUtil.getBasedir(), path );
679 FileUtils.deleteDirectory( dir );
681 assertFalse( dir.exists() );
683 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
685 new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
686 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
688 FileUtils.deleteDirectory( dest );
689 FileUtils.deleteDirectory( parentPom );
690 FileUtils.deleteDirectory( rootPom );
692 assertFalse( dest.exists() );
693 assertFalse( parentPom.exists() );
694 assertFalse( rootPom.exists() );
697 private File copyTestArtifactWithParent( String srcPath, String destPath )
700 File src = new File( FileUtil.getBasedir(), srcPath );
701 File dest = new File( FileUtil.getBasedir(), destPath );
703 FileUtils.copyDirectory( src, dest );
704 assertTrue( dest.exists() );