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.metadata.model.ArtifactMetadata;
29 import org.apache.archiva.metadata.model.Dependency;
30 import org.apache.archiva.metadata.model.License;
31 import org.apache.archiva.metadata.model.MailingList;
32 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
33 import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
34 import org.apache.archiva.filter.AllFilter;
35 import org.apache.archiva.filter.ExcludesFilter;
36 import org.apache.archiva.filter.Filter;
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.proxy.maven.WagonFactory;
41 import org.apache.archiva.proxy.maven.WagonFactoryRequest;
42 import org.apache.archiva.repository.RepositoryRegistry;
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;
53 import java.io.IOException;
55 import java.nio.file.Files;
56 import java.nio.file.Path;
57 import java.nio.file.Paths;
58 import java.nio.file.StandardCopyOption;
59 import java.util.ArrayList;
60 import java.util.Arrays;
61 import java.util.Collection;
62 import java.util.Collections;
63 import java.util.Comparator;
64 import java.util.List;
66 import static org.mockito.Mockito.mock;
67 import static org.mockito.Mockito.when;
69 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
70 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
71 public class Maven2RepositoryMetadataResolverTest
74 private static final Filter<String> ALL = new AllFilter<String>();
77 @Named ( "repositoryStorage#maven2" )
78 private Maven2RepositoryStorage storage;
81 RepositoryRegistry repositoryRegistry;
83 private static final String TEST_REPO_ID = "test";
85 private static final String TEST_REMOTE_REPO_ID = "central";
87 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
89 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
91 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
93 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
95 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
97 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
99 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
101 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
104 @Named ( "archivaConfiguration#default" )
105 protected ArchivaConfiguration configuration;
107 private WagonFactory wagonFactory;
109 ManagedRepositoryConfiguration testRepo;
120 c = new Configuration();
123 testRepo = new ManagedRepositoryConfiguration();
124 testRepo.setId( TEST_REPO_ID );
125 testRepo.setLocation( Paths.get( "target/test-repository" ).toAbsolutePath().toString() );
126 testRepo.setReleases( true );
127 testRepo.setSnapshots( true );
128 c.addManagedRepository( testRepo );
130 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
131 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
132 testRemoteRepo.setLayout( "default" );
133 testRemoteRepo.setName( "Central Repository" );
134 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
135 testRemoteRepo.setTimeout( 10 );
136 c.addRemoteRepository( testRemoteRepo );
138 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
139 proxyConnector.setSourceRepoId( TEST_REPO_ID );
140 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
141 proxyConnector.setDisabled( false );
142 c.addProxyConnector( proxyConnector );
144 RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
145 c.setRepositoryScanning(scCfg);
147 configuration.save( c );
148 assertFalse(configuration.isDefaulted());
149 repositoryRegistry.reload();
151 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
152 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
154 wagonFactory = mock( WagonFactory.class );
156 storage.setWagonFactory( wagonFactory );
158 Wagon wagon = new MockWagon();
159 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
163 public void testModelWithJdkProfileActivation()
166 ReadMetadataRequest readMetadataRequest =
167 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
168 "maven-archiver" ).projectVersion( "2.4.1" );
169 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
170 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
174 public void testGetProjectVersionMetadata()
177 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
178 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
179 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
180 assertEquals( "jar", facet.getPackaging() );
181 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
182 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
183 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
184 assertEquals( "1.2.1", facet.getParent().getVersion() );
185 assertEquals( "archiva-common", facet.getArtifactId() );
186 assertEquals( "org.apache.archiva", facet.getGroupId() );
187 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
188 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
189 assertNotNull( metadata.getDescription() );
190 // TODO: this would be better
192 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
193 // metadata.getDescription() );
194 assertEquals( "1.2.1", metadata.getId() );
195 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
196 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
197 checkApacheLicense( metadata );
198 assertEquals( "Archiva Base :: Common", metadata.getName() );
199 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
200 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
201 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
202 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
203 checkOrganizationApache( metadata );
205 assertEquals( 4, metadata.getMailingLists().size() );
206 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
207 "http://www.nabble.com/archiva-users-f16426.html" );
208 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
209 "http://www.nabble.com/archiva-dev-f16427.html" );
210 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
211 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
212 "http://www.nabble.com/Archiva---Issues-f29617.html" );
214 List<Dependency> dependencies = metadata.getDependencies();
215 assertEquals( 10, dependencies.size() );
216 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
217 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
218 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
219 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
220 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
221 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
222 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
223 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
224 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
225 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
227 assertEquals( 8, metadata.getProperties().size() );
228 assertEquals( "http://www.apache.org/images/asf_logo_wide.gif", metadata.getProperties().get("organization.logo") );
232 public void testGetArtifactMetadata()
235 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
236 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
237 List<ArtifactMetadata> artifacts = new ArrayList<>( springArtifacts );
238 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
241 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
243 return o1.getId().compareTo( o2.getId() );
247 assertEquals( 3, artifacts.size() );
249 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
250 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
251 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
252 assertEquals( 0, facet.getBuildNumber() );
253 assertNull( facet.getTimestamp() );
254 assertEquals( "sources", facet.getClassifier() );
255 assertEquals( "java-source", facet.getType() );
257 artifactMetadata = artifacts.get( 1 );
258 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
259 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
260 assertEquals( 0, facet.getBuildNumber() );
261 assertNull( facet.getTimestamp() );
262 assertNull( facet.getClassifier() );
263 assertEquals( "jar", facet.getType() );
265 artifactMetadata = artifacts.get( 2 );
266 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
267 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
268 assertEquals( 0, facet.getBuildNumber() );
269 assertNull( facet.getTimestamp() );
270 assertNull( facet.getClassifier() );
271 assertEquals( "pom", facet.getType() );
275 public void testGetArtifactMetadataSnapshots()
278 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
279 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
280 List<ArtifactMetadata> artifacts = new ArrayList<>( testArtifacts );
281 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
284 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
286 return o1.getId().compareTo( o2.getId() );
290 assertEquals( 6, artifacts.size() );
292 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
293 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
294 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
295 assertEquals( 1, facet.getBuildNumber() );
296 assertEquals( "20100308.230825", facet.getTimestamp() );
297 assertNull( facet.getClassifier() );
298 assertEquals( "jar", facet.getType() );
300 artifactMetadata = artifacts.get( 1 );
301 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
302 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
303 assertEquals( 1, facet.getBuildNumber() );
304 assertEquals( "20100308.230825", facet.getTimestamp() );
305 assertNull( facet.getClassifier() );
306 assertEquals( "pom", facet.getType() );
308 artifactMetadata = artifacts.get( 2 );
309 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
310 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
311 assertEquals( 2, facet.getBuildNumber() );
312 assertEquals( "20100310.014828", facet.getTimestamp() );
313 assertEquals( "javadoc", facet.getClassifier() );
314 assertEquals( "javadoc", facet.getType() );
316 artifactMetadata = artifacts.get( 3 );
317 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
318 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
319 assertEquals( 2, facet.getBuildNumber() );
320 assertEquals( "20100310.014828", facet.getTimestamp() );
321 assertEquals( "sources", facet.getClassifier() );
322 assertEquals( "java-source", facet.getType() );
324 artifactMetadata = artifacts.get( 4 );
325 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
326 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
327 assertEquals( 2, facet.getBuildNumber() );
328 assertEquals( "20100310.014828", facet.getTimestamp() );
329 assertNull( facet.getClassifier() );
330 assertEquals( "jar", facet.getType() );
332 artifactMetadata = artifacts.get( 5 );
333 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
334 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
335 assertEquals( 2, facet.getBuildNumber() );
336 assertEquals( "20100310.014828", facet.getTimestamp() );
337 assertNull( facet.getClassifier() );
338 assertEquals( "pom", facet.getType() );
342 public void testGetArtifactMetadataSnapshotsMRM1859()
345 Path repoDir = Paths.get("target/test-repository/com/example/test/test-artifact/1.0-SNAPSHOT");
346 URL url = Thread.currentThread().getContextClassLoader().getResource("resolver-status.properties");
347 Path resFile = Paths.get(url.toURI());
348 Path destFile = repoDir.resolve(resFile.getFileName());
349 Files.copy(resFile, destFile, StandardCopyOption.REPLACE_EXISTING);
350 URL url2 = Thread.currentThread().getContextClassLoader().getResource("test01.properties");
351 Path resFile2 = Paths.get(url2.toURI());
352 Path destFile2 = repoDir.resolve(resFile2.getFileName());
353 Files.copy(resFile2, destFile2, StandardCopyOption.REPLACE_EXISTING);
358 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
359 new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
360 List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
361 Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
363 public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
364 return o1.getId().compareTo(o2.getId());
368 assertEquals(6, artifacts.size());
370 ArtifactMetadata artifactMetadata = artifacts.get(0);
371 assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
372 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
373 assertEquals(1, facet.getBuildNumber());
374 assertEquals("20100308.230825", facet.getTimestamp());
375 assertNull(facet.getClassifier());
376 assertEquals("jar", facet.getType());
378 artifactMetadata = artifacts.get(1);
379 assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
380 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
381 assertEquals(1, facet.getBuildNumber());
382 assertEquals("20100308.230825", facet.getTimestamp());
383 assertNull(facet.getClassifier());
384 assertEquals("pom", facet.getType());
386 artifactMetadata = artifacts.get(2);
387 assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
388 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
389 assertEquals(2, facet.getBuildNumber());
390 assertEquals("20100310.014828", facet.getTimestamp());
391 assertEquals("javadoc", facet.getClassifier());
392 assertEquals("javadoc", facet.getType());
394 artifactMetadata = artifacts.get(3);
395 assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
396 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
397 assertEquals(2, facet.getBuildNumber());
398 assertEquals("20100310.014828", facet.getTimestamp());
399 assertEquals("sources", facet.getClassifier());
400 assertEquals("java-source", facet.getType());
402 artifactMetadata = artifacts.get(4);
403 assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
404 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
405 assertEquals(2, facet.getBuildNumber());
406 assertEquals("20100310.014828", facet.getTimestamp());
407 assertNull(facet.getClassifier());
408 assertEquals("jar", facet.getType());
410 artifactMetadata = artifacts.get(5);
411 assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
412 facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
413 assertEquals(2, facet.getBuildNumber());
414 assertEquals("20100310.014828", facet.getTimestamp());
415 assertNull(facet.getClassifier());
416 assertEquals("pom", facet.getType());
419 Files.delete(destFile);
420 Files.delete(destFile2);
425 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
427 assertDependency( dependency, groupId, artifactId, version, "compile" );
430 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
433 assertEquals( artifactId, dependency.getArtifactId() );
434 assertEquals( "jar", dependency.getType() );
435 assertEquals( version, dependency.getVersion() );
436 assertEquals( groupId, dependency.getNamespace() );
437 assertEquals( scope, dependency.getScope() );
438 assertNull( dependency.getClassifier() );
439 assertNull( dependency.getSystemPath() );
443 public void testGetProjectVersionMetadataForTimestampedSnapshot()
446 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
447 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
448 MavenProjectFacet facet = MavenProjectFacet.class.cast( metadata.getFacet( MavenProjectFacet.FACET_ID ) );
449 assertEquals( "pom", facet.getPackaging() );
450 assertEquals( "http://www.apache.org/", metadata.getUrl() );
451 assertNull( facet.getParent() );
452 assertEquals( "org.apache", facet.getGroupId() );
453 assertEquals( "apache", facet.getArtifactId() );
454 assertNull( metadata.getCiManagement() );
455 assertNotNull( metadata.getDescription() );
456 // TODO: this would be better
458 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
459 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
460 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
461 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
462 // "developers and users.", metadata.getDescription() );
463 assertEquals( "5-SNAPSHOT", metadata.getId() );
464 assertNull( metadata.getIssueManagement() );
465 checkApacheLicense( metadata );
466 assertEquals( "The Apache Software Foundation", metadata.getName() );
467 String path = "maven/pom/trunk/asf";
468 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
469 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
470 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
471 checkOrganizationApache( metadata );
472 assertEquals( 1, metadata.getMailingLists().size() );
473 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
474 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
475 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
476 Collections.<String>emptyList(), true );
477 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
481 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
486 storage.readProjectVersionMetadata(
487 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
488 fail( "Should not be found" );
490 catch ( RepositoryStorageMetadataNotFoundException e )
492 assertEquals( "missing-pom", e.getId() );
497 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
502 storage.readProjectVersionMetadata(
503 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
504 fail( "Should not be found" );
506 catch ( RepositoryStorageMetadataNotFoundException e )
508 assertEquals( "missing-pom", e.getId() );
513 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
518 storage.readProjectVersionMetadata(
519 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
520 fail( "Should not be found" );
522 catch ( RepositoryStorageMetadataNotFoundException e )
524 assertEquals( "missing-pom", e.getId() );
529 public void testGetProjectVersionMetadataForInvalidPom()
534 storage.readProjectVersionMetadata(
535 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
536 fail( "Should have received an exception due to invalid POM" );
538 catch ( RepositoryStorageMetadataInvalidException e )
540 assertEquals( "invalid-pom", e.getId() );
545 public void testGetProjectVersionMetadataForMislocatedPom()
550 storage.readProjectVersionMetadata(
551 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
552 fail( "Should have received an exception due to mislocated POM" );
554 catch ( RepositoryStorageMetadataInvalidException e )
556 assertEquals( "mislocated-pom", e.getId() );
561 public void testGetProjectVersionMetadataForMissingPom()
566 storage.readProjectVersionMetadata(
567 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
568 fail( "Should not be found" );
570 catch ( RepositoryStorageMetadataNotFoundException e )
572 assertEquals( "missing-pom", e.getId() );
577 public void testGetRootNamespaces()
580 assertEquals( Arrays.asList( "com", "org"), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
584 public void testGetNamespaces()
587 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
588 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
589 assertEquals( Collections.<String>emptyList(),
590 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
592 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
593 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
594 assertEquals( Collections.<String>emptyList(),
595 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
596 assertEquals( Arrays.asList( "plugins", "shared" ),
597 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
598 assertEquals( Collections.<String>emptyList(),
599 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
600 assertEquals( Collections.<String>emptyList(),
601 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
603 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
604 assertEquals( Collections.<String>emptyList(),
605 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
609 public void testGetProjects()
612 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
613 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
614 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
615 "missing-metadata", "missing-parent", "test-artifact" ),
616 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
618 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
619 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
620 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
621 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
622 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
623 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
624 assertEquals( Collections.<String>emptyList(),
625 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
626 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
627 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
631 public void testGetProjectVersions()
634 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
635 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
636 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
637 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
638 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
639 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
640 assertEquals( Arrays.asList( "1.0" ),
641 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
643 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
644 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
646 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
647 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
648 assertEquals( Arrays.asList( "1.2.1" ),
649 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
650 assertEquals( Arrays.asList( "1.2.1" ),
651 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
652 assertEquals( Arrays.asList( "1.2.1" ),
653 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
654 assertEquals( Arrays.asList( "3" ),
655 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
657 assertEquals( Collections.<String>emptyList(),
658 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
662 public void testGetArtifacts()
665 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
666 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
667 assertEquals( 3, artifacts.size() );
668 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
671 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
673 return o1.getId().compareTo( o2.getId() );
677 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
678 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
679 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
680 "f83aa25f016212a551a4b2249985effc" );
684 public void testGetArtifactsFiltered()
687 ExcludesFilter<String> filter =
688 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
689 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
690 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
691 assertEquals( 2, artifacts.size() );
692 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
695 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
697 return o1.getId().compareTo( o2.getId() );
701 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
702 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
706 public void testGetArtifactsTimestampedSnapshots()
709 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
710 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
711 assertEquals( 1, artifacts.size() );
713 ArtifactMetadata artifact = artifacts.get( 0 );
714 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
715 assertEquals( "com.example.test", artifact.getNamespace() );
716 assertEquals( "missing-metadata", artifact.getProject() );
717 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
718 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
721 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
723 assertEquals( id, artifact.getId() );
724 assertEquals( md5, artifact.getMd5() );
725 assertEquals( sha1, artifact.getSha1() );
726 assertEquals( size, artifact.getSize() );
727 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
728 assertEquals( "plexus-spring", artifact.getProject() );
729 assertEquals( "1.2", artifact.getVersion() );
730 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
733 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
734 String unsubscribe, List<String> otherArchives, boolean allowPost )
736 assertEquals( archive, mailingList.getMainArchiveUrl() );
739 assertEquals( post, mailingList.getPostAddress() );
743 assertNull( mailingList.getPostAddress() );
745 assertEquals( subscribe, mailingList.getSubscribeAddress() );
746 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
747 assertEquals( name, mailingList.getName() );
748 assertEquals( otherArchives, mailingList.getOtherArchives() );
751 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
754 List<String> otherArchives = new ArrayList<>();
755 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
756 if ( nabbleUrl != null )
758 otherArchives.add( nabbleUrl );
760 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
761 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
762 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
763 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
766 private void checkApacheLicense( ProjectVersionMetadata metadata )
768 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
769 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
770 metadata.getLicenses() );
773 private void checkOrganizationApache( ProjectVersionMetadata metadata )
775 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
776 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
779 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
782 for ( String path : pathsToBeDeleted )
784 Path dir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path );
785 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
787 assertFalse( Files.exists(dir) );
789 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
791 Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
792 Path rootPom = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
794 org.apache.archiva.common.utils.FileUtils.deleteDirectory( dest );
795 org.apache.archiva.common.utils.FileUtils.deleteDirectory( parentPom );
796 org.apache.archiva.common.utils.FileUtils.deleteDirectory( rootPom );
798 assertFalse( Files.exists(dest) );
799 assertFalse( Files.exists(parentPom) );
800 assertFalse( Files.exists(rootPom) );
803 private Path copyTestArtifactWithParent( String srcPath, String destPath )
806 Path src = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath );
807 Path dest = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath );
809 FileUtils.copyDirectory( src.toFile(), dest.toFile() );
810 assertTrue( Files.exists(dest) );