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.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.Dependency;
25 import org.apache.archiva.metadata.model.License;
26 import org.apache.archiva.metadata.model.MailingList;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.repository.filter.AllFilter;
29 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
30 import org.apache.archiva.metadata.repository.filter.Filter;
31 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
32 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
33 import org.apache.archiva.proxy.common.WagonFactory;
34 import org.apache.commons.io.FileUtils;
35 import org.apache.archiva.common.utils.FileUtil;
36 import org.apache.archiva.configuration.ArchivaConfiguration;
37 import org.apache.archiva.configuration.Configuration;
38 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
39 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
40 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
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 static org.mockito.Mockito.mock;
49 import static org.mockito.Mockito.when;
51 import javax.inject.Inject;
52 import javax.inject.Named;
54 import java.io.IOException;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.Collection;
58 import java.util.Collections;
59 import java.util.Comparator;
60 import java.util.List;
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 testGetProjectVersionMetadata()
138 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva",
139 "archiva-common", "1.2.1" );
140 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
141 assertEquals( "jar", facet.getPackaging() );
142 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
143 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
144 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
145 assertEquals( "1.2.1", facet.getParent().getVersion() );
146 assertEquals( "archiva-common", facet.getArtifactId() );
147 assertEquals( "org.apache.archiva", facet.getGroupId() );
148 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
149 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
150 assertNotNull( metadata.getDescription() );
151 // TODO: this would be better
153 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
154 // metadata.getDescription() );
155 assertEquals( "1.2.1", metadata.getId() );
156 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
157 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
158 checkApacheLicense( metadata );
159 assertEquals( "Archiva Base :: Common", metadata.getName() );
160 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
161 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
162 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
163 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
164 checkOrganizationApache( metadata );
166 assertEquals( 4, metadata.getMailingLists().size() );
167 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
168 "http://www.nabble.com/archiva-users-f16426.html" );
169 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
170 "http://www.nabble.com/archiva-dev-f16427.html" );
171 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
172 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
173 "http://www.nabble.com/Archiva---Issues-f29617.html" );
175 List<Dependency> dependencies = metadata.getDependencies();
176 assertEquals( 10, dependencies.size() );
177 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
178 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
179 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
180 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
181 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
182 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
183 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
184 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
185 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
186 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
190 public void testGetArtifactMetadata()
193 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID,
194 "org.codehaus.plexus",
195 "plexus-spring", "1.2", ALL );
196 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
197 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
199 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
201 return o1.getId().compareTo( o2.getId() );
205 assertEquals( 3, artifacts.size() );
207 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
208 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
209 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
210 assertEquals( 0, facet.getBuildNumber() );
211 assertNull( facet.getTimestamp() );
212 assertEquals( "sources", facet.getClassifier() );
213 assertEquals( "java-source", facet.getType() );
215 artifactMetadata = artifacts.get( 1 );
216 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
217 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
218 assertEquals( 0, facet.getBuildNumber() );
219 assertNull( facet.getTimestamp() );
220 assertNull( facet.getClassifier() );
221 assertEquals( "jar", facet.getType() );
223 artifactMetadata = artifacts.get( 2 );
224 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
225 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
226 assertEquals( 0, facet.getBuildNumber() );
227 assertNull( facet.getTimestamp() );
228 assertNull( facet.getClassifier() );
229 assertEquals( "pom", facet.getType() );
233 public void testGetArtifactMetadataSnapshots()
236 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata( TEST_REPO_ID, "com.example.test",
237 "test-artifact", "1.0-SNAPSHOT",
239 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
240 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
242 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
244 return o1.getId().compareTo( o2.getId() );
248 assertEquals( 6, artifacts.size() );
250 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
251 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
252 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
253 assertEquals( 1, facet.getBuildNumber() );
254 assertEquals( "20100308.230825", facet.getTimestamp() );
255 assertNull( facet.getClassifier() );
256 assertEquals( "jar", facet.getType() );
258 artifactMetadata = artifacts.get( 1 );
259 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
260 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
261 assertEquals( 1, facet.getBuildNumber() );
262 assertEquals( "20100308.230825", facet.getTimestamp() );
263 assertNull( facet.getClassifier() );
264 assertEquals( "pom", facet.getType() );
266 artifactMetadata = artifacts.get( 2 );
267 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
268 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
269 assertEquals( 2, facet.getBuildNumber() );
270 assertEquals( "20100310.014828", facet.getTimestamp() );
271 assertEquals( "javadoc", facet.getClassifier() );
272 assertEquals( "javadoc", facet.getType() );
274 artifactMetadata = artifacts.get( 3 );
275 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
276 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
277 assertEquals( 2, facet.getBuildNumber() );
278 assertEquals( "20100310.014828", facet.getTimestamp() );
279 assertEquals( "sources", facet.getClassifier() );
280 assertEquals( "java-source", facet.getType() );
282 artifactMetadata = artifacts.get( 4 );
283 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
284 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
285 assertEquals( 2, facet.getBuildNumber() );
286 assertEquals( "20100310.014828", facet.getTimestamp() );
287 assertNull( facet.getClassifier() );
288 assertEquals( "jar", facet.getType() );
290 artifactMetadata = artifacts.get( 5 );
291 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", 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( "pom", facet.getType() );
299 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
301 assertDependency( dependency, groupId, artifactId, version, "compile" );
304 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
307 assertEquals( artifactId, dependency.getArtifactId() );
308 assertEquals( "jar", dependency.getType() );
309 assertEquals( version, dependency.getVersion() );
310 assertEquals( groupId, dependency.getGroupId() );
311 assertEquals( scope, dependency.getScope() );
312 assertNull( dependency.getClassifier() );
313 assertNull( dependency.getSystemPath() );
317 public void testGetProjectVersionMetadataForTimestampedSnapshot()
320 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache",
322 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
323 assertEquals( "pom", facet.getPackaging() );
324 assertEquals( "http://www.apache.org/", metadata.getUrl() );
325 assertNull( facet.getParent() );
326 assertEquals( "org.apache", facet.getGroupId() );
327 assertEquals( "apache", facet.getArtifactId() );
328 assertNull( metadata.getCiManagement() );
329 assertNotNull( metadata.getDescription() );
330 // TODO: this would be better
332 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
333 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
334 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
335 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
336 // "developers and users.", metadata.getDescription() );
337 assertEquals( "5-SNAPSHOT", metadata.getId() );
338 assertNull( metadata.getIssueManagement() );
339 checkApacheLicense( metadata );
340 assertEquals( "The Apache Software Foundation", metadata.getName() );
341 String path = "maven/pom/trunk/asf";
342 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
343 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
344 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
345 checkOrganizationApache( metadata );
346 assertEquals( 1, metadata.getMailingLists().size() );
347 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
348 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
349 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
350 Collections.<String>emptyList(), true );
351 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
355 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
360 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
361 fail( "Should not be found" );
363 catch ( RepositoryStorageMetadataNotFoundException e )
365 assertEquals( "missing-pom", e.getId() );
370 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
375 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
377 fail( "Should not be found" );
379 catch ( RepositoryStorageMetadataNotFoundException e )
381 assertEquals( "missing-pom", e.getId() );
386 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
391 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
393 fail( "Should not be found" );
395 catch ( RepositoryStorageMetadataNotFoundException e )
397 assertEquals( "missing-pom", e.getId() );
402 public void testGetProjectVersionMetadataForInvalidPom()
407 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
408 fail( "Should have received an exception due to invalid POM" );
410 catch ( RepositoryStorageMetadataInvalidException e )
412 assertEquals( "invalid-pom", e.getId() );
417 public void testGetProjectVersionMetadataForMislocatedPom()
422 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
423 fail( "Should have received an exception due to mislocated POM" );
425 catch ( RepositoryStorageMetadataInvalidException e )
427 assertEquals( "mislocated-pom", e.getId() );
432 public void testGetProjectVersionMetadataForMissingPom()
437 storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
438 fail( "Should not be found" );
440 catch ( RepositoryStorageMetadataNotFoundException e )
442 assertEquals( "missing-pom", e.getId() );
446 // Tests for MRM-1411 - START
448 public void testGetProjectVersionMetadataWithParentSuccessful()
451 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
452 "target/test-repository/com/example/test/test-artifact-module-a" );
454 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
455 "test-artifact-module-a", "1.0" );
457 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
458 assertEquals( "jar", facet.getPackaging() );
459 assertEquals( "http://maven.apache.org", metadata.getUrl() );
460 assertEquals( "com.example.test", facet.getParent().getGroupId() );
461 assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
462 assertEquals( "1.0", facet.getParent().getVersion() );
463 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
464 assertEquals( "com.example.test", facet.getGroupId() );
465 assertNull( metadata.getCiManagement() );
466 assertNotNull( metadata.getDescription() );
468 checkApacheLicense( metadata );
470 assertEquals( "1.0", metadata.getId() );
471 assertEquals( "Test Artifact :: Module A", metadata.getName() );
472 String path = "test-artifact/trunk/test-artifact-module-a";
473 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
474 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
475 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
477 List<Dependency> dependencies = metadata.getDependencies();
478 assertEquals( 2, dependencies.size() );
479 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
480 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
482 List<String> paths = new ArrayList<String>();
483 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
484 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
485 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
487 deleteTestArtifactWithParent( paths );
491 public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
494 // remove configuration
495 Configuration config = configuration.getConfiguration();
496 RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
497 config.removeRemoteRepository( remoteRepo );
499 configuration.save( config );
501 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
502 "target/test-repository/com/example/test/test-artifact-module-a" );
504 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
505 "test-artifact-module-a", "1.0" );
506 assertEquals( "1.0", metadata.getId() );
508 MavenProjectFacet facet = ( MavenProjectFacet ) metadata.getFacet( MavenProjectFacet.FACET_ID );
509 assertNotNull( facet );
510 assertEquals( "com.example.test", facet.getGroupId() );
511 assertEquals( "test-artifact-module-a", facet.getArtifactId() );
512 assertEquals( "jar", facet.getPackaging() );
514 List<String> paths = new ArrayList<String>();
515 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
516 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
517 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
519 deleteTestArtifactWithParent( paths );
523 public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
526 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
527 "target/test-repository/com/example/test/test-artifact-module-a" );
529 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
531 assertEquals( "1.1", metadata.getId() );
533 MavenProjectFacet facet = ( MavenProjectFacet ) metadata.getFacet( MavenProjectFacet.FACET_ID );
534 assertNotNull( facet );
535 assertEquals( "com.example.test", facet.getGroupId() );
536 assertEquals( "missing-parent", facet.getArtifactId() );
537 assertEquals( "jar", facet.getPackaging() );
539 List<String> paths = new ArrayList<String>();
540 paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
541 paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
542 paths.add( "target/test-repository/com/example/test/test-artifact-root" );
544 deleteTestArtifactWithParent( paths );
548 public void testGetProjectVersionMetadataWithParentSnapshotVersion()
551 copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
552 "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
554 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
555 "test-snapshot-artifact-module-a", "1.1-SNAPSHOT" );
557 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
558 assertEquals( "jar", facet.getPackaging() );
559 assertEquals( "com.example.test", facet.getParent().getGroupId() );
560 assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
561 assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
562 assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
563 assertEquals( "com.example.test", facet.getGroupId() );
564 assertNull( metadata.getCiManagement() );
565 assertNotNull( metadata.getDescription() );
567 checkApacheLicense( metadata );
569 assertEquals( "1.1-SNAPSHOT", metadata.getId() );
570 assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
571 String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
572 assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
573 assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
574 assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
576 List<Dependency> dependencies = metadata.getDependencies();
577 assertEquals( 2, dependencies.size() );
578 assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
579 assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
581 List<String> paths = new ArrayList<String>();
582 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
583 paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
585 deleteTestArtifactWithParent( paths );
588 // Tests for MRM-1411 - END
591 public void testGetRootNamespaces()
593 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
597 public void testGetNamespaces()
599 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
600 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
601 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "com.example.test",
604 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
605 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
606 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva",
608 assertEquals( Arrays.asList( "plugins", "shared" ), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven",
610 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins",
612 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared",
615 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
616 assertEquals( Collections.<String>emptyList(), storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus",
621 public void testGetProjects()
623 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
624 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
625 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
626 "missing-metadata", "missing-parent", "test-artifact" ), storage.listProjects( TEST_REPO_ID,
630 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
631 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
632 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
633 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
634 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
635 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins",
637 assertEquals( Arrays.asList( "maven-downloader" ), storage.listProjects( TEST_REPO_ID,
638 "org.apache.maven.shared", ALL ) );
642 public void testGetProjectVersions()
644 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
645 "incomplete-metadata", ALL ) );
646 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
647 "malformed-metadata", ALL ) );
648 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
649 "missing-metadata", ALL ) );
650 assertEquals( Arrays.asList( "1.0" ), storage.listProjectVersions( TEST_REPO_ID, "com.example.test",
651 "invalid-pom", ALL ) );
653 assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache",
656 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), storage.listProjectVersions( TEST_REPO_ID,
657 "org.apache.archiva", "archiva",
659 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
660 "archiva-base", ALL ) );
661 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
662 "archiva-common", ALL ) );
663 assertEquals( Arrays.asList( "1.2.1" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
664 "archiva-modules", ALL ) );
665 assertEquals( Arrays.asList( "3" ), storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
666 "archiva-parent", ALL ) );
668 assertEquals( Collections.<String>emptyList(), storage.listProjectVersions( TEST_REPO_ID,
669 "org.apache.maven.shared",
670 "maven-downloader", ALL ) );
674 public void testGetArtifacts()
676 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
677 "org.codehaus.plexus",
681 assertEquals( 3, artifacts.size() );
682 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
684 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
686 return o1.getId().compareTo( o2.getId() );
690 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
691 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
692 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
693 "f83aa25f016212a551a4b2249985effc" );
697 public void testGetArtifactsFiltered()
699 ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
700 "plexus-spring-1.2.pom" ) );
701 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
702 "org.codehaus.plexus",
706 assertEquals( 2, artifacts.size() );
707 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
709 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
711 return o1.getId().compareTo( o2.getId() );
715 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
716 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
720 public void testGetArtifactsTimestampedSnapshots()
722 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata( TEST_REPO_ID,
727 assertEquals( 1, artifacts.size() );
729 ArtifactMetadata artifact = artifacts.get( 0 );
730 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
731 assertEquals( "com.example.test", artifact.getNamespace() );
732 assertEquals( "missing-metadata", artifact.getProject() );
733 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
734 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
737 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
739 assertEquals( id, artifact.getId() );
740 assertEquals( md5, artifact.getMd5() );
741 assertEquals( sha1, artifact.getSha1() );
742 assertEquals( size, artifact.getSize() );
743 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
744 assertEquals( "plexus-spring", artifact.getProject() );
745 assertEquals( "1.2", artifact.getVersion() );
746 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
749 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
750 String unsubscribe, List<String> otherArchives, boolean allowPost )
752 assertEquals( archive, mailingList.getMainArchiveUrl() );
755 assertEquals( post, mailingList.getPostAddress() );
759 assertNull( mailingList.getPostAddress() );
761 assertEquals( subscribe, mailingList.getSubscribeAddress() );
762 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
763 assertEquals( name, mailingList.getName() );
764 assertEquals( otherArchives, mailingList.getOtherArchives() );
767 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
770 List<String> otherArchives = new ArrayList<String>();
771 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
772 if ( nabbleUrl != null )
774 otherArchives.add( nabbleUrl );
776 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
777 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
778 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
779 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
782 private void checkApacheLicense( ProjectVersionMetadata metadata )
784 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
785 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
786 metadata.getLicenses() );
789 private void checkOrganizationApache( ProjectVersionMetadata metadata )
791 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
792 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
795 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
798 for( String path : pathsToBeDeleted )
800 File dir = new File( FileUtil.getBasedir(), path );
801 FileUtils.deleteDirectory( dir );
803 assertFalse( dir.exists() );
805 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
806 File parentPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
807 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
809 FileUtils.deleteDirectory( dest );
810 FileUtils.deleteDirectory( parentPom );
811 FileUtils.deleteDirectory( rootPom );
813 assertFalse( dest.exists() );
814 assertFalse( parentPom.exists() );
815 assertFalse( rootPom.exists() );
818 private File copyTestArtifactWithParent( String srcPath, String destPath )
821 File src = new File( FileUtil.getBasedir(), srcPath );
822 File dest = new File( FileUtil.getBasedir(), destPath );
824 FileUtils.copyDirectory( src, dest );
825 assertTrue( dest.exists() );