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.MetadataResolverException;
32 import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
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( StorageMetadataResolver.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 public void testGetRootNamespaces()
225 assertEquals( Arrays.asList( "com", "org" ), resolver.getRootNamespaces( TEST_REPO_ID ) );
228 public void testGetNamespaces()
230 assertEquals( Arrays.asList( "example" ), resolver.getNamespaces( TEST_REPO_ID, "com" ) );
231 assertEquals( Arrays.asList( "test" ), resolver.getNamespaces( TEST_REPO_ID, "com.example" ) );
232 assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "com.example.test" ) );
234 assertEquals( Arrays.asList( "apache", "codehaus" ), resolver.getNamespaces( TEST_REPO_ID, "org" ) );
235 assertEquals( Arrays.asList( "archiva", "maven" ), resolver.getNamespaces( TEST_REPO_ID, "org.apache" ) );
236 assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) );
237 assertEquals( Arrays.asList( "plugins", "shared" ),
238 resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
239 assertEquals( Collections.<String>emptyList(),
240 resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven.plugins" ) );
241 assertEquals( Collections.<String>emptyList(),
242 resolver.getNamespaces( TEST_REPO_ID, "org.apache.maven.shared" ) );
244 assertEquals( Arrays.asList( "plexus" ), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus" ) );
245 assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) );
248 public void testGetProjects()
250 assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com" ) );
251 assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com.example" ) );
252 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "missing-metadata" ),
253 resolver.getProjects( TEST_REPO_ID, "com.example.test" ) );
255 assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org" ) );
256 assertEquals( Arrays.asList( "apache" ), resolver.getProjects( TEST_REPO_ID, "org.apache" ) );
257 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
258 resolver.getProjects( TEST_REPO_ID, "org.apache.archiva" ) );
259 assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
260 assertEquals( Collections.<String>emptyList(),
261 resolver.getProjects( TEST_REPO_ID, "org.apache.maven.plugins" ) );
262 assertEquals( Arrays.asList( "maven-downloader" ),
263 resolver.getProjects( TEST_REPO_ID, "org.apache.maven.shared" ) );
266 public void testGetProjectVersions()
268 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
269 resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata" ) );
270 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
271 resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata" ) );
272 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
273 resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata" ) );
274 assertEquals( Arrays.asList( "1.0" ),
275 resolver.getProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom" ) );
277 assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ),
278 resolver.getProjectVersions( TEST_REPO_ID, "org.apache", "apache" ) );
280 assertEquals( Arrays.asList( "1.2.1" ),
281 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva" ) );
282 assertEquals( Arrays.asList( "1.2.1" ),
283 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base" ) );
284 assertEquals( Arrays.asList( "1.2.1" ),
285 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common" ) );
286 assertEquals( Arrays.asList( "1.2.1" ),
287 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules" ) );
288 assertEquals( Arrays.asList( "3" ),
289 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent" ) );
291 assertEquals( Collections.<String>emptyList(),
292 resolver.getProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader" ) );
295 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
296 String unsubscribe, List<String> otherArchives, boolean allowPost )
298 assertEquals( archive, mailingList.getMainArchiveUrl() );
301 assertEquals( post, mailingList.getPostAddress() );
305 assertNull( mailingList.getPostAddress() );
307 assertEquals( subscribe, mailingList.getSubscribeAddress() );
308 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
309 assertEquals( name, mailingList.getName() );
310 assertEquals( otherArchives, mailingList.getOtherArchives() );
313 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
316 List<String> otherArchives = new ArrayList<String>();
317 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
318 if ( nabbleUrl != null )
320 otherArchives.add( nabbleUrl );
322 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
323 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
324 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
325 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
328 private void checkApacheLicense( ProjectVersionMetadata metadata )
330 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
331 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
332 metadata.getLicenses() );
335 private void checkOrganizationApache( ProjectVersionMetadata metadata )
337 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
338 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );