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.Arrays;
24 import org.apache.archiva.metadata.model.License;
25 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
26 import org.apache.archiva.metadata.repository.MetadataResolver;
27 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
28 import org.apache.maven.archiva.configuration.Configuration;
29 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
32 public class Maven2RepositoryMetadataResolverTest
33 extends PlexusInSpringTestCase
35 private Maven2RepositoryMetadataResolver resolver;
37 private static final String TEST_REPO_ID = "test";
39 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
41 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
43 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
50 ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
51 Configuration c = new Configuration();
52 ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
53 testRepo.setId( TEST_REPO_ID );
54 testRepo.setLocation( getTestPath( "src/test/repositories/test" ) );
55 c.addManagedRepository( testRepo );
56 configuration.save( c );
58 resolver = (Maven2RepositoryMetadataResolver) lookup( MetadataResolver.class, "maven2" );
61 public void testGetProjectVersionMetadata()
63 ProjectVersionMetadata metadata =
64 resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
65 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
66 assertEquals( "jar", facet.getPackaging() );
67 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
68 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
69 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
70 assertEquals( "1.2.1", facet.getParent().getVersion() );
71 assertEquals( "archiva-common", facet.getArtifactId() );
72 assertEquals( "org.apache.archiva", facet.getGroupId() );
73 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
74 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
75 assertNotNull( metadata.getDescription() );
76 // TODO: this would be better
78 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
79 // metadata.getDescription() );
80 assertEquals( "1.2.1", metadata.getId() );
81 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
82 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
83 checkApacheLicense( metadata );
84 assertEquals( "Archiva Base :: Common", metadata.getName() );
85 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
86 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
87 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
88 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
89 checkOrganizationApache( metadata );
92 public void testGetProjectVersionMetadataForTimestampedSnapshot()
94 ProjectVersionMetadata metadata =
95 resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" );
96 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
97 assertEquals( "pom", facet.getPackaging() );
98 assertEquals( "http://www.apache.org/", metadata.getUrl() );
99 assertNull( facet.getParent() );
100 assertEquals( "org.apache", facet.getGroupId() );
101 assertEquals( "apache", facet.getArtifactId() );
102 assertNull( metadata.getCiManagement() );
103 assertNotNull( metadata.getDescription() );
104 // TODO: this would be better
106 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
107 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
108 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
109 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
110 // "developers and users.", metadata.getDescription() );
111 assertEquals( "5-SNAPSHOT", metadata.getId() );
112 assertNull( metadata.getIssueManagement() );
113 checkApacheLicense( metadata );
114 assertEquals( "The Apache Software Foundation", metadata.getName() );
115 String path = "maven/pom/trunk/asf";
116 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
117 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
118 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
119 checkOrganizationApache( metadata );
122 private void checkApacheLicense( ProjectVersionMetadata metadata )
124 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
125 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
126 metadata.getLicenses() );
129 private void checkOrganizationApache( ProjectVersionMetadata metadata )
131 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
132 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );