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 ( { "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 ( "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 @Named ( "archivaConfiguration#default" )
98 protected ArchivaConfiguration configuration;
100 private WagonFactory wagonFactory;
102 ManagedRepositoryConfiguration testRepo;
113 c = new Configuration();
114 testRepo = new ManagedRepositoryConfiguration();
115 testRepo.setId( TEST_REPO_ID );
116 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
117 testRepo.setReleases( true );
118 testRepo.setSnapshots( true );
119 c.addManagedRepository( testRepo );
121 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
122 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
123 testRemoteRepo.setLayout( "default" );
124 testRemoteRepo.setName( "Central Repository" );
125 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
126 testRemoteRepo.setTimeout( 10 );
127 c.addRemoteRepository( testRemoteRepo );
129 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
130 proxyConnector.setSourceRepoId( TEST_REPO_ID );
131 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
132 proxyConnector.setDisabled( false );
133 c.addProxyConnector( proxyConnector );
135 configuration.save( c );
137 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
138 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
140 wagonFactory = mock( WagonFactory.class );
142 storage.setWagonFactory( wagonFactory );
144 Wagon wagon = new MockWagon();
145 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
149 public void testModelWithJdkProfileActivation()
152 ReadMetadataRequest readMetadataRequest =
153 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
154 "maven-archiver" ).projectVersion( "2.4.1" );
155 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
156 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
160 public void testGetProjectVersionMetadata()
163 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
164 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
165 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
166 assertEquals( "jar", facet.getPackaging() );
167 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
168 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
169 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
170 assertEquals( "1.2.1", facet.getParent().getVersion() );
171 assertEquals( "archiva-common", facet.getArtifactId() );
172 assertEquals( "org.apache.archiva", facet.getGroupId() );
173 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
174 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
175 assertNotNull( metadata.getDescription() );
176 // TODO: this would be better
178 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
179 // metadata.getDescription() );
180 assertEquals( "1.2.1", metadata.getId() );
181 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
182 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
183 checkApacheLicense( metadata );
184 assertEquals( "Archiva Base :: Common", metadata.getName() );
185 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
186 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
187 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
188 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
189 checkOrganizationApache( metadata );
191 assertEquals( 4, metadata.getMailingLists().size() );
192 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
193 "http://www.nabble.com/archiva-users-f16426.html" );
194 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
195 "http://www.nabble.com/archiva-dev-f16427.html" );
196 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
197 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
198 "http://www.nabble.com/Archiva---Issues-f29617.html" );
200 List<Dependency> dependencies = metadata.getDependencies();
201 assertEquals( 10, dependencies.size() );
202 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
203 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
204 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
205 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
206 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
207 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
208 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
209 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
210 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
211 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
215 public void testGetArtifactMetadata()
218 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
219 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
220 List<ArtifactMetadata> artifacts = new ArrayList<>( springArtifacts );
221 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
224 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
226 return o1.getId().compareTo( o2.getId() );
230 assertEquals( 3, artifacts.size() );
232 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
233 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
234 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
235 assertEquals( 0, facet.getBuildNumber() );
236 assertNull( facet.getTimestamp() );
237 assertEquals( "sources", facet.getClassifier() );
238 assertEquals( "java-source", facet.getType() );
240 artifactMetadata = artifacts.get( 1 );
241 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
242 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
243 assertEquals( 0, facet.getBuildNumber() );
244 assertNull( facet.getTimestamp() );
245 assertNull( facet.getClassifier() );
246 assertEquals( "jar", facet.getType() );
248 artifactMetadata = artifacts.get( 2 );
249 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
250 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
251 assertEquals( 0, facet.getBuildNumber() );
252 assertNull( facet.getTimestamp() );
253 assertNull( facet.getClassifier() );
254 assertEquals( "pom", facet.getType() );
258 public void testGetArtifactMetadataSnapshots()
261 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
262 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
263 List<ArtifactMetadata> artifacts = new ArrayList<>( testArtifacts );
264 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
267 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
269 return o1.getId().compareTo( o2.getId() );
273 assertEquals( 6, artifacts.size() );
275 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
276 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
277 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
278 assertEquals( 1, facet.getBuildNumber() );
279 assertEquals( "20100308.230825", facet.getTimestamp() );
280 assertNull( facet.getClassifier() );
281 assertEquals( "jar", facet.getType() );
283 artifactMetadata = artifacts.get( 1 );
284 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
285 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
286 assertEquals( 1, facet.getBuildNumber() );
287 assertEquals( "20100308.230825", facet.getTimestamp() );
288 assertNull( facet.getClassifier() );
289 assertEquals( "pom", facet.getType() );
291 artifactMetadata = artifacts.get( 2 );
292 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
293 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
294 assertEquals( 2, facet.getBuildNumber() );
295 assertEquals( "20100310.014828", facet.getTimestamp() );
296 assertEquals( "javadoc", facet.getClassifier() );
297 assertEquals( "javadoc", facet.getType() );
299 artifactMetadata = artifacts.get( 3 );
300 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
301 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
302 assertEquals( 2, facet.getBuildNumber() );
303 assertEquals( "20100310.014828", facet.getTimestamp() );
304 assertEquals( "sources", facet.getClassifier() );
305 assertEquals( "java-source", facet.getType() );
307 artifactMetadata = artifacts.get( 4 );
308 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
309 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
310 assertEquals( 2, facet.getBuildNumber() );
311 assertEquals( "20100310.014828", facet.getTimestamp() );
312 assertNull( facet.getClassifier() );
313 assertEquals( "jar", facet.getType() );
315 artifactMetadata = artifacts.get( 5 );
316 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
317 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
318 assertEquals( 2, facet.getBuildNumber() );
319 assertEquals( "20100310.014828", facet.getTimestamp() );
320 assertNull( facet.getClassifier() );
321 assertEquals( "pom", facet.getType() );
324 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
326 assertDependency( dependency, groupId, artifactId, version, "compile" );
329 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
332 assertEquals( artifactId, dependency.getArtifactId() );
333 assertEquals( "jar", dependency.getType() );
334 assertEquals( version, dependency.getVersion() );
335 assertEquals( groupId, dependency.getGroupId() );
336 assertEquals( scope, dependency.getScope() );
337 assertNull( dependency.getClassifier() );
338 assertNull( dependency.getSystemPath() );
342 public void testGetProjectVersionMetadataForTimestampedSnapshot()
345 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
346 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
347 MavenProjectFacet facet = MavenProjectFacet.class.cast( metadata.getFacet( MavenProjectFacet.FACET_ID ) );
348 assertEquals( "pom", facet.getPackaging() );
349 assertEquals( "http://www.apache.org/", metadata.getUrl() );
350 assertNull( facet.getParent() );
351 assertEquals( "org.apache", facet.getGroupId() );
352 assertEquals( "apache", facet.getArtifactId() );
353 assertNull( metadata.getCiManagement() );
354 assertNotNull( metadata.getDescription() );
355 // TODO: this would be better
357 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
358 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
359 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
360 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
361 // "developers and users.", metadata.getDescription() );
362 assertEquals( "5-SNAPSHOT", metadata.getId() );
363 assertNull( metadata.getIssueManagement() );
364 checkApacheLicense( metadata );
365 assertEquals( "The Apache Software Foundation", metadata.getName() );
366 String path = "maven/pom/trunk/asf";
367 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
368 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
369 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
370 checkOrganizationApache( metadata );
371 assertEquals( 1, metadata.getMailingLists().size() );
372 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
373 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
374 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
375 Collections.<String>emptyList(), true );
376 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
380 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
385 storage.readProjectVersionMetadata(
386 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
387 fail( "Should not be found" );
389 catch ( RepositoryStorageMetadataNotFoundException e )
391 assertEquals( "missing-pom", e.getId() );
396 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
401 storage.readProjectVersionMetadata(
402 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
403 fail( "Should not be found" );
405 catch ( RepositoryStorageMetadataNotFoundException e )
407 assertEquals( "missing-pom", e.getId() );
412 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
417 storage.readProjectVersionMetadata(
418 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
419 fail( "Should not be found" );
421 catch ( RepositoryStorageMetadataNotFoundException e )
423 assertEquals( "missing-pom", e.getId() );
428 public void testGetProjectVersionMetadataForInvalidPom()
433 storage.readProjectVersionMetadata(
434 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
435 fail( "Should have received an exception due to invalid POM" );
437 catch ( RepositoryStorageMetadataInvalidException e )
439 assertEquals( "invalid-pom", e.getId() );
444 public void testGetProjectVersionMetadataForMislocatedPom()
449 storage.readProjectVersionMetadata(
450 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
451 fail( "Should have received an exception due to mislocated POM" );
453 catch ( RepositoryStorageMetadataInvalidException e )
455 assertEquals( "mislocated-pom", e.getId() );
460 public void testGetProjectVersionMetadataForMissingPom()
465 storage.readProjectVersionMetadata(
466 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
467 fail( "Should not be found" );
469 catch ( RepositoryStorageMetadataNotFoundException e )
471 assertEquals( "missing-pom", e.getId() );
476 public void testGetRootNamespaces()
479 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
483 public void testGetNamespaces()
486 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
487 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
488 assertEquals( Collections.<String>emptyList(),
489 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
491 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
492 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
493 assertEquals( Collections.<String>emptyList(),
494 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
495 assertEquals( Arrays.asList( "plugins", "shared" ),
496 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
497 assertEquals( Collections.<String>emptyList(),
498 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
499 assertEquals( Collections.<String>emptyList(),
500 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
502 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
503 assertEquals( Collections.<String>emptyList(),
504 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
508 public void testGetProjects()
511 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
512 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
513 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
514 "missing-metadata", "missing-parent", "test-artifact" ),
515 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
517 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
518 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
519 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
520 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
521 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
522 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
523 assertEquals( Collections.<String>emptyList(),
524 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
525 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
526 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
530 public void testGetProjectVersions()
533 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
534 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
535 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
536 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
537 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
538 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
539 assertEquals( Arrays.asList( "1.0" ),
540 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
542 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
543 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
545 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
546 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
547 assertEquals( Arrays.asList( "1.2.1" ),
548 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
549 assertEquals( Arrays.asList( "1.2.1" ),
550 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
551 assertEquals( Arrays.asList( "1.2.1" ),
552 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
553 assertEquals( Arrays.asList( "3" ),
554 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
556 assertEquals( Collections.<String>emptyList(),
557 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
561 public void testGetArtifacts()
564 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
565 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
566 assertEquals( 3, artifacts.size() );
567 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
570 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
572 return o1.getId().compareTo( o2.getId() );
576 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
577 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
578 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
579 "f83aa25f016212a551a4b2249985effc" );
583 public void testGetArtifactsFiltered()
586 ExcludesFilter<String> filter =
587 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
588 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
589 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
590 assertEquals( 2, artifacts.size() );
591 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
594 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
596 return o1.getId().compareTo( o2.getId() );
600 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
601 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
605 public void testGetArtifactsTimestampedSnapshots()
608 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
609 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
610 assertEquals( 1, artifacts.size() );
612 ArtifactMetadata artifact = artifacts.get( 0 );
613 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
614 assertEquals( "com.example.test", artifact.getNamespace() );
615 assertEquals( "missing-metadata", artifact.getProject() );
616 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
617 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
620 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
622 assertEquals( id, artifact.getId() );
623 assertEquals( md5, artifact.getMd5() );
624 assertEquals( sha1, artifact.getSha1() );
625 assertEquals( size, artifact.getSize() );
626 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
627 assertEquals( "plexus-spring", artifact.getProject() );
628 assertEquals( "1.2", artifact.getVersion() );
629 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
632 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
633 String unsubscribe, List<String> otherArchives, boolean allowPost )
635 assertEquals( archive, mailingList.getMainArchiveUrl() );
638 assertEquals( post, mailingList.getPostAddress() );
642 assertNull( mailingList.getPostAddress() );
644 assertEquals( subscribe, mailingList.getSubscribeAddress() );
645 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
646 assertEquals( name, mailingList.getName() );
647 assertEquals( otherArchives, mailingList.getOtherArchives() );
650 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
653 List<String> otherArchives = new ArrayList<>();
654 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
655 if ( nabbleUrl != null )
657 otherArchives.add( nabbleUrl );
659 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
660 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
661 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
662 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
665 private void checkApacheLicense( ProjectVersionMetadata metadata )
667 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
668 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
669 metadata.getLicenses() );
672 private void checkOrganizationApache( ProjectVersionMetadata metadata )
674 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
675 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
678 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
681 for ( String path : pathsToBeDeleted )
683 File dir = new File( FileUtil.getBasedir(), path );
684 FileUtils.deleteDirectory( dir );
686 assertFalse( dir.exists() );
688 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
690 new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
691 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
693 FileUtils.deleteDirectory( dest );
694 FileUtils.deleteDirectory( parentPom );
695 FileUtils.deleteDirectory( rootPom );
697 assertFalse( dest.exists() );
698 assertFalse( parentPom.exists() );
699 assertFalse( rootPom.exists() );
702 private File copyTestArtifactWithParent( String srcPath, String destPath )
705 File src = new File( FileUtil.getBasedir(), srcPath );
706 File dest = new File( FileUtil.getBasedir(), destPath );
708 FileUtils.copyDirectory( src, dest );
709 assertTrue( dest.exists() );