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;
59 import static org.mockito.Mockito.mock;
60 import static org.mockito.Mockito.when;
62 @RunWith( SpringJUnit4ClassRunner.class )
63 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
64 public class Maven2RepositoryMetadataResolverTest
67 private static final Filter<String> ALL = new AllFilter<String>();
70 @Named( value = "repositoryStorage#maven2" )
71 private Maven2RepositoryStorage storage;
73 private static final String TEST_REPO_ID = "test";
75 private static final String TEST_REMOTE_REPO_ID = "central";
77 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
79 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
81 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
83 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
85 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
87 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
89 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
91 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
94 private ArchivaConfiguration configuration;
96 private WagonFactory wagonFactory;
104 Configuration c = new Configuration();
105 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
106 testRepo.setId( TEST_REPO_ID );
107 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
108 c.addManagedRepository( testRepo );
110 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
111 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
112 testRemoteRepo.setLayout( "default" );
113 testRemoteRepo.setName( "Central Repository" );
114 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
115 testRemoteRepo.setTimeout( 10 );
116 c.addRemoteRepository( testRemoteRepo );
118 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
119 proxyConnector.setSourceRepoId( TEST_REPO_ID );
120 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
121 proxyConnector.setDisabled( false );
122 c.addProxyConnector( proxyConnector );
124 configuration.save( c );
126 wagonFactory = mock( WagonFactory.class );
128 storage.setWagonFactory( wagonFactory );
130 Wagon wagon = new MockWagon();
131 when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
135 public void testModelWithJdkProfileActivation()
139 ProjectVersionMetadata metadata =
140 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.maven", "maven-archiver", "2.4.1" );
141 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
145 public void testGetProjectVersionMetadata()
148 ProjectVersionMetadata metadata =
149 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
150 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
151 assertEquals( "jar", facet.getPackaging() );
152 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
153 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
154 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
155 assertEquals( "1.2.1", facet.getParent().getVersion() );
156 assertEquals( "archiva-common", facet.getArtifactId() );
157 assertEquals( "org.apache.archiva", facet.getGroupId() );
158 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
159 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
160 assertNotNull( metadata.getDescription() );
161 // TODO: this would be better
163 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
164 // metadata.getDescription() );
165 assertEquals( "1.2.1", metadata.getId() );
166 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
167 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
168 checkApacheLicense( metadata );
169 assertEquals( "Archiva Base :: Common", metadata.getName() );
170 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
171 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
172 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
173 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
174 checkOrganizationApache( metadata );
176 assertEquals( 4, metadata.getMailingLists().size() );
177 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
178 "http://www.nabble.com/archiva-users-f16426.html" );
179 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
180 "http://www.nabble.com/archiva-dev-f16427.html" );
181 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
182 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
183 "http://www.nabble.com/Archiva---Issues-f29617.html" );
185 List<Dependency> dependencies = metadata.getDependencies();
186 assertEquals( 10, dependencies.size() );
187 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
188 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
189 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
190 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
191 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
192 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
193 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
194 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
195 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
196 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
200 public void testGetArtifactMetadata()
203 Collection<ArtifactMetadata> springArtifacts =
204 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL );
205 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
206 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
208 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
210 return o1.getId().compareTo( o2.getId() );
214 assertEquals( 3, artifacts.size() );
216 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
217 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
218 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
219 assertEquals( 0, facet.getBuildNumber() );
220 assertNull( facet.getTimestamp() );
221 assertEquals( "sources", facet.getClassifier() );
222 assertEquals( "java-source", facet.getType() );
224 artifactMetadata = artifacts.get( 1 );
225 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
226 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
227 assertEquals( 0, facet.getBuildNumber() );
228 assertNull( facet.getTimestamp() );
229 assertNull( facet.getClassifier() );
230 assertEquals( "jar", facet.getType() );
232 artifactMetadata = artifacts.get( 2 );
233 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
234 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
235 assertEquals( 0, facet.getBuildNumber() );
236 assertNull( facet.getTimestamp() );
237 assertNull( facet.getClassifier() );
238 assertEquals( "pom", facet.getType() );
242 public void testGetArtifactMetadataSnapshots()
245 Collection<ArtifactMetadata> testArtifacts =
246 storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL );
247 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
248 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
250 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
252 return o1.getId().compareTo( o2.getId() );
256 assertEquals( 6, artifacts.size() );
258 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
259 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
260 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
261 assertEquals( 1, facet.getBuildNumber() );
262 assertEquals( "20100308.230825", facet.getTimestamp() );
263 assertNull( facet.getClassifier() );
264 assertEquals( "jar", facet.getType() );
266 artifactMetadata = artifacts.get( 1 );
267 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
268 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
269 assertEquals( 1, facet.getBuildNumber() );
270 assertEquals( "20100308.230825", facet.getTimestamp() );
271 assertNull( facet.getClassifier() );
272 assertEquals( "pom", facet.getType() );
274 artifactMetadata = artifacts.get( 2 );
275 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
276 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
277 assertEquals( 2, facet.getBuildNumber() );
278 assertEquals( "20100310.014828", facet.getTimestamp() );
279 assertEquals( "javadoc", facet.getClassifier() );
280 assertEquals( "javadoc", facet.getType() );
282 artifactMetadata = artifacts.get( 3 );
283 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
284 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
285 assertEquals( 2, facet.getBuildNumber() );
286 assertEquals( "20100310.014828", facet.getTimestamp() );
287 assertEquals( "sources", facet.getClassifier() );
288 assertEquals( "java-source", facet.getType() );
290 artifactMetadata = artifacts.get( 4 );
291 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
292 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
293 assertEquals( 2, facet.getBuildNumber() );
294 assertEquals( "20100310.014828", facet.getTimestamp() );
295 assertNull( facet.getClassifier() );
296 assertEquals( "jar", facet.getType() );
298 artifactMetadata = artifacts.get( 5 );
299 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
300 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
301 assertEquals( 2, facet.getBuildNumber() );
302 assertEquals( "20100310.014828", facet.getTimestamp() );
303 assertNull( facet.getClassifier() );
304 assertEquals( "pom", facet.getType() );
307 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
309 assertDependency( dependency, groupId, artifactId, version, "compile" );
312 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
315 assertEquals( artifactId, dependency.getArtifactId() );
316 assertEquals( "jar", dependency.getType() );
317 assertEquals( version, dependency.getVersion() );
318 assertEquals( groupId, dependency.getGroupId() );
319 assertEquals( scope, dependency.getScope() );
320 assertNull( dependency.getClassifier() );
321 assertNull( dependency.getSystemPath() );
325 public void testGetProjectVersionMetadataForTimestampedSnapshot()
328 ProjectVersionMetadata metadata =
329 storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
330 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
331 assertEquals( "pom", facet.getPackaging() );
332 assertEquals( "http://www.apache.org/", metadata.getUrl() );
333 assertNull( facet.getParent() );
334 assertEquals( "org.apache", facet.getGroupId() );
335 assertEquals( "apache", facet.getArtifactId() );
336 assertNull( metadata.getCiManagement() );
337 assertNotNull( metadata.getDescription() );
338 // TODO: this would be better
340 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
341 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
342 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
343 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
344 // "developers and users.", metadata.getDescription() );
345 assertEquals( "5-SNAPSHOT", metadata.getId() );
346 assertNull( metadata.getIssueManagement() );
347 checkApacheLicense( metadata );
348 assertEquals( "The Apache Software Foundation", metadata.getName() );
349 String path = "maven/pom/trunk/asf";
350 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
351 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
352 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
353 checkOrganizationApache( metadata );
354 assertEquals( 1, metadata.getMailingLists().size() );
355 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
356 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
357 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
358 Collections.<String>emptyList(), true );
359 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
363 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
368 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
369 fail( "Should not be found" );
371 catch ( RepositoryStorageMetadataNotFoundException e )
373 assertEquals( "missing-pom", e.getId() );
378 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
383 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
385 fail( "Should not be found" );
387 catch ( RepositoryStorageMetadataNotFoundException e )
389 assertEquals( "missing-pom", e.getId() );
394 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
399 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
401 fail( "Should not be found" );
403 catch ( RepositoryStorageMetadataNotFoundException e )
405 assertEquals( "missing-pom", e.getId() );
410 public void testGetProjectVersionMetadataForInvalidPom()
415 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
416 fail( "Should have received an exception due to invalid POM" );
418 catch ( RepositoryStorageMetadataInvalidException e )
420 assertEquals( "invalid-pom", e.getId() );
425 public void testGetProjectVersionMetadataForMislocatedPom()
430 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
431 fail( "Should have received an exception due to mislocated POM" );
433 catch ( RepositoryStorageMetadataInvalidException e )
435 assertEquals( "mislocated-pom", e.getId() );
440 public void testGetProjectVersionMetadataForMissingPom()
445 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
446 fail( "Should not be found" );
448 catch ( RepositoryStorageMetadataNotFoundException e )
450 assertEquals( "missing-pom", e.getId() );
454 // Tests for MRM-1411 - START
456 public void testGetProjectVersionMetadataWithParentSuccessful()
459 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
460 "target/test-repository/com/example/test/test-artifact-module-a" );
462 ProjectVersionMetadata metadata =
463 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
465 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
466 assertEquals( "jar", facet.getPackaging() );
467 assertEquals( "http://maven.apache.org", metadata.getUrl() );
468 assertEquals( "com.example.test", facet.getParent().getGroupId() );
469 assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
470 assertEquals( "1.0", facet.getParent().getVersion() );
471 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
472 assertEquals( "com.example.test", facet.getGroupId() );
473 assertNull( metadata.getCiManagement() );
474 assertNotNull( metadata.getDescription() );
476 checkApacheLicense( metadata );
478 assertEquals( "1.0", metadata.getId() );
479 assertEquals( "Test Artifact :: Module A", metadata.getName() );
480 String path = "test-artifact/trunk/test-artifact-module-a";
481 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
482 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
483 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
485 List<Dependency> dependencies = metadata.getDependencies();
486 assertEquals( 2, dependencies.size() );
487 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
488 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
490 List<String> paths = new ArrayList<String>();
491 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
492 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
493 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
495 deleteTestArtifactWithParent( paths );
499 public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
502 // remove configuration
503 Configuration config = configuration.getConfiguration();
504 RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
505 config.removeRemoteRepository( remoteRepo );
507 configuration.save( config );
509 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
510 "target/test-repository/com/example/test/test-artifact-module-a" );
512 ProjectVersionMetadata metadata =
513 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
514 assertEquals( "1.0", metadata.getId() );
516 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
517 assertNotNull( facet );
518 assertEquals( "com.example.test", facet.getGroupId() );
519 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
520 assertEquals( "jar", facet.getPackaging() );
522 List<String> paths = new ArrayList<String>();
523 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
524 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
525 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
527 deleteTestArtifactWithParent( paths );
531 public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
534 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
535 "target/test-repository/com/example/test/test-artifact-module-a" );
537 ProjectVersionMetadata metadata =
538 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
540 assertEquals( "1.1", metadata.getId() );
542 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
543 assertNotNull( facet );
544 assertEquals( "com.example.test", facet.getGroupId() );
545 assertEquals( "missing-parent", facet.getArtifactId() );
546 assertEquals( "jar", facet.getPackaging() );
548 List<String> paths = new ArrayList<String>();
549 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
550 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
551 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
553 deleteTestArtifactWithParent( paths );
557 public void testGetProjectVersionMetadataWithParentSnapshotVersion()
560 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
561 "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
563 ProjectVersionMetadata metadata =
564 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
567 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
568 assertEquals( "jar", facet.getPackaging() );
569 assertEquals( "com.example.test", facet.getParent().getGroupId() );
570 assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
571 assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
572 assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
573 assertEquals( "com.example.test", facet.getGroupId() );
574 assertNull( metadata.getCiManagement() );
575 assertNotNull( metadata.getDescription() );
577 checkApacheLicense( metadata );
579 assertEquals( "1.1-SNAPSHOT", metadata.getId() );
580 assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
581 String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
582 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
583 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
584 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
586 List<Dependency> dependencies = metadata.getDependencies();
587 assertEquals( 2, dependencies.size() );
588 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
589 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
591 List<String> paths = new ArrayList<String>();
592 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
593 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
595 deleteTestArtifactWithParent( paths );
598 // Tests for MRM-1411 - END
601 public void testGetRootNamespaces()
604 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
608 public void testGetNamespaces()
611 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
612 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
613 assertEquals( Collections.<String>emptyList(),
614 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
616 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
617 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
618 assertEquals( Collections.<String>emptyList(),
619 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
620 assertEquals( Arrays.asList( "plugins", "shared" ),
621 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
622 assertEquals( Collections.<String>emptyList(),
623 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
624 assertEquals( Collections.<String>emptyList(),
625 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
627 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
628 assertEquals( Collections.<String>emptyList(),
629 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
633 public void testGetProjects()
636 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
637 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
638 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
639 "missing-metadata", "missing-parent", "test-artifact" ),
640 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
642 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
643 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
644 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
645 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
646 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
647 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
648 assertEquals( Collections.<String>emptyList(),
649 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
650 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
651 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
655 public void testGetProjectVersions()
658 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
659 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
660 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
661 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
662 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
663 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
664 assertEquals( Arrays.asList( "1.0" ),
665 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
667 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
668 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
670 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
671 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
672 assertEquals( Arrays.asList( "1.2.1" ),
673 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
674 assertEquals( Arrays.asList( "1.2.1" ),
675 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
676 assertEquals( Arrays.asList( "1.2.1" ),
677 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
678 assertEquals( Arrays.asList( "3" ),
679 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
681 assertEquals( Collections.<String>emptyList(),
682 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
686 public void testGetArtifacts()
689 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
690 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
691 assertEquals( 3, artifacts.size() );
692 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
694 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
696 return o1.getId().compareTo( o2.getId() );
700 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
701 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
702 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
703 "f83aa25f016212a551a4b2249985effc" );
707 public void testGetArtifactsFiltered()
710 ExcludesFilter<String> filter =
711 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
712 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
713 storage.readArtifactsMetadata( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) );
714 assertEquals( 2, artifacts.size() );
715 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
717 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
719 return o1.getId().compareTo( o2.getId() );
723 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
724 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
728 public void testGetArtifactsTimestampedSnapshots()
731 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(
732 storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT",
734 assertEquals( 1, artifacts.size() );
736 ArtifactMetadata artifact = artifacts.get( 0 );
737 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
738 assertEquals( "com.example.test", artifact.getNamespace() );
739 assertEquals( "missing-metadata", artifact.getProject() );
740 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
741 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
744 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
746 assertEquals( id, artifact.getId() );
747 assertEquals( md5, artifact.getMd5() );
748 assertEquals( sha1, artifact.getSha1() );
749 assertEquals( size, artifact.getSize() );
750 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
751 assertEquals( "plexus-spring", artifact.getProject() );
752 assertEquals( "1.2", artifact.getVersion() );
753 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
756 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
757 String unsubscribe, List<String> otherArchives, boolean allowPost )
759 assertEquals( archive, mailingList.getMainArchiveUrl() );
762 assertEquals( post, mailingList.getPostAddress() );
766 assertNull( mailingList.getPostAddress() );
768 assertEquals( subscribe, mailingList.getSubscribeAddress() );
769 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
770 assertEquals( name, mailingList.getName() );
771 assertEquals( otherArchives, mailingList.getOtherArchives() );
774 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
777 List<String> otherArchives = new ArrayList<String>();
778 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
779 if ( nabbleUrl != null )
781 otherArchives.add( nabbleUrl );
783 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
784 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
785 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
786 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
789 private void checkApacheLicense( ProjectVersionMetadata metadata )
791 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
792 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
793 metadata.getLicenses() );
796 private void checkOrganizationApache( ProjectVersionMetadata metadata )
798 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
799 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
802 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
805 for ( String path : pathsToBeDeleted )
807 File dir = new File( FileUtil.getBasedir(), path );
808 FileUtils.deleteDirectory( dir );
810 assertFalse( dir.exists() );
812 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
814 new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
815 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
817 FileUtils.deleteDirectory( dest );
818 FileUtils.deleteDirectory( parentPom );
819 FileUtils.deleteDirectory( rootPom );
821 assertFalse( dest.exists() );
822 assertFalse( parentPom.exists() );
823 assertFalse( rootPom.exists() );
826 private File copyTestArtifactWithParent( String srcPath, String destPath )
829 File src = new File( FileUtil.getBasedir(), srcPath );
830 File dest = new File( FileUtil.getBasedir(), destPath );
832 FileUtils.copyDirectory( src, dest );
833 assertTrue( dest.exists() );