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.model.maven2.MavenArtifactFacet;
35 import org.apache.archiva.metadata.repository.filter.AllFilter;
36 import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
37 import org.apache.archiva.metadata.repository.filter.Filter;
38 import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
39 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
40 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
41 import org.apache.archiva.proxy.common.WagonFactory;
42 import org.apache.archiva.proxy.common.WagonFactoryRequest;
43 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
44 import org.apache.commons.io.FileUtils;
45 import org.apache.maven.wagon.Wagon;
46 import org.junit.Before;
47 import org.junit.Test;
48 import org.junit.runner.RunWith;
49 import org.springframework.test.context.ContextConfiguration;
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 import static org.mockito.Mockito.mock;
63 import static org.mockito.Mockito.when;
65 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
66 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
67 public class Maven2RepositoryMetadataResolverTest
70 private static final Filter<String> ALL = new AllFilter<String>();
73 @Named ( "repositoryStorage#maven2" )
74 private Maven2RepositoryStorage storage;
76 private static final String TEST_REPO_ID = "test";
78 private static final String TEST_REMOTE_REPO_ID = "central";
80 private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
82 private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
84 private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
86 private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
88 private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
90 private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
92 private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
94 private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
97 @Named ( "archivaConfiguration#default" )
98 protected ArchivaConfiguration configuration;
100 private WagonFactory wagonFactory;
102 ManagedRepositoryConfiguration testRepo;
113 c = new Configuration();
114 testRepo = new ManagedRepositoryConfiguration();
115 testRepo.setId( TEST_REPO_ID );
116 testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
117 testRepo.setReleases( true );
118 testRepo.setSnapshots( true );
119 c.addManagedRepository( testRepo );
121 RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
122 testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
123 testRemoteRepo.setLayout( "default" );
124 testRemoteRepo.setName( "Central Repository" );
125 testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
126 testRemoteRepo.setTimeout( 10 );
127 c.addRemoteRepository( testRemoteRepo );
129 ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
130 proxyConnector.setSourceRepoId( TEST_REPO_ID );
131 proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
132 proxyConnector.setDisabled( false );
133 c.addProxyConnector( proxyConnector );
135 configuration.save( c );
137 assertTrue( c.getManagedRepositories().get( 0 ).isSnapshots() );
138 assertTrue( c.getManagedRepositories().get( 0 ).isReleases() );
140 wagonFactory = mock( WagonFactory.class );
142 storage.setWagonFactory( wagonFactory );
144 Wagon wagon = new MockWagon();
145 when( wagonFactory.getWagon( new WagonFactoryRequest().protocol( "wagon#http" ) ) ).thenReturn( wagon );
149 public void testModelWithJdkProfileActivation()
152 ReadMetadataRequest readMetadataRequest =
153 new ReadMetadataRequest().repositoryId( TEST_REPO_ID ).namespace( "org.apache.maven" ).projectId(
154 "maven-archiver" ).projectVersion( "2.4.1" );
155 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
156 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
160 public void testGetProjectVersionMetadata()
163 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
164 new ReadMetadataRequest( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" ) );
165 MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
166 assertEquals( "jar", facet.getPackaging() );
167 assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
168 assertEquals( "org.apache.archiva", facet.getParent().getGroupId() );
169 assertEquals( "archiva-base", facet.getParent().getArtifactId() );
170 assertEquals( "1.2.1", facet.getParent().getVersion() );
171 assertEquals( "archiva-common", facet.getArtifactId() );
172 assertEquals( "org.apache.archiva", facet.getGroupId() );
173 assertEquals( "continuum", metadata.getCiManagement().getSystem() );
174 assertEquals( "http://vmbuild.apache.org/continuum", metadata.getCiManagement().getUrl() );
175 assertNotNull( metadata.getDescription() );
176 // TODO: this would be better
178 // "Archiva is an application for managing one or more remote repositories, including administration, artifact handling, browsing and searching.",
179 // metadata.getDescription() );
180 assertEquals( "1.2.1", metadata.getId() );
181 assertEquals( "jira", metadata.getIssueManagement().getSystem() );
182 assertEquals( "http://jira.codehaus.org/browse/MRM", metadata.getIssueManagement().getUrl() );
183 checkApacheLicense( metadata );
184 assertEquals( "Archiva Base :: Common", metadata.getName() );
185 String path = "archiva/tags/archiva-1.2.1/archiva-modules/archiva-base/archiva-common";
186 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
187 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
188 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
189 checkOrganizationApache( metadata );
191 assertEquals( 4, metadata.getMailingLists().size() );
192 assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
193 "http://www.nabble.com/archiva-users-f16426.html" );
194 assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
195 "http://www.nabble.com/archiva-dev-f16427.html" );
196 assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
197 assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
198 "http://www.nabble.com/Archiva---Issues-f29617.html" );
200 List<Dependency> dependencies = metadata.getDependencies();
201 assertEquals( 10, dependencies.size() );
202 assertDependency( dependencies.get( 0 ), "commons-lang", "commons-lang", "2.2" );
203 assertDependency( dependencies.get( 1 ), "commons-io", "commons-io", "1.4" );
204 assertDependency( dependencies.get( 2 ), "org.slf4j", "slf4j-api", "1.5.0" );
205 assertDependency( dependencies.get( 3 ), "org.codehaus.plexus", "plexus-component-api", "1.0-alpha-22" );
206 assertDependency( dependencies.get( 4 ), "org.codehaus.plexus", "plexus-spring", "1.2", "test" );
207 assertDependency( dependencies.get( 5 ), "xalan", "xalan", "2.7.0" );
208 assertDependency( dependencies.get( 6 ), "dom4j", "dom4j", "1.6.1", "test" );
209 assertDependency( dependencies.get( 7 ), "junit", "junit", "3.8.1", "test" );
210 assertDependency( dependencies.get( 8 ), "easymock", "easymock", "1.2_Java1.3", "test" );
211 assertDependency( dependencies.get( 9 ), "easymock", "easymockclassextension", "1.2", "test" );
213 assertEquals( 8, metadata.getProperties().size() );
214 assertEquals( "http://www.apache.org/images/asf_logo_wide.gif", metadata.getProperties().get("organization.logo") );
218 public void testGetArtifactMetadata()
221 Collection<ArtifactMetadata> springArtifacts = storage.readArtifactsMetadata(
222 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
223 List<ArtifactMetadata> artifacts = new ArrayList<>( springArtifacts );
224 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
227 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
229 return o1.getId().compareTo( o2.getId() );
233 assertEquals( 3, artifacts.size() );
235 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
236 assertEquals( "plexus-spring-1.2-sources.jar", artifactMetadata.getId() );
237 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
238 assertEquals( 0, facet.getBuildNumber() );
239 assertNull( facet.getTimestamp() );
240 assertEquals( "sources", facet.getClassifier() );
241 assertEquals( "java-source", facet.getType() );
243 artifactMetadata = artifacts.get( 1 );
244 assertEquals( "plexus-spring-1.2.jar", artifactMetadata.getId() );
245 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
246 assertEquals( 0, facet.getBuildNumber() );
247 assertNull( facet.getTimestamp() );
248 assertNull( facet.getClassifier() );
249 assertEquals( "jar", facet.getType() );
251 artifactMetadata = artifacts.get( 2 );
252 assertEquals( "plexus-spring-1.2.pom", artifactMetadata.getId() );
253 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
254 assertEquals( 0, facet.getBuildNumber() );
255 assertNull( facet.getTimestamp() );
256 assertNull( facet.getClassifier() );
257 assertEquals( "pom", facet.getType() );
261 public void testGetArtifactMetadataSnapshots()
264 Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(
265 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL ) );
266 List<ArtifactMetadata> artifacts = new ArrayList<>( testArtifacts );
267 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
270 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
272 return o1.getId().compareTo( o2.getId() );
276 assertEquals( 6, artifacts.size() );
278 ArtifactMetadata artifactMetadata = artifacts.get( 0 );
279 assertEquals( "test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId() );
280 MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
281 assertEquals( 1, facet.getBuildNumber() );
282 assertEquals( "20100308.230825", facet.getTimestamp() );
283 assertNull( facet.getClassifier() );
284 assertEquals( "jar", facet.getType() );
286 artifactMetadata = artifacts.get( 1 );
287 assertEquals( "test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId() );
288 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
289 assertEquals( 1, facet.getBuildNumber() );
290 assertEquals( "20100308.230825", facet.getTimestamp() );
291 assertNull( facet.getClassifier() );
292 assertEquals( "pom", facet.getType() );
294 artifactMetadata = artifacts.get( 2 );
295 assertEquals( "test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId() );
296 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
297 assertEquals( 2, facet.getBuildNumber() );
298 assertEquals( "20100310.014828", facet.getTimestamp() );
299 assertEquals( "javadoc", facet.getClassifier() );
300 assertEquals( "javadoc", facet.getType() );
302 artifactMetadata = artifacts.get( 3 );
303 assertEquals( "test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId() );
304 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
305 assertEquals( 2, facet.getBuildNumber() );
306 assertEquals( "20100310.014828", facet.getTimestamp() );
307 assertEquals( "sources", facet.getClassifier() );
308 assertEquals( "java-source", facet.getType() );
310 artifactMetadata = artifacts.get( 4 );
311 assertEquals( "test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId() );
312 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
313 assertEquals( 2, facet.getBuildNumber() );
314 assertEquals( "20100310.014828", facet.getTimestamp() );
315 assertNull( facet.getClassifier() );
316 assertEquals( "jar", facet.getType() );
318 artifactMetadata = artifacts.get( 5 );
319 assertEquals( "test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId() );
320 facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
321 assertEquals( 2, facet.getBuildNumber() );
322 assertEquals( "20100310.014828", facet.getTimestamp() );
323 assertNull( facet.getClassifier() );
324 assertEquals( "pom", facet.getType() );
327 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
329 assertDependency( dependency, groupId, artifactId, version, "compile" );
332 private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
335 assertEquals( artifactId, dependency.getArtifactId() );
336 assertEquals( "jar", dependency.getType() );
337 assertEquals( version, dependency.getVersion() );
338 assertEquals( groupId, dependency.getGroupId() );
339 assertEquals( scope, dependency.getScope() );
340 assertNull( dependency.getClassifier() );
341 assertNull( dependency.getSystemPath() );
345 public void testGetProjectVersionMetadataForTimestampedSnapshot()
348 ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(
349 new ReadMetadataRequest( TEST_REPO_ID, "org.apache", "apache", "5-SNAPSHOT" ) );
350 MavenProjectFacet facet = MavenProjectFacet.class.cast( metadata.getFacet( MavenProjectFacet.FACET_ID ) );
351 assertEquals( "pom", facet.getPackaging() );
352 assertEquals( "http://www.apache.org/", metadata.getUrl() );
353 assertNull( facet.getParent() );
354 assertEquals( "org.apache", facet.getGroupId() );
355 assertEquals( "apache", facet.getArtifactId() );
356 assertNull( metadata.getCiManagement() );
357 assertNotNull( metadata.getDescription() );
358 // TODO: this would be better
360 // "The Apache Software Foundation provides support for the Apache community of open-source software projects. " +
361 // "The Apache projects are characterized by a collaborative, consensus based development process, an open " +
362 // "and pragmatic software license, and a desire to create high quality software that leads the way in its " +
363 // "field. We consider ourselves not simply a group of projects sharing a server, but rather a community of " +
364 // "developers and users.", metadata.getDescription() );
365 assertEquals( "5-SNAPSHOT", metadata.getId() );
366 assertNull( metadata.getIssueManagement() );
367 checkApacheLicense( metadata );
368 assertEquals( "The Apache Software Foundation", metadata.getName() );
369 String path = "maven/pom/trunk/asf";
370 assertEquals( ASF_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
371 assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
372 assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
373 checkOrganizationApache( metadata );
374 assertEquals( 1, metadata.getMailingLists().size() );
375 assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
376 "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
377 "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
378 Collections.<String>emptyList(), true );
379 assertEquals( Collections.<Dependency>emptyList(), metadata.getDependencies() );
383 public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
388 storage.readProjectVersionMetadata(
389 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" ) );
390 fail( "Should not be found" );
392 catch ( RepositoryStorageMetadataNotFoundException e )
394 assertEquals( "missing-pom", e.getId() );
399 public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
404 storage.readProjectVersionMetadata(
405 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "malformed-metadata", "1.0-SNAPSHOT" ) );
406 fail( "Should not be found" );
408 catch ( RepositoryStorageMetadataNotFoundException e )
410 assertEquals( "missing-pom", e.getId() );
415 public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
420 storage.readProjectVersionMetadata(
421 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "incomplete-metadata", "1.0-SNAPSHOT" ) );
422 fail( "Should not be found" );
424 catch ( RepositoryStorageMetadataNotFoundException e )
426 assertEquals( "missing-pom", e.getId() );
431 public void testGetProjectVersionMetadataForInvalidPom()
436 storage.readProjectVersionMetadata(
437 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" ) );
438 fail( "Should have received an exception due to invalid POM" );
440 catch ( RepositoryStorageMetadataInvalidException e )
442 assertEquals( "invalid-pom", e.getId() );
447 public void testGetProjectVersionMetadataForMislocatedPom()
452 storage.readProjectVersionMetadata(
453 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" ) );
454 fail( "Should have received an exception due to mislocated POM" );
456 catch ( RepositoryStorageMetadataInvalidException e )
458 assertEquals( "mislocated-pom", e.getId() );
463 public void testGetProjectVersionMetadataForMissingPom()
468 storage.readProjectVersionMetadata(
469 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" ) );
470 fail( "Should not be found" );
472 catch ( RepositoryStorageMetadataNotFoundException e )
474 assertEquals( "missing-pom", e.getId() );
479 public void testGetRootNamespaces()
482 assertEquals( Arrays.asList( "com", "org" ), storage.listRootNamespaces( TEST_REPO_ID, ALL ) );
486 public void testGetNamespaces()
489 assertEquals( Arrays.asList( "example" ), storage.listNamespaces( TEST_REPO_ID, "com", ALL ) );
490 assertEquals( Arrays.asList( "test" ), storage.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
491 assertEquals( Collections.<String>emptyList(),
492 storage.listNamespaces( TEST_REPO_ID, "com.example.test", ALL ) );
494 assertEquals( Arrays.asList( "apache", "codehaus" ), storage.listNamespaces( TEST_REPO_ID, "org", ALL ) );
495 assertEquals( Arrays.asList( "archiva", "maven" ), storage.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
496 assertEquals( Collections.<String>emptyList(),
497 storage.listNamespaces( TEST_REPO_ID, "org.apache.archiva", ALL ) );
498 assertEquals( Arrays.asList( "plugins", "shared" ),
499 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven", ALL ) );
500 assertEquals( Collections.<String>emptyList(),
501 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
502 assertEquals( Collections.<String>emptyList(),
503 storage.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
505 assertEquals( Arrays.asList( "plexus" ), storage.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
506 assertEquals( Collections.<String>emptyList(),
507 storage.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus", ALL ) );
511 public void testGetProjects()
514 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com", ALL ) );
515 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "com.example", ALL ) );
516 assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
517 "missing-metadata", "missing-parent", "test-artifact" ),
518 storage.listProjects( TEST_REPO_ID, "com.example.test", ALL ) );
520 assertEquals( Collections.<String>emptyList(), storage.listProjects( TEST_REPO_ID, "org", ALL ) );
521 assertEquals( Arrays.asList( "apache" ), storage.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
522 assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
523 storage.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
524 assertEquals( Arrays.asList( "maven-archiver", "maven-parent" ),
525 storage.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
526 assertEquals( Collections.<String>emptyList(),
527 storage.listProjects( TEST_REPO_ID, "org.apache.maven.plugins", ALL ) );
528 assertEquals( Arrays.asList( "maven-downloader", "maven-shared-components" ),
529 storage.listProjects( TEST_REPO_ID, "org.apache.maven.shared", ALL ) );
533 public void testGetProjectVersions()
536 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
537 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "incomplete-metadata", ALL ) );
538 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
539 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "malformed-metadata", ALL ) );
540 assertEquals( Arrays.asList( "1.0-SNAPSHOT" ),
541 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "missing-metadata", ALL ) );
542 assertEquals( Arrays.asList( "1.0" ),
543 storage.listProjectVersions( TEST_REPO_ID, "com.example.test", "invalid-pom", ALL ) );
545 assertEquals( Arrays.asList( "4", "5-SNAPSHOT", "7" ),
546 storage.listProjectVersions( TEST_REPO_ID, "org.apache", "apache", ALL ) );
548 assertEquals( Arrays.asList( "1.2.1", "1.2.2" ),
549 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva", ALL ) );
550 assertEquals( Arrays.asList( "1.2.1" ),
551 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-base", ALL ) );
552 assertEquals( Arrays.asList( "1.2.1" ),
553 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-common", ALL ) );
554 assertEquals( Arrays.asList( "1.2.1" ),
555 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-modules", ALL ) );
556 assertEquals( Arrays.asList( "3" ),
557 storage.listProjectVersions( TEST_REPO_ID, "org.apache.archiva", "archiva-parent", ALL ) );
559 assertEquals( Collections.<String>emptyList(),
560 storage.listProjectVersions( TEST_REPO_ID, "org.apache.maven.shared", "maven-downloader", ALL ) );
564 public void testGetArtifacts()
567 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
568 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) ) );
569 assertEquals( 3, artifacts.size() );
570 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
573 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
575 return o1.getId().compareTo( o2.getId() );
579 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
580 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
581 assertArtifact( artifacts.get( 2 ), "plexus-spring-1.2.pom", 7407, "96b14cf880e384b2d15e8193c57b65c5420ca4c5",
582 "f83aa25f016212a551a4b2249985effc" );
586 public void testGetArtifactsFiltered()
589 ExcludesFilter<String> filter =
590 new ExcludesFilter<String>( Collections.singletonList( "plexus-spring-1.2.pom" ) );
591 List<ArtifactMetadata> artifacts = new ArrayList<>( storage.readArtifactsMetadata(
592 new ReadMetadataRequest( TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) ) );
593 assertEquals( 2, artifacts.size() );
594 Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
597 public int compare( ArtifactMetadata o1, ArtifactMetadata o2 )
599 return o1.getId().compareTo( o2.getId() );
603 assertArtifact( artifacts.get( 0 ), "plexus-spring-1.2-sources.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
604 assertArtifact( artifacts.get( 1 ), "plexus-spring-1.2.jar", 0, EMPTY_SHA1, EMPTY_MD5 );
608 public void testGetArtifactsTimestampedSnapshots()
611 List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( storage.readArtifactsMetadata(
612 new ReadMetadataRequest( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) ) );
613 assertEquals( 1, artifacts.size() );
615 ArtifactMetadata artifact = artifacts.get( 0 );
616 assertEquals( "missing-metadata-1.0-20091101.112233-1.pom", artifact.getId() );
617 assertEquals( "com.example.test", artifact.getNamespace() );
618 assertEquals( "missing-metadata", artifact.getProject() );
619 assertEquals( "1.0-20091101.112233-1", artifact.getVersion() );
620 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
623 private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
625 assertEquals( id, artifact.getId() );
626 assertEquals( md5, artifact.getMd5() );
627 assertEquals( sha1, artifact.getSha1() );
628 assertEquals( size, artifact.getSize() );
629 assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
630 assertEquals( "plexus-spring", artifact.getProject() );
631 assertEquals( "1.2", artifact.getVersion() );
632 assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
635 private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
636 String unsubscribe, List<String> otherArchives, boolean allowPost )
638 assertEquals( archive, mailingList.getMainArchiveUrl() );
641 assertEquals( post, mailingList.getPostAddress() );
645 assertNull( mailingList.getPostAddress() );
647 assertEquals( subscribe, mailingList.getSubscribeAddress() );
648 assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
649 assertEquals( name, mailingList.getName() );
650 assertEquals( otherArchives, mailingList.getOtherArchives() );
653 private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
656 List<String> otherArchives = new ArrayList<>();
657 otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
658 if ( nabbleUrl != null )
660 otherArchives.add( nabbleUrl );
662 otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
663 assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
664 prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
665 prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
668 private void checkApacheLicense( ProjectVersionMetadata metadata )
670 assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
671 "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
672 metadata.getLicenses() );
675 private void checkOrganizationApache( ProjectVersionMetadata metadata )
677 assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
678 assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
681 private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
684 for ( String path : pathsToBeDeleted )
686 File dir = new File( FileUtil.getBasedir(), path );
687 FileUtils.deleteDirectory( dir );
689 assertFalse( dir.exists() );
691 File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
693 new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
694 File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
696 FileUtils.deleteDirectory( dest );
697 FileUtils.deleteDirectory( parentPom );
698 FileUtils.deleteDirectory( rootPom );
700 assertFalse( dest.exists() );
701 assertFalse( parentPom.exists() );
702 assertFalse( rootPom.exists() );
705 private File copyTestArtifactWithParent( String srcPath, String destPath )
708 File src = new File( FileUtil.getBasedir(), srcPath );
709 File dest = new File( FileUtil.getBasedir(), destPath );
711 FileUtils.copyDirectory( src, dest );
712 assertTrue( dest.exists() );