1 package org.apache.archiva.metadata.repository.storage.maven2;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.common.utils.FileUtil;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
28 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
29 import org.apache.archiva.metadata.model.ArtifactMetadata;
30 import org.apache.archiva.metadata.model.Dependency;
31 import org.apache.archiva.metadata.model.License;
32 import org.apache.archiva.metadata.model.MailingList;
33 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
34 import org.apache.archiva.metadata.repository.filter.AllFilter;
35 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
36 import org.apache.archiva.metadata.repository.filter.Filter;
37 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
38 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
39 import org.apache.archiva.proxy.common.WagonFactory;
40 import org.apache.commons.io.FileUtils;
41 import org.apache.maven.wagon.Wagon;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48 import javax.inject.Inject;
49 import javax.inject.Named;
51 import java.io.IOException;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collection;
55 import java.util.Collections;
56 import java.util.Comparator;
57 import java.util.List;
58 import org.apache.archiva.test.ArchivaSpringJUnit4ClassRunner;
60 import static org.mockito.Mockito.mock;
61 import static org.mockito.Mockito.when;
63 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
64 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
65 public class Maven2RepositoryMetadataResolverTest
68 private static final Filter<String> ALL = new AllFilter<String>();
71 @Named( value = "repositoryStorage#maven2" )
72 private Maven2RepositoryStorage storage;
74 private static final String TEST_REPO_ID = "test";
76 private static final String TEST_REMOTE_REPO_ID = "central";
78 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
80 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
82 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
84 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
86 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
88 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
90 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
92 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
95 private ArchivaConfiguration configuration;
97 private WagonFactory wagonFactory;
105 Configuration c = new Configuration();
106 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
107 testRepo.setId( TEST_REPO_ID );
108 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
109 c.addManagedRepository( testRepo );
111 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
112 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
113 testRemoteRepo.setLayout( "default" );
114 testRemoteRepo.setName( "Central Repository" );
115 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
116 testRemoteRepo.setTimeout( 10 );
117 c.addRemoteRepository( testRemoteRepo );
119 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
120 proxyConnector.setSourceRepoId( TEST_REPO_ID );
121 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
122 proxyConnector.setDisabled( false );
123 c.addProxyConnector( proxyConnector );
125 configuration.save( c );
127 wagonFactory = mock( WagonFactory.class );
129 storage.setWagonFactory( wagonFactory );
131 Wagon wagon = new MockWagon();
132 when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
136 public void testModelWithJdkProfileActivation()
140 ProjectVersionMetadata metadata =
141 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.maven", "maven-archiver", "2.4.1" );
142 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
146 public void testGetProjectVersionMetadata()
149 ProjectVersionMetadata metadata =
150 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
151 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
152 assertEquals( "jar", facet.getPackaging() );
153 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
154 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
155 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
156 assertEquals( "1.2.1", facet.getParent().getVersion() );
157 assertEquals( "archiva-common", facet.getArtifactId() );
158 assertEquals( "org.apache.archiva", facet.getGroupId() );
159 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
160 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
161 assertNotNull( metadata.getDescription() );
162 // TODO: this would be better
164 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
165 // metadata.getDescription() );
166 assertEquals( "1.2.1", metadata.getId() );
167 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
168 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
169 checkApacheLicense( metadata );
170 assertEquals( "Archiva Base :: Common", metadata.getName() );
171 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
172 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
173 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
174 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
175 checkOrganizationApache( metadata );
177 assertEquals( 4, metadata.getMailingLists().size() );
178 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
179 "http://www.nabble.com/archiva-users-f16426.html" );
180 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
181 "http://www.nabble.com/archiva-dev-f16427.html" );
182 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
183 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
184 "http://www.nabble.com/Archiva---Issues-f29617.html" );
186 List<Dependency> dependencies = metadata.getDependencies();
187 assertEquals( 10, dependencies.size() );
188 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
189 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
190 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
191 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
192 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
193 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
194 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
195 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
196 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
197 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
201 public void testGetArtifactMetadata()
204 Collection<ArtifactMetadata> springArtifacts =
205 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL );
206 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
207 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
209 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
211 return o1.getId().compareTo( o2.getId() );
215 assertEquals( 3, artifacts.size() );
217 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
218 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
219 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
220 assertEquals( 0, facet.getBuildNumber() );
221 assertNull( facet.getTimestamp() );
222 assertEquals( "sources", facet.getClassifier() );
223 assertEquals( "java-source", facet.getType() );
225 artifactMetadata = artifacts.get( 1 );
226 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
227 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
228 assertEquals( 0, facet.getBuildNumber() );
229 assertNull( facet.getTimestamp() );
230 assertNull( facet.getClassifier() );
231 assertEquals( "jar", facet.getType() );
233 artifactMetadata = artifacts.get( 2 );
234 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
235 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
236 assertEquals( 0, facet.getBuildNumber() );
237 assertNull( facet.getTimestamp() );
238 assertNull( facet.getClassifier() );
239 assertEquals( "pom", facet.getType() );
243 public void testGetArtifactMetadataSnapshots()
246 Collection<ArtifactMetadata> testArtifacts =
247 storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL );
248 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
249 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
251 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
253 return o1.getId().compareTo( o2.getId() );
257 assertEquals( 6, artifacts.size() );
259 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
260 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
261 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
262 assertEquals( 1, facet.getBuildNumber() );
263 assertEquals( "20100308.230825", facet.getTimestamp() );
264 assertNull( facet.getClassifier() );
265 assertEquals( "jar", facet.getType() );
267 artifactMetadata = artifacts.get( 1 );
268 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
269 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
270 assertEquals( 1, facet.getBuildNumber() );
271 assertEquals( "20100308.230825", facet.getTimestamp() );
272 assertNull( facet.getClassifier() );
273 assertEquals( "pom", facet.getType() );
275 artifactMetadata = artifacts.get( 2 );
276 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
277 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
278 assertEquals( 2, facet.getBuildNumber() );
279 assertEquals( "20100310.014828", facet.getTimestamp() );
280 assertEquals( "javadoc", facet.getClassifier() );
281 assertEquals( "javadoc", facet.getType() );
283 artifactMetadata = artifacts.get( 3 );
284 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
285 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
286 assertEquals( 2, facet.getBuildNumber() );
287 assertEquals( "20100310.014828", facet.getTimestamp() );
288 assertEquals( "sources", facet.getClassifier() );
289 assertEquals( "java-source", facet.getType() );
291 artifactMetadata = artifacts.get( 4 );
292 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
293 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
294 assertEquals( 2, facet.getBuildNumber() );
295 assertEquals( "20100310.014828", facet.getTimestamp() );
296 assertNull( facet.getClassifier() );
297 assertEquals( "jar", facet.getType() );
299 artifactMetadata = artifacts.get( 5 );
300 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
301 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
302 assertEquals( 2, facet.getBuildNumber() );
303 assertEquals( "20100310.014828", facet.getTimestamp() );
304 assertNull( facet.getClassifier() );
305 assertEquals( "pom", facet.getType() );
308 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
310 assertDependency( dependency, groupId, artifactId, version, "compile" );
313 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
316 assertEquals( artifactId, dependency.getArtifactId() );
317 assertEquals( "jar", dependency.getType() );
318 assertEquals( version, dependency.getVersion() );
319 assertEquals( groupId, dependency.getGroupId() );
320 assertEquals( scope, dependency.getScope() );
321 assertNull( dependency.getClassifier() );
322 assertNull( dependency.getSystemPath() );
326 public void testGetProjectVersionMetadataForTimestampedSnapshot()
329 ProjectVersionMetadata metadata =
330 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
331 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
332 assertEquals( "pom", facet.getPackaging() );
333 assertEquals( "http://www.apache.org/", metadata.getUrl() );
334 assertNull( facet.getParent() );
335 assertEquals( "org.apache", facet.getGroupId() );
336 assertEquals( "apache", facet.getArtifactId() );
337 assertNull( metadata.getCiManagement() );
338 assertNotNull( metadata.getDescription() );
339 // TODO: this would be better
341 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
342 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
343 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
344 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
345 // "developers and users.", metadata.getDescription() );
346 assertEquals( "5-SNAPSHOT", metadata.getId() );
347 assertNull( metadata.getIssueManagement() );
348 checkApacheLicense( metadata );
349 assertEquals( "The Apache Software Foundation", metadata.getName() );
350 String path = "maven/pom/trunk/asf";
351 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
352 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
353 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
354 checkOrganizationApache( metadata );
355 assertEquals( 1, metadata.getMailingLists().size() );
356 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
357 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
358 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
359 Collections.<String>emptyList(), true );
360 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
364 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
369 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
370 fail( "Should not be found" );
372 catch ( RepositoryStorageMetadataNotFoundException e )
374 assertEquals( "missing-pom", e.getId() );
379 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
384 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
386 fail( "Should not be found" );
388 catch ( RepositoryStorageMetadataNotFoundException e )
390 assertEquals( "missing-pom", e.getId() );
395 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
400 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
402 fail( "Should not be found" );
404 catch ( RepositoryStorageMetadataNotFoundException e )
406 assertEquals( "missing-pom", e.getId() );
411 public void testGetProjectVersionMetadataForInvalidPom()
416 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
417 fail( "Should have received an exception due to invalid POM" );
419 catch ( RepositoryStorageMetadataInvalidException e )
421 assertEquals( "invalid-pom", e.getId() );
426 public void testGetProjectVersionMetadataForMislocatedPom()
431 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
432 fail( "Should have received an exception due to mislocated POM" );
434 catch ( RepositoryStorageMetadataInvalidException e )
436 assertEquals( "mislocated-pom", e.getId() );
441 public void testGetProjectVersionMetadataForMissingPom()
446 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
447 fail( "Should not be found" );
449 catch ( RepositoryStorageMetadataNotFoundException e )
451 assertEquals( "missing-pom", e.getId() );
455 // Tests for MRM-1411 - START
457 public void testGetProjectVersionMetadataWithParentSuccessful()
460 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
461 "target/test-repository/com/example/test/test-artifact-module-a" );
463 ProjectVersionMetadata metadata =
464 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
466 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
467 assertEquals( "jar", facet.getPackaging() );
468 assertEquals( "http://maven.apache.org", metadata.getUrl() );
469 assertEquals( "com.example.test", facet.getParent().getGroupId() );
470 assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
471 assertEquals( "1.0", facet.getParent().getVersion() );
472 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
473 assertEquals( "com.example.test", facet.getGroupId() );
474 assertNull( metadata.getCiManagement() );
475 assertNotNull( metadata.getDescription() );
477 checkApacheLicense( metadata );
479 assertEquals( "1.0", metadata.getId() );
480 assertEquals( "Test Artifact :: Module A", metadata.getName() );
481 String path = "test-artifact/trunk/test-artifact-module-a";
482 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
483 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
484 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
486 List<Dependency> dependencies = metadata.getDependencies();
487 assertEquals( 2, dependencies.size() );
488 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
489 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
491 List<String> paths = new ArrayList<String>();
492 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
493 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
494 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
496 deleteTestArtifactWithParent( paths );
500 public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
503 // remove configuration
504 Configuration config = configuration.getConfiguration();
505 RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
506 config.removeRemoteRepository( remoteRepo );
508 configuration.save( config );
510 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
511 "target/test-repository/com/example/test/test-artifact-module-a" );
513 ProjectVersionMetadata metadata =
514 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
515 assertEquals( "1.0", metadata.getId() );
517 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
518 assertNotNull( facet );
519 assertEquals( "com.example.test", facet.getGroupId() );
520 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
521 assertEquals( "jar", facet.getPackaging() );
523 List<String> paths = new ArrayList<String>();
524 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
525 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
526 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
528 deleteTestArtifactWithParent( paths );
532 public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
535 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
536 "target/test-repository/com/example/test/test-artifact-module-a" );
538 ProjectVersionMetadata metadata =
539 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
541 assertEquals( "1.1", metadata.getId() );
543 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
544 assertNotNull( facet );
545 assertEquals( "com.example.test", facet.getGroupId() );
546 assertEquals( "missing-parent", facet.getArtifactId() );
547 assertEquals( "jar", facet.getPackaging() );
549 List<String> paths = new ArrayList<String>();
550 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
551 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
552 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
554 deleteTestArtifactWithParent( paths );
558 public void testGetProjectVersionMetadataWithParentSnapshotVersion()
561 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
562 "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
564 ProjectVersionMetadata metadata =
565 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
568 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
569 assertEquals( "jar", facet.getPackaging() );
570 assertEquals( "com.example.test", facet.getParent().getGroupId() );
571 assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
572 assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
573 assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
574 assertEquals( "com.example.test", facet.getGroupId() );
575 assertNull( metadata.getCiManagement() );
576 assertNotNull( metadata.getDescription() );
578 checkApacheLicense( metadata );
580 assertEquals( "1.1-SNAPSHOT", metadata.getId() );
581 assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
582 String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
583 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
584 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
585 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
587 List<Dependency> dependencies = metadata.getDependencies();
588 assertEquals( 2, dependencies.size() );
589 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
590 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
592 List<String> paths = new ArrayList<String>();
593 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
594 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
596 deleteTestArtifactWithParent( paths );
599 // Tests for MRM-1411 - END
602 public void testGetRootNamespaces()
605 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
609 public void testGetNamespaces()
612 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
613 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
614 assertEquals( Collections.<String>emptyList(),
615 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
617 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
618 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
619 assertEquals( Collections.<String>emptyList(),
620 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
621 assertEquals( Arrays.asList( "plugins", "shared" ),
622 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
623 assertEquals( Collections.<String>emptyList(),
624 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
625 assertEquals( Collections.<String>emptyList(),
626 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
628 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
629 assertEquals( Collections.<String>emptyList(),
630 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
634 public void testGetProjects()
637 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
638 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
639 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
640 "missing-metadata", "missing-parent", "test-artifact" ),
641 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
643 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
644 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
645 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
646 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
647 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
648 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
649 assertEquals( Collections.<String>emptyList(),
650 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
651 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
652 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
656 public void testGetProjectVersions()
659 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
660 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
661 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
662 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
663 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
664 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
665 assertEquals( Arrays.asList( "1.0" ),
666 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
668 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
669 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
671 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
672 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
673 assertEquals( Arrays.asList( "1.2.1" ),
674 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
675 assertEquals( Arrays.asList( "1.2.1" ),
676 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
677 assertEquals( Arrays.asList( "1.2.1" ),
678 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
679 assertEquals( Arrays.asList( "3" ),
680 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
682 assertEquals( Collections.<String>emptyList(),
683 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
687 public void testGetArtifacts()
690 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
691 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
692 assertEquals( 3, artifacts.size() );
693 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 );
703 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
704 "f83aa25f016212a551a4b2249985effc" );
708 public void testGetArtifactsFiltered()
711 ExcludesFilter<String> filter =
712 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
713 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
714 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) );
715 assertEquals( 2, artifacts.size() );
716 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
718 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
720 return o1.getId().compareTo( o2.getId() );
724 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
725 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
729 public void testGetArtifactsTimestampedSnapshots()
732 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
733 storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT",
735 assertEquals( 1, artifacts.size() );
737 ArtifactMetadata artifact = artifacts.get( 0 );
738 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
739 assertEquals( "com.example.test", artifact.getNamespace() );
740 assertEquals( "missing-metadata", artifact.getProject() );
741 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
742 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
745 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
747 assertEquals( id, artifact.getId() );
748 assertEquals( md5, artifact.getMd5() );
749 assertEquals( sha1, artifact.getSha1() );
750 assertEquals( size, artifact.getSize() );
751 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
752 assertEquals( "plexus-spring", artifact.getProject() );
753 assertEquals( "1.2", artifact.getVersion() );
754 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
757 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
758 String unsubscribe, List<String> otherArchives, boolean allowPost )
760 assertEquals( archive, mailingList.getMainArchiveUrl() );
763 assertEquals( post, mailingList.getPostAddress() );
767 assertNull( mailingList.getPostAddress() );
769 assertEquals( subscribe, mailingList.getSubscribeAddress() );
770 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
771 assertEquals( name, mailingList.getName() );
772 assertEquals( otherArchives, mailingList.getOtherArchives() );
775 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
778 List<String> otherArchives = new ArrayList<String>();
779 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
780 if ( nabbleUrl != null )
782 otherArchives.add( nabbleUrl );
784 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
785 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
786 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
787 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
790 private void checkApacheLicense( ProjectVersionMetadata metadata )
792 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
793 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
794 metadata.getLicenses() );
797 private void checkOrganizationApache( ProjectVersionMetadata metadata )
799 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
800 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
803 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
806 for ( String path : pathsToBeDeleted )
808 File dir = new File( FileUtil.getBasedir(), path );
809 FileUtils.deleteDirectory( dir );
811 assertFalse( dir.exists() );
813 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
815 new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
816 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
818 FileUtils.deleteDirectory( dest );
819 FileUtils.deleteDirectory( parentPom );
820 FileUtils.deleteDirectory( rootPom );
822 assertFalse( dest.exists() );
823 assertFalse( parentPom.exists() );
824 assertFalse( rootPom.exists() );
827 private File copyTestArtifactWithParent( String srcPath, String destPath )
830 File src = new File( FileUtil.getBasedir(), srcPath );
831 File dest = new File( FileUtil.getBasedir(), destPath );
833 FileUtils.copyDirectory( src, dest );
834 assertTrue( dest.exists() );