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 java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
27 import org.apache.archiva.metadata.model.Dependency;
28 import org.apache.archiva.metadata.model.License;
29 import org.apache.archiva.metadata.model.MailingList;
30 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
31 import org.apache.archiva.metadata.repository.MetadataResolver;
32 import org.apache.archiva.metadata.repository.MetadataResolverException;
33 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
34 import org.apache.maven.archiva.configuration.Configuration;
35 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
36 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
38 public class Maven2RepositoryMetadataResolverTest
39 extends PlexusInSpringTestCase
41 private Maven2RepositoryMetadataResolver resolver;
43 private static final String TEST_REPO_ID = "test";
45 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
47 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
49 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
56 ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
57 Configuration c = new Configuration();
58 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
59 testRepo.setId( TEST_REPO_ID );
60 testRepo.setLocation( getTestPath( "src/test/repositories/test" ) );
61 c.addManagedRepository( testRepo );
62 configuration.save( c );
64 resolver = (Maven2RepositoryMetadataResolver) lookup( MetadataResolver.class, "maven2" );
67 public void testGetProjectVersionMetadata()
68 throws MetadataResolverException
70 ProjectVersionMetadata metadata =
71 resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
72 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
73 assertEquals( "jar", facet.getPackaging() );
74 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
75 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
76 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
77 assertEquals( "1.2.1", facet.getParent().getVersion() );
78 assertEquals( "archiva-common", facet.getArtifactId() );
79 assertEquals( "org.apache.archiva", facet.getGroupId() );
80 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
81 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
82 assertNotNull( metadata.getDescription() );
83 // TODO: this would be better
85 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
86 // metadata.getDescription() );
87 assertEquals( "1.2.1", metadata.getId() );
88 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
89 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
90 checkApacheLicense( metadata );
91 assertEquals( "Archiva Base :: Common", metadata.getName() );
92 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
93 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
94 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
95 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
96 checkOrganizationApache( metadata );
98 assertEquals( 4, metadata.getMailingLists().size() );
99 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
100 "http://www.nabble.com/archiva-users-f16426.html" );
101 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
102 "http://www.nabble.com/archiva-dev-f16427.html" );
103 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
104 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
105 "http://www.nabble.com/Archiva---Issues-f29617.html" );
107 List<Dependency> dependencies = metadata.getDependencies();
108 assertEquals( 10, dependencies.size() );
109 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
110 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
111 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
112 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
113 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
114 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
115 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
116 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
117 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
118 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
121 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
123 assertDependency( dependency, groupId, artifactId, version, "compile" );
126 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
129 assertEquals( artifactId, dependency.getArtifactId() );
130 assertEquals( "jar", dependency.getType() );
131 assertEquals( version, dependency.getVersion() );
132 assertEquals( groupId, dependency.getGroupId() );
133 assertEquals( scope, dependency.getScope() );
134 assertNull( dependency.getClassifier() );
135 assertNull( dependency.getSystemPath() );
138 public void testGetProjectVersionMetadataForTimestampedSnapshot()
139 throws MetadataResolverException
141 ProjectVersionMetadata metadata =
142 resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
143 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
144 assertEquals( "pom", facet.getPackaging() );
145 assertEquals( "http://www.apache.org/", metadata.getUrl() );
146 assertNull( facet.getParent() );
147 assertEquals( "org.apache", facet.getGroupId() );
148 assertEquals( "apache", facet.getArtifactId() );
149 assertNull( metadata.getCiManagement() );
150 assertNotNull( metadata.getDescription() );
151 // TODO: this would be better
153 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
154 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
155 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
156 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
157 // "developers and users.", metadata.getDescription() );
158 assertEquals( "5-SNAPSHOT", metadata.getId() );
159 assertNull( metadata.getIssueManagement() );
160 checkApacheLicense( metadata );
161 assertEquals( "The Apache Software Foundation", metadata.getName() );
162 String path = "maven/pom/trunk/asf";
163 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
164 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
165 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
166 checkOrganizationApache( metadata );
167 assertEquals( 1, metadata.getMailingLists().size() );
168 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
169 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
170 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
171 Collections.<String>emptyList(), true );
172 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
175 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
176 throws MetadataResolverException
178 ProjectVersionMetadata metadata =
179 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );
180 assertNull( metadata );
183 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
184 throws MetadataResolverException
186 ProjectVersionMetadata metadata =
187 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" );
188 assertNull( metadata );
191 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
192 throws MetadataResolverException
194 ProjectVersionMetadata metadata =
195 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" );
196 assertNull( metadata );
199 public void testGetProjectVersionMetadataForInvalidPom()
203 ProjectVersionMetadata metadata =
204 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
206 fail( "Expected failure, but received metadata: " + metadata );
208 catch ( MetadataResolverException e )
214 public void testGetProjectVersionMetadataForMissingPom()
215 throws MetadataResolverException
217 ProjectVersionMetadata metadata =
218 resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
219 assertNull( metadata );
223 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
224 String unsubscribe, List<String> otherArchives, boolean allowPost )
226 assertEquals( archive, mailingList.getMainArchiveUrl() );
229 assertEquals( post, mailingList.getPostAddress() );
233 assertNull( mailingList.getPostAddress() );
235 assertEquals( subscribe, mailingList.getSubscribeAddress() );
236 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
237 assertEquals( name, mailingList.getName() );
238 assertEquals( otherArchives, mailingList.getOtherArchives() );
241 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
244 List<String> otherArchives = new ArrayList<String>();
245 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
246 if ( nabbleUrl != null )
248 otherArchives.add( nabbleUrl );
250 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
251 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
252 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
253 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
256 private void checkApacheLicense( ProjectVersionMetadata metadata )
258 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
259 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
260 metadata.getLicenses() );
263 private void checkOrganizationApache( ProjectVersionMetadata metadata )
265 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
266 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );