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.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.Configuration;
25 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
26 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
27 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
28 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
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.filter.AllFilter;
36 import org.apache.archiva.filter.ExcludesFilter;
37 import org.apache.archiva.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.maven.WagonFactory;
42 import org.apache.archiva.proxy.maven.WagonFactoryRequest;
43 import org.apache.archiva.repository.RepositoryRegistry;
44 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
45 import org.apache.commons.io.FileUtils;
46 import org.apache.maven.wagon.Wagon;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.springframework.test.context.ContextConfiguration;
52 import javax.inject.Inject;
53 import javax.inject.Named;
54 import java.io.IOException;
56 import java.nio.file.Files;
57 import java.nio.file.Path;
58 import java.nio.file.Paths;
59 import java.nio.file.StandardCopyOption;
60 import java.util.ArrayList;
61 import java.util.Arrays;
62 import java.util.Collection;
63 import java.util.Collections;
64 import java.util.Comparator;
65 import java.util.List;
67 import static org.mockito.Mockito.mock;
68 import static org.mockito.Mockito.when;
70 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
71 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
72 public class Maven2RepositoryMetadataResolverTest
75 private static final Filter<String> ALL = new AllFilter<String>();
78 @Named ( "repositoryStorage#maven2" )
79 private Maven2RepositoryStorage storage;
82 RepositoryRegistry repositoryRegistry;
84 private static final String TEST_REPO_ID = "test";
86 private static final String TEST_REMOTE_REPO_ID = "central";
88 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
90 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
92 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
94 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
96 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
98 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
100 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
102 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
105 @Named ( "archivaConfiguration#default" )
106 protected ArchivaConfiguration configuration;
108 private WagonFactory wagonFactory;
110 ManagedRepositoryConfiguration testRepo;
121 c = new Configuration();
124 testRepo = new ManagedRepositoryConfiguration();
125 testRepo.setId( TEST_REPO_ID );
126 testRepo.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toString() );
127 testRepo.setReleases( true );
128 testRepo.setSnapshots( true );
129 c.addManagedRepository( testRepo );
131 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
132 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
133 testRemoteRepo.setLayout( "default" );
134 testRemoteRepo.setName( "Central Repository" );
135 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
136 testRemoteRepo.setTimeout( 10 );
137 c.addRemoteRepository( testRemoteRepo );
139 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
140 proxyConnector.setSourceRepoId( TEST_REPO_ID );
141 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
142 proxyConnector.setDisabled( false );
143 c.addProxyConnector( proxyConnector );
145 RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
146 c.setRepositoryScanning(scCfg);
148 configuration.save( c );
149 assertFalse(configuration.isDefaulted());
150 repositoryRegistry.reload();
152 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
153 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
155 wagonFactory = mock( WagonFactory.class );
157 storage.setWagonFactory( wagonFactory );
159 Wagon wagon = new MockWagon();
160 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
164 public void testModelWithJdkProfileActivation()
167 ReadMetadataRequest readMetadataRequest =
168 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
169 "maven-archiver" ).projectVersion( "2.4.1" );
170 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
171 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
175 public void testGetProjectVersionMetadata()
178 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
179 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
180 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
181 assertEquals( "jar", facet.getPackaging() );
182 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
183 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
184 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
185 assertEquals( "1.2.1", facet.getParent().getVersion() );
186 assertEquals( "archiva-common", facet.getArtifactId() );
187 assertEquals( "org.apache.archiva", facet.getGroupId() );
188 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
189 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
190 assertNotNull( metadata.getDescription() );
191 // TODO: this would be better
193 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
194 // metadata.getDescription() );
195 assertEquals( "1.2.1", metadata.getId() );
196 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
197 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
198 checkApacheLicense( metadata );
199 assertEquals( "Archiva Base :: Common", metadata.getName() );
200 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
201 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
202 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
203 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
204 checkOrganizationApache( metadata );
206 assertEquals( 4, metadata.getMailingLists().size() );
207 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
208 "http://www.nabble.com/archiva-users-f16426.html" );
209 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
210 "http://www.nabble.com/archiva-dev-f16427.html" );
211 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
212 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
213 "http://www.nabble.com/Archiva---Issues-f29617.html" );
215 List<Dependency> dependencies = metadata.getDependencies();
216 assertEquals( 10, dependencies.size() );
217 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
218 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
219 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
220 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
221 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
222 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
223 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
224 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
225 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
226 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
228 assertEquals( 8, metadata.getProperties().size() );
229 assertEquals( "http://www.apache.org/images/asf_logo_wide.gif", metadata.getProperties().get("organization.logo") );
233 public void testGetArtifactMetadata()
236 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
237 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
238 List<ArtifactMetadata> artifacts = new ArrayList<>( springArtifacts );
239 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
242 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
244 return o1.getId().compareTo( o2.getId() );
248 assertEquals( 3, artifacts.size() );
250 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
251 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
252 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
253 assertEquals( 0, facet.getBuildNumber() );
254 assertNull( facet.getTimestamp() );
255 assertEquals( "sources", facet.getClassifier() );
256 assertEquals( "java-source", facet.getType() );
258 artifactMetadata = artifacts.get( 1 );
259 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
260 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
261 assertEquals( 0, facet.getBuildNumber() );
262 assertNull( facet.getTimestamp() );
263 assertNull( facet.getClassifier() );
264 assertEquals( "jar", facet.getType() );
266 artifactMetadata = artifacts.get( 2 );
267 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
268 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
269 assertEquals( 0, facet.getBuildNumber() );
270 assertNull( facet.getTimestamp() );
271 assertNull( facet.getClassifier() );
272 assertEquals( "pom", facet.getType() );
276 public void testGetArtifactMetadataSnapshots()
279 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
280 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
281 List<ArtifactMetadata> artifacts = new ArrayList<>( testArtifacts );
282 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
285 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
287 return o1.getId().compareTo( o2.getId() );
291 assertEquals( 6, artifacts.size() );
293 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
294 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
295 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
296 assertEquals( 1, facet.getBuildNumber() );
297 assertEquals( "20100308.230825", facet.getTimestamp() );
298 assertNull( facet.getClassifier() );
299 assertEquals( "jar", facet.getType() );
301 artifactMetadata = artifacts.get( 1 );
302 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
303 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
304 assertEquals( 1, facet.getBuildNumber() );
305 assertEquals( "20100308.230825", facet.getTimestamp() );
306 assertNull( facet.getClassifier() );
307 assertEquals( "pom", facet.getType() );
309 artifactMetadata = artifacts.get( 2 );
310 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
311 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
312 assertEquals( 2, facet.getBuildNumber() );
313 assertEquals( "20100310.014828", facet.getTimestamp() );
314 assertEquals( "javadoc", facet.getClassifier() );
315 assertEquals( "javadoc", facet.getType() );
317 artifactMetadata = artifacts.get( 3 );
318 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
319 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
320 assertEquals( 2, facet.getBuildNumber() );
321 assertEquals( "20100310.014828", facet.getTimestamp() );
322 assertEquals( "sources", facet.getClassifier() );
323 assertEquals( "java-source", facet.getType() );
325 artifactMetadata = artifacts.get( 4 );
326 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
327 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
328 assertEquals( 2, facet.getBuildNumber() );
329 assertEquals( "20100310.014828", facet.getTimestamp() );
330 assertNull( facet.getClassifier() );
331 assertEquals( "jar", facet.getType() );
333 artifactMetadata = artifacts.get( 5 );
334 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
335 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
336 assertEquals( 2, facet.getBuildNumber() );
337 assertEquals( "20100310.014828", facet.getTimestamp() );
338 assertNull( facet.getClassifier() );
339 assertEquals( "pom", facet.getType() );
343 public void testGetArtifactMetadataSnapshotsMRM1859()
346 Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
347 URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
348 Path resFile = Paths.get(url.toURI());
349 Path destFile = repoDir.resolve(resFile.getFileName());
350 Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
351 URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
352 Path resFile2 = Paths.get(url2.toURI());
353 Path destFile2 = repoDir.resolve(resFile2.getFileName());
354 Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
359 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
360 new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
361 List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
362 Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
364 public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
365 return o1.getId().compareTo(o2.getId());
369 assertEquals(6, artifacts.size());
371 ArtifactMetadata artifactMetadata = artifacts.get(0);
372 assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
373 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
374 assertEquals(1, facet.getBuildNumber());
375 assertEquals("20100308.230825", facet.getTimestamp());
376 assertNull(facet.getClassifier());
377 assertEquals("jar", facet.getType());
379 artifactMetadata = artifacts.get(1);
380 assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
381 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
382 assertEquals(1, facet.getBuildNumber());
383 assertEquals("20100308.230825", facet.getTimestamp());
384 assertNull(facet.getClassifier());
385 assertEquals("pom", facet.getType());
387 artifactMetadata = artifacts.get(2);
388 assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
389 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
390 assertEquals(2, facet.getBuildNumber());
391 assertEquals("20100310.014828", facet.getTimestamp());
392 assertEquals("javadoc", facet.getClassifier());
393 assertEquals("javadoc", facet.getType());
395 artifactMetadata = artifacts.get(3);
396 assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
397 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
398 assertEquals(2, facet.getBuildNumber());
399 assertEquals("20100310.014828", facet.getTimestamp());
400 assertEquals("sources", facet.getClassifier());
401 assertEquals("java-source", facet.getType());
403 artifactMetadata = artifacts.get(4);
404 assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
405 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
406 assertEquals(2, facet.getBuildNumber());
407 assertEquals("20100310.014828", facet.getTimestamp());
408 assertNull(facet.getClassifier());
409 assertEquals("jar", facet.getType());
411 artifactMetadata = artifacts.get(5);
412 assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
413 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
414 assertEquals(2, facet.getBuildNumber());
415 assertEquals("20100310.014828", facet.getTimestamp());
416 assertNull(facet.getClassifier());
417 assertEquals("pom", facet.getType());
420 Files.delete(destFile);
421 Files.delete(destFile2);
426 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
428 assertDependency( dependency, groupId, artifactId, version, "compile" );
431 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
434 assertEquals( artifactId, dependency.getArtifactId() );
435 assertEquals( "jar", dependency.getType() );
436 assertEquals( version, dependency.getVersion() );
437 assertEquals( groupId, dependency.getNamespace() );
438 assertEquals( scope, dependency.getScope() );
439 assertNull( dependency.getClassifier() );
440 assertNull( dependency.getSystemPath() );
444 public void testGetProjectVersionMetadataForTimestampedSnapshot()
447 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
448 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
449 MavenProjectFacet facet = MavenProjectFacet.class.cast( metadata.getFacet( MavenProjectFacet.FACET_ID ) );
450 assertEquals( "pom", facet.getPackaging() );
451 assertEquals( "http://www.apache.org/", metadata.getUrl() );
452 assertNull( facet.getParent() );
453 assertEquals( "org.apache", facet.getGroupId() );
454 assertEquals( "apache", facet.getArtifactId() );
455 assertNull( metadata.getCiManagement() );
456 assertNotNull( metadata.getDescription() );
457 // TODO: this would be better
459 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
460 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
461 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
462 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
463 // "developers and users.", metadata.getDescription() );
464 assertEquals( "5-SNAPSHOT", metadata.getId() );
465 assertNull( metadata.getIssueManagement() );
466 checkApacheLicense( metadata );
467 assertEquals( "The Apache Software Foundation", metadata.getName() );
468 String path = "maven/pom/trunk/asf";
469 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
470 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
471 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
472 checkOrganizationApache( metadata );
473 assertEquals( 1, metadata.getMailingLists().size() );
474 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
475 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
476 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
477 Collections.<String>emptyList(), true );
478 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
482 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
487 storage.readProjectVersionMetadata(
488 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
489 fail( "Should not be found" );
491 catch ( RepositoryStorageMetadataNotFoundException e )
493 assertEquals( "missing-pom", e.getId() );
498 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
503 storage.readProjectVersionMetadata(
504 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
505 fail( "Should not be found" );
507 catch ( RepositoryStorageMetadataNotFoundException e )
509 assertEquals( "missing-pom", e.getId() );
514 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
519 storage.readProjectVersionMetadata(
520 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
521 fail( "Should not be found" );
523 catch ( RepositoryStorageMetadataNotFoundException e )
525 assertEquals( "missing-pom", e.getId() );
530 public void testGetProjectVersionMetadataForInvalidPom()
535 storage.readProjectVersionMetadata(
536 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
537 fail( "Should have received an exception due to invalid POM" );
539 catch ( RepositoryStorageMetadataInvalidException e )
541 assertEquals( "invalid-pom", e.getId() );
546 public void testGetProjectVersionMetadataForMislocatedPom()
551 storage.readProjectVersionMetadata(
552 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
553 fail( "Should have received an exception due to mislocated POM" );
555 catch ( RepositoryStorageMetadataInvalidException e )
557 assertEquals( "mislocated-pom", e.getId() );
562 public void testGetProjectVersionMetadataForMissingPom()
567 storage.readProjectVersionMetadata(
568 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
569 fail( "Should not be found" );
571 catch ( RepositoryStorageMetadataNotFoundException e )
573 assertEquals( "missing-pom", e.getId() );
578 public void testGetRootNamespaces()
581 assertEquals( Arrays.asList( "com", "org"), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
585 public void testGetNamespaces()
588 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
589 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
590 assertEquals( Collections.<String>emptyList(),
591 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
593 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
594 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
595 assertEquals( Collections.<String>emptyList(),
596 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
597 assertEquals( Arrays.asList( "plugins", "shared" ),
598 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
599 assertEquals( Collections.<String>emptyList(),
600 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
601 assertEquals( Collections.<String>emptyList(),
602 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
604 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
605 assertEquals( Collections.<String>emptyList(),
606 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
610 public void testGetProjects()
613 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
614 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
615 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
616 "missing-metadata", "missing-parent", "test-artifact" ),
617 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
619 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
620 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
621 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
622 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
623 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
624 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
625 assertEquals( Collections.<String>emptyList(),
626 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
627 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
628 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
632 public void testGetProjectVersions()
635 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
636 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
637 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
638 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
639 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
640 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
641 assertEquals( Arrays.asList( "1.0" ),
642 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
644 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
645 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
647 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
648 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
649 assertEquals( Arrays.asList( "1.2.1" ),
650 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
651 assertEquals( Arrays.asList( "1.2.1" ),
652 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
653 assertEquals( Arrays.asList( "1.2.1" ),
654 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
655 assertEquals( Arrays.asList( "3" ),
656 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
658 assertEquals( Collections.<String>emptyList(),
659 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
663 public void testGetArtifacts()
666 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
667 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
668 assertEquals( 3, artifacts.size() );
669 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
672 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
674 return o1.getId().compareTo( o2.getId() );
678 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
679 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
680 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
681 "f83aa25f016212a551a4b2249985effc" );
685 public void testGetArtifactsFiltered()
688 ExcludesFilter<String> filter =
689 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
690 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
691 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
692 assertEquals( 2, artifacts.size() );
693 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
696 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
698 return o1.getId().compareTo( o2.getId() );
702 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
703 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
707 public void testGetArtifactsTimestampedSnapshots()
710 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
711 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
712 assertEquals( 1, artifacts.size() );
714 ArtifactMetadata artifact = artifacts.get( 0 );
715 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
716 assertEquals( "com.example.test", artifact.getNamespace() );
717 assertEquals( "missing-metadata", artifact.getProject() );
718 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
719 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
722 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
724 assertEquals( id, artifact.getId() );
725 assertEquals( md5, artifact.getMd5() );
726 assertEquals( sha1, artifact.getSha1() );
727 assertEquals( size, artifact.getSize() );
728 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
729 assertEquals( "plexus-spring", artifact.getProject() );
730 assertEquals( "1.2", artifact.getVersion() );
731 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
734 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
735 String unsubscribe, List<String> otherArchives, boolean allowPost )
737 assertEquals( archive, mailingList.getMainArchiveUrl() );
740 assertEquals( post, mailingList.getPostAddress() );
744 assertNull( mailingList.getPostAddress() );
746 assertEquals( subscribe, mailingList.getSubscribeAddress() );
747 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
748 assertEquals( name, mailingList.getName() );
749 assertEquals( otherArchives, mailingList.getOtherArchives() );
752 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
755 List<String> otherArchives = new ArrayList<>();
756 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
757 if ( nabbleUrl != null )
759 otherArchives.add( nabbleUrl );
761 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
762 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
763 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
764 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
767 private void checkApacheLicense( ProjectVersionMetadata metadata )
769 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
770 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
771 metadata.getLicenses() );
774 private void checkOrganizationApache( ProjectVersionMetadata metadata )
776 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
777 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
780 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
783 for ( String path : pathsToBeDeleted )
785 Path dir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
786 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
788 assertFalse( Files.exists(dir) );
790 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
792 Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
793 Path rootPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
795 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dest );
796 org.apache.archiva.common.utils.FileUtils.deleteDirectory( parentPom );
797 org.apache.archiva.common.utils.FileUtils.deleteDirectory( rootPom );
799 assertFalse( Files.exists(dest) );
800 assertFalse( Files.exists(parentPom) );
801 assertFalse( Files.exists(rootPom) );
804 private Path copyTestArtifactWithParent( String srcPath, String destPath )
807 Path src = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath );
808 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath );
810 FileUtils.copyDirectory( src.toFile(), dest.toFile() );
811 assertTrue( Files.exists(dest) );