1 package org.apache.archiva.repository.maven.metadata.storage;
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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.TestCase;
22 import org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.Configuration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
26 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
27 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
28 import org.apache.archiva.filter.AllFilter;
29 import org.apache.archiva.filter.ExcludesFilter;
30 import org.apache.archiva.filter.Filter;
31 import org.apache.archiva.maven.metadata.model.MavenArtifactFacet;
32 import org.apache.archiva.metadata.model.ArtifactMetadata;
33 import org.apache.archiva.metadata.model.Dependency;
34 import org.apache.archiva.metadata.model.License;
35 import org.apache.archiva.metadata.model.MailingList;
36 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
37 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
38 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
39 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
40 import org.apache.archiva.maven.proxy.WagonFactory;
41 import org.apache.archiva.maven.proxy.WagonFactoryRequest;
42 import org.apache.archiva.repository.RepositoryRegistry;
43 import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
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 @SuppressWarnings( "unused" )
86 RepositoryHandlerDependencies repositoryHandlerDependencies;
89 private static final String TEST_REPO_ID = "test";
91 private static final String TEST_REMOTE_REPO_ID = "central";
93 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
95 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
97 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
99 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
101 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
103 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
105 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
107 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
110 @Named ( "archivaConfiguration#default" )
111 protected ArchivaConfiguration configuration;
113 private WagonFactory wagonFactory;
115 ManagedRepositoryConfiguration testRepo;
126 c = new Configuration();
129 testRepo = new ManagedRepositoryConfiguration();
130 testRepo.setId( TEST_REPO_ID );
131 testRepo.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toString() );
132 testRepo.setReleases( true );
133 testRepo.setSnapshots( true );
134 c.addManagedRepository( testRepo );
136 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
137 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
138 testRemoteRepo.setLayout( "default" );
139 testRemoteRepo.setName( "Central Repository" );
140 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
141 testRemoteRepo.setTimeout( 10 );
142 c.addRemoteRepository( testRemoteRepo );
144 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
145 proxyConnector.setSourceRepoId( TEST_REPO_ID );
146 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
147 proxyConnector.setDisabled( false );
148 c.addProxyConnector( proxyConnector );
150 RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
151 c.setRepositoryScanning(scCfg);
153 configuration.save( c );
154 assertFalse(configuration.isDefaulted());
155 repositoryRegistry.reload();
157 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
158 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
160 wagonFactory = mock( WagonFactory.class );
162 storage.setWagonFactory( wagonFactory );
164 Wagon wagon = new MockWagon();
165 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
169 public void testModelWithJdkProfileActivation()
172 ReadMetadataRequest readMetadataRequest =
173 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
174 "maven-archiver" ).projectVersion( "2.4.1" );
175 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
176 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
180 public void testGetProjectVersionMetadata()
183 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
184 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
185 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
186 assertEquals( "jar", facet.getPackaging() );
187 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
188 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
189 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
190 assertEquals( "1.2.1", facet.getParent().getVersion() );
191 assertEquals( "archiva-common", facet.getArtifactId() );
192 assertEquals( "org.apache.archiva", facet.getGroupId() );
193 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
194 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
195 assertNotNull( metadata.getDescription() );
196 // TODO: this would be better
198 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
199 // metadata.getDescription() );
200 assertEquals( "1.2.1", metadata.getId() );
201 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
202 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
203 checkApacheLicense( metadata );
204 assertEquals( "Archiva Base :: Common", metadata.getName() );
205 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
206 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
207 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
208 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
209 checkOrganizationApache( metadata );
211 assertEquals( 4, metadata.getMailingLists().size() );
212 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
213 "http://www.nabble.com/archiva-users-f16426.html" );
214 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
215 "http://www.nabble.com/archiva-dev-f16427.html" );
216 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
217 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
218 "http://www.nabble.com/Archiva---Issues-f29617.html" );
220 List<Dependency> dependencies = metadata.getDependencies();
221 assertEquals( 10, dependencies.size() );
222 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
223 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
224 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
225 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
226 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
227 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
228 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
229 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
230 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
231 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
233 assertEquals( 8, metadata.getProperties().size() );
234 assertEquals( "http://www.apache.org/images/asf_logo_wide.gif", metadata.getProperties().get("organization.logo") );
238 public void testGetArtifactMetadata()
241 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
242 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
243 List<ArtifactMetadata> artifacts = new ArrayList<>( springArtifacts );
244 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
247 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
249 return o1.getId().compareTo( o2.getId() );
253 assertEquals( 3, artifacts.size() );
255 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
256 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
257 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
258 assertEquals( 0, facet.getBuildNumber() );
259 assertNull( facet.getTimestamp() );
260 assertEquals( "sources", facet.getClassifier() );
261 assertEquals( "java-source", facet.getType() );
263 artifactMetadata = artifacts.get( 1 );
264 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
265 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
266 assertEquals( 0, facet.getBuildNumber() );
267 assertNull( facet.getTimestamp() );
268 assertNull( facet.getClassifier() );
269 assertEquals( "jar", facet.getType() );
271 artifactMetadata = artifacts.get( 2 );
272 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
273 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
274 assertEquals( 0, facet.getBuildNumber() );
275 assertNull( facet.getTimestamp() );
276 assertNull( facet.getClassifier() );
277 assertEquals( "pom", facet.getType() );
281 public void testGetArtifactMetadataSnapshots()
284 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
285 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
286 List<ArtifactMetadata> artifacts = new ArrayList<>( testArtifacts );
287 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
290 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
292 return o1.getId().compareTo( o2.getId() );
296 assertEquals( 6, artifacts.size() );
298 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
299 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
300 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
301 assertEquals( 1, facet.getBuildNumber() );
302 assertEquals( "20100308.230825", facet.getTimestamp() );
303 assertNull( facet.getClassifier() );
304 assertEquals( "jar", facet.getType() );
306 artifactMetadata = artifacts.get( 1 );
307 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
308 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
309 assertEquals( 1, facet.getBuildNumber() );
310 assertEquals( "20100308.230825", facet.getTimestamp() );
311 assertNull( facet.getClassifier() );
312 assertEquals( "pom", facet.getType() );
314 artifactMetadata = artifacts.get( 2 );
315 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
316 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
317 assertEquals( 2, facet.getBuildNumber() );
318 assertEquals( "20100310.014828", facet.getTimestamp() );
319 assertEquals( "javadoc", facet.getClassifier() );
320 assertEquals( "javadoc", facet.getType() );
322 artifactMetadata = artifacts.get( 3 );
323 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
324 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
325 assertEquals( 2, facet.getBuildNumber() );
326 assertEquals( "20100310.014828", facet.getTimestamp() );
327 assertEquals( "sources", facet.getClassifier() );
328 assertEquals( "java-source", facet.getType() );
330 artifactMetadata = artifacts.get( 4 );
331 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
332 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
333 assertEquals( 2, facet.getBuildNumber() );
334 assertEquals( "20100310.014828", facet.getTimestamp() );
335 assertNull( facet.getClassifier() );
336 assertEquals( "jar", facet.getType() );
338 artifactMetadata = artifacts.get( 5 );
339 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
340 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
341 assertEquals( 2, facet.getBuildNumber() );
342 assertEquals( "20100310.014828", facet.getTimestamp() );
343 assertNull( facet.getClassifier() );
344 assertEquals( "pom", facet.getType() );
348 public void testGetArtifactMetadataSnapshotsMRM1859()
351 Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
352 URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
353 Path resFile = Paths.get(url.toURI());
354 Path destFile = repoDir.resolve(resFile.getFileName());
355 Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
356 URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
357 Path resFile2 = Paths.get(url2.toURI());
358 Path destFile2 = repoDir.resolve(resFile2.getFileName());
359 Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
364 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
365 new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
366 List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
367 Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
369 public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
370 return o1.getId().compareTo(o2.getId());
374 assertEquals(6, artifacts.size());
376 ArtifactMetadata artifactMetadata = artifacts.get(0);
377 assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
378 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
379 assertEquals(1, facet.getBuildNumber());
380 assertEquals("20100308.230825", facet.getTimestamp());
381 assertNull(facet.getClassifier());
382 assertEquals("jar", facet.getType());
384 artifactMetadata = artifacts.get(1);
385 assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
386 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
387 assertEquals(1, facet.getBuildNumber());
388 assertEquals("20100308.230825", facet.getTimestamp());
389 assertNull(facet.getClassifier());
390 assertEquals("pom", facet.getType());
392 artifactMetadata = artifacts.get(2);
393 assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
394 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
395 assertEquals(2, facet.getBuildNumber());
396 assertEquals("20100310.014828", facet.getTimestamp());
397 assertEquals("javadoc", facet.getClassifier());
398 assertEquals("javadoc", facet.getType());
400 artifactMetadata = artifacts.get(3);
401 assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
402 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
403 assertEquals(2, facet.getBuildNumber());
404 assertEquals("20100310.014828", facet.getTimestamp());
405 assertEquals("sources", facet.getClassifier());
406 assertEquals("java-source", facet.getType());
408 artifactMetadata = artifacts.get(4);
409 assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
410 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
411 assertEquals(2, facet.getBuildNumber());
412 assertEquals("20100310.014828", facet.getTimestamp());
413 assertNull(facet.getClassifier());
414 assertEquals("jar", facet.getType());
416 artifactMetadata = artifacts.get(5);
417 assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
418 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
419 assertEquals(2, facet.getBuildNumber());
420 assertEquals("20100310.014828", facet.getTimestamp());
421 assertNull(facet.getClassifier());
422 assertEquals("pom", facet.getType());
425 Files.delete(destFile);
426 Files.delete(destFile2);
431 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
433 assertDependency( dependency, groupId, artifactId, version, "compile" );
436 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
439 assertEquals( artifactId, dependency.getArtifactId() );
440 assertEquals( "jar", dependency.getType() );
441 assertEquals( version, dependency.getVersion() );
442 assertEquals( groupId, dependency.getNamespace() );
443 assertEquals( scope, dependency.getScope() );
444 assertNull( dependency.getClassifier() );
445 assertNull( dependency.getSystemPath() );
449 public void testGetProjectVersionMetadataForTimestampedSnapshot()
452 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
453 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
454 MavenProjectFacet facet = MavenProjectFacet.class.cast( metadata.getFacet( MavenProjectFacet.FACET_ID ) );
455 assertEquals( "pom", facet.getPackaging() );
456 assertEquals( "http://www.apache.org/", metadata.getUrl() );
457 assertNull( facet.getParent() );
458 assertEquals( "org.apache", facet.getGroupId() );
459 assertEquals( "apache", facet.getArtifactId() );
460 assertNull( metadata.getCiManagement() );
461 assertNotNull( metadata.getDescription() );
462 // TODO: this would be better
464 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
465 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
466 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
467 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
468 // "developers and users.", metadata.getDescription() );
469 assertEquals( "5-SNAPSHOT", metadata.getId() );
470 assertNull( metadata.getIssueManagement() );
471 checkApacheLicense( metadata );
472 assertEquals( "The Apache Software Foundation", metadata.getName() );
473 String path = "maven/pom/trunk/asf";
474 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
475 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
476 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
477 checkOrganizationApache( metadata );
478 assertEquals( 1, metadata.getMailingLists().size() );
479 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
480 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
481 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
482 Collections.<String>emptyList(), true );
483 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
487 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
492 storage.readProjectVersionMetadata(
493 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
494 fail( "Should not be found" );
496 catch ( RepositoryStorageMetadataNotFoundException e )
498 assertEquals( "missing-pom", e.getId() );
503 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
508 storage.readProjectVersionMetadata(
509 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
510 fail( "Should not be found" );
512 catch ( RepositoryStorageMetadataNotFoundException e )
514 assertEquals( "missing-pom", e.getId() );
519 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
524 storage.readProjectVersionMetadata(
525 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
526 fail( "Should not be found" );
528 catch ( RepositoryStorageMetadataNotFoundException e )
530 assertEquals( "missing-pom", e.getId() );
535 public void testGetProjectVersionMetadataForInvalidPom()
540 storage.readProjectVersionMetadata(
541 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
542 fail( "Should have received an exception due to invalid POM" );
544 catch ( RepositoryStorageMetadataInvalidException e )
546 assertEquals( "invalid-pom", e.getId() );
551 public void testGetProjectVersionMetadataForMislocatedPom()
556 storage.readProjectVersionMetadata(
557 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
558 fail( "Should have received an exception due to mislocated POM" );
560 catch ( RepositoryStorageMetadataInvalidException e )
562 assertEquals( "mislocated-pom", e.getId() );
567 public void testGetProjectVersionMetadataForMissingPom()
572 storage.readProjectVersionMetadata(
573 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
574 fail( "Should not be found" );
576 catch ( RepositoryStorageMetadataNotFoundException e )
578 assertEquals( "missing-pom", e.getId() );
583 public void testGetRootNamespaces()
586 assertEquals( Arrays.asList( "com", "org"), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
590 public void testGetNamespaces()
593 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
594 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
595 assertEquals( Collections.<String>emptyList(),
596 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
598 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
599 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
600 assertEquals( Collections.<String>emptyList(),
601 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
602 assertEquals( Arrays.asList( "plugins", "shared" ),
603 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
604 assertEquals( Collections.<String>emptyList(),
605 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
606 assertEquals( Collections.<String>emptyList(),
607 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
609 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
610 assertEquals( Collections.<String>emptyList(),
611 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
615 public void testGetProjects()
618 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
619 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
620 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
621 "missing-metadata", "missing-parent", "test-artifact" ),
622 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
624 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
625 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
626 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
627 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
628 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
629 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
630 assertEquals( Collections.<String>emptyList(),
631 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
632 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
633 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
637 public void testGetProjectVersions()
640 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
641 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
642 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
643 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
644 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
645 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
646 assertEquals( Arrays.asList( "1.0" ),
647 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
649 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
650 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
652 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
653 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
654 assertEquals( Arrays.asList( "1.2.1" ),
655 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
656 assertEquals( Arrays.asList( "1.2.1" ),
657 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
658 assertEquals( Arrays.asList( "1.2.1" ),
659 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
660 assertEquals( Arrays.asList( "3" ),
661 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
663 assertEquals( Collections.<String>emptyList(),
664 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
668 public void testGetArtifacts()
671 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
672 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
673 assertEquals( 3, artifacts.size() );
674 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
677 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
679 return o1.getId().compareTo( o2.getId() );
683 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
684 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
685 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
686 "f83aa25f016212a551a4b2249985effc" );
690 public void testGetArtifactsFiltered()
693 ExcludesFilter<String> filter =
694 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
695 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
696 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
697 assertEquals( 2, artifacts.size() );
698 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
701 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
703 return o1.getId().compareTo( o2.getId() );
707 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
708 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
712 public void testGetArtifactsTimestampedSnapshots()
715 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
716 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
717 assertEquals( 1, artifacts.size() );
719 ArtifactMetadata artifact = artifacts.get( 0 );
720 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
721 assertEquals( "com.example.test", artifact.getNamespace() );
722 assertEquals( "missing-metadata", artifact.getProject() );
723 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
724 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
727 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
729 assertEquals( id, artifact.getId() );
730 assertEquals( md5, artifact.getMd5() );
731 assertEquals( sha1, artifact.getSha1() );
732 assertEquals( size, artifact.getSize() );
733 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
734 assertEquals( "plexus-spring", artifact.getProject() );
735 assertEquals( "1.2", artifact.getVersion() );
736 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
739 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
740 String unsubscribe, List<String> otherArchives, boolean allowPost )
742 assertEquals( archive, mailingList.getMainArchiveUrl() );
745 assertEquals( post, mailingList.getPostAddress() );
749 assertNull( mailingList.getPostAddress() );
751 assertEquals( subscribe, mailingList.getSubscribeAddress() );
752 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
753 assertEquals( name, mailingList.getName() );
754 assertEquals( otherArchives, mailingList.getOtherArchives() );
757 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
760 List<String> otherArchives = new ArrayList<>();
761 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
762 if ( nabbleUrl != null )
764 otherArchives.add( nabbleUrl );
766 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
767 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
768 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
769 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
772 private void checkApacheLicense( ProjectVersionMetadata metadata )
774 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
775 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
776 metadata.getLicenses() );
779 private void checkOrganizationApache( ProjectVersionMetadata metadata )
781 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
782 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
785 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
788 for ( String path : pathsToBeDeleted )
790 Path dir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
791 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
793 assertFalse( Files.exists(dir) );
795 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
797 Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
798 Path rootPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
800 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dest );
801 org.apache.archiva.common.utils.FileUtils.deleteDirectory( parentPom );
802 org.apache.archiva.common.utils.FileUtils.deleteDirectory( rootPom );
804 assertFalse( Files.exists(dest) );
805 assertFalse( Files.exists(parentPom) );
806 assertFalse( Files.exists(rootPom) );
809 private Path copyTestArtifactWithParent( String srcPath, String destPath )
812 Path src = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath );
813 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath );
815 FileUtils.copyDirectory( src.toFile(), dest.toFile() );
816 assertTrue( Files.exists(dest) );