1 package org.apache.archiva.repository.maven.content;
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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.FileLockManager;
22 import org.apache.archiva.common.utils.VersionComparator;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.FileType;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.model.ArtifactReference;
27 import org.apache.archiva.model.ProjectReference;
28 import org.apache.archiva.model.VersionedReference;
29 import org.apache.archiva.repository.EditableManagedRepository;
30 import org.apache.archiva.repository.LayoutException;
31 import org.apache.archiva.repository.ManagedRepositoryContent;
32 import org.apache.archiva.repository.RepositoryContent;
33 import org.apache.archiva.repository.content.Artifact;
34 import org.apache.archiva.repository.content.BaseArtifactTypes;
35 import org.apache.archiva.repository.content.ItemSelector;
36 import org.apache.archiva.repository.content.Project;
37 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
38 import org.apache.archiva.repository.maven.MavenManagedRepository;
39 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
40 import org.apache.commons.io.FileUtils;
41 import org.junit.Before;
42 import org.junit.Test;
44 import javax.inject.Inject;
45 import javax.inject.Named;
46 import java.io.IOException;
47 import java.net.URISyntaxException;
48 import java.nio.file.Files;
49 import java.nio.file.Path;
50 import java.nio.file.Paths;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.Collections;
54 import java.util.List;
56 import java.util.stream.Collectors;
57 import java.util.stream.Stream;
59 import static org.junit.Assert.*;
62 * ManagedDefaultRepositoryContentTest
64 public class ManagedDefaultRepositoryContentTest
65 extends AbstractManagedRepositoryContentTest
67 private ManagedDefaultRepositoryContent repoContent;
73 @Named ( "archivaConfiguration#default" )
74 ArchivaConfiguration archivaConfiguration;
77 List<? extends ArtifactMappingProvider> artifactMappingProviders;
80 MavenContentHelper contentHelper;
83 FileLockManager fileLockManager;
85 private Path getRepositoryPath(String repoName) {
88 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
90 catch ( URISyntaxException e )
92 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
100 Path repoDir = getRepositoryPath( "default-repository" );
102 MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
104 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
105 fileType.addPattern( "**/*.xml" );
106 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
108 fileTypes.afterConfigurationChange( null, "fileType", null );
110 repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
111 repoContent.setMavenContentHelper( contentHelper );
113 //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
117 public void testGetVersionsBadArtifact()
120 assertGetVersions( "bad_artifact", Collections.emptyList() );
124 public void testGetVersionsMissingMultipleVersions()
127 assertGetVersions( "missing_metadata_b", Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) );
131 public void testGetVersionsSimple()
134 assertVersions( "proxied_multi", "2.1", new String[]{ "2.1" } );
138 public void testGetVersionsSimpleYetIncomplete()
141 assertGetVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) );
145 public void testGetVersionsSimpleYetMissing()
148 assertGetVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) );
152 public void testGetVersionsSnapshotA()
155 assertVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
156 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
157 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
158 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
159 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
163 public void testToMetadataPathFromProjectReference()
165 ProjectReference reference = new ProjectReference();
166 reference.setGroupId( "com.foo" );
167 reference.setArtifactId( "foo-tool" );
169 assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
173 public void testToMetadataPathFromVersionReference()
175 VersionedReference reference = new VersionedReference();
176 reference.setGroupId( "com.foo" );
177 reference.setArtifactId( "foo-tool" );
178 reference.setVersion( "1.0" );
180 assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
185 public void testToPathOnNullArtifactReference()
189 ArtifactReference reference = null;
190 repoContent.toPath( reference );
191 fail( "Should have failed due to null artifact reference." );
193 catch ( IllegalArgumentException e )
200 public void testExcludeMetadataFile()
203 assertVersions( "include_xml", "1.0", new String[]{ "1.0" } );
206 private void assertGetVersions( String artifactId, List<String> expectedVersions )
209 ProjectReference reference = new ProjectReference();
210 reference.setGroupId( "org.apache.archiva.metadata.tests" );
211 reference.setArtifactId( artifactId );
213 // Use the test metadata-repository, which is already setup for
214 // These kind of version tests.
215 Path repoDir = getRepositoryPath( "metadata-repository" );
216 (( EditableManagedRepository)repoContent.getRepository()).setLocation( repoDir.toAbsolutePath().toUri() );
218 // Request the versions.
219 Set<String> testedVersionSet = repoContent.getVersions( reference );
221 // Sort the list (for asserts)
222 VersionComparator comparator = new VersionComparator( );
223 List<String> testedVersions = new ArrayList<>();
224 testedVersions.addAll( testedVersionSet );
225 Collections.sort( testedVersions, comparator );
227 // Test the expected array of versions, to the actual tested versions
228 assertEquals( "available versions", expectedVersions, testedVersions );
230 ItemSelector selector = ArchivaItemSelector.builder( )
231 .withNamespace( "org.apache.archiva.metadata.tests" )
232 .withProjectId( artifactId )
234 Project project = repoContent.getProject( selector );
235 assertNotNull( project );
236 List<String> versions = repoContent.getVersions( project ).stream().map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
237 assertArrayEquals( expectedVersions.toArray(), versions.toArray( ) );
240 private void assertVersions( String artifactId, String version, String[] expectedVersions )
243 VersionedReference reference = new VersionedReference();
244 reference.setGroupId( "org.apache.archiva.metadata.tests" );
245 reference.setArtifactId( artifactId );
246 reference.setVersion( version );
248 // Use the test metadata-repository, which is already setup for
249 // These kind of version tests.
250 Path repoDir = getRepositoryPath( "metadata-repository" );
251 ((EditableManagedRepository)repoContent.getRepository()).setLocation( repoDir.toAbsolutePath().toUri() );
253 // Request the versions.
254 Set<String> testedVersionSet = repoContent.getVersions( reference );
256 // Sort the list (for asserts later)
257 final VersionComparator comparator = new VersionComparator( );
258 List<String> testedVersions = new ArrayList<>();
259 testedVersions.addAll( testedVersionSet );
260 Collections.sort( testedVersions, comparator );
262 // Test the expected array of versions, to the actual tested versions
263 assertEquals( "Assert Versions: length/size", expectedVersions.length, testedVersions.size() );
265 for ( int i = 0; i < expectedVersions.length; i++ )
267 String actualVersion = testedVersions.get( i );
268 assertEquals( "Versions[" + i + "]", expectedVersions[i], actualVersion );
272 ItemSelector selector = ArchivaItemSelector.builder( )
273 .withNamespace( "org.apache.archiva.metadata.tests" )
274 .withProjectId( artifactId )
275 .withVersion( version )
277 List<String> versions = repoContent.getVersions( selector ).stream()
278 .map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
279 assertArrayEquals( expectedVersions, versions.toArray( ) );
286 protected ArtifactReference toArtifactReference( String path )
287 throws LayoutException
289 return repoContent.toArtifactReference( path );
293 protected ItemSelector toItemSelector( String path ) throws LayoutException
295 return repoContent.toItemSelector( path );
299 protected String toPath( ArtifactReference reference )
301 return repoContent.toPath( reference );
305 protected String toPath( ItemSelector selector ) {
306 return repoContent.toPath( selector );
310 protected ManagedRepositoryContent getManaged( )
316 protected RepositoryContent getContent( )
321 private Path setupRepoCopy( String source, String target) throws IOException
323 Path defaultRepo = getRepositoryPath( source );
324 Path newRepo = defaultRepo.getParent( ).resolve( target );
325 FileUtils.copyDirectory( defaultRepo.toFile( ), newRepo.toFile( ) );
327 MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", newRepo );
329 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
330 fileType.addPattern( "**/*.xml" );
331 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
333 fileTypes.afterConfigurationChange( null, "fileType", null );
335 repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
341 public void testDeleteArtifactWithType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
343 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
344 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
345 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
346 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
347 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
348 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
350 ArtifactReference ref = new ArtifactReference( );
351 ref.setGroupId( "org.apache.maven" );
352 ref.setArtifactId( "samplejar" );
353 ref.setVersion( "1.0" );
354 ref.setType( "jar" );
356 repoContent.deleteArtifact( ref );
358 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
359 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
360 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
361 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
362 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
369 public void testDeleteArtifactWithClassifier() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
371 Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
372 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
373 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
374 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
375 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
376 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
377 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
379 ArtifactReference ref = new ArtifactReference( );
380 ref.setGroupId( "org.apache.maven" );
381 ref.setArtifactId( "samplejar" );
382 ref.setVersion( "1.0" );
383 ref.setClassifier( "source" );
384 ref.setType( "jar" );
386 repoContent.deleteArtifact( ref );
388 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
389 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
390 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
391 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
392 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
393 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
398 public void testDeleteArtifactWithoutType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
400 Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
401 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
402 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
403 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
404 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
405 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
406 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
408 ArtifactReference ref = new ArtifactReference( );
409 ref.setGroupId( "org.apache.maven" );
410 ref.setArtifactId( "samplejar" );
411 ref.setVersion( "1.0" );
413 repoContent.deleteArtifact( ref );
415 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
416 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) );
422 public void testDeleteVersion() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
424 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
425 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
426 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
427 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
428 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
429 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
431 VersionedReference ref = new VersionedReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" ).version( "1.0" );
433 repoContent.deleteVersion( ref );
435 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
440 public void testDeleteProject() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
442 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
443 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
444 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
445 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
446 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
447 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
449 ProjectReference ref = new ProjectReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" );
451 repoContent.deleteProject( ref );
453 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
458 public void testGetArtifactStreamWithVersionSelector() {
459 ItemSelector selector = ArchivaItemSelector.builder( )
460 .withNamespace( "javax.sql" )
461 .withProjectId( "jdbc" )
462 .withVersion( "2.0" ).build();
463 try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
465 assertNotNull( stream );
466 List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
467 checkArtifactListWithVersionSelector1( results );
472 public void testGetArtifactListWithVersionSelector() {
473 ItemSelector selector = ArchivaItemSelector.builder( )
474 .withNamespace( "javax.sql" )
475 .withProjectId( "jdbc" )
476 .withVersion( "2.0" ).build();
477 List<? extends Artifact> results = repoContent.getArtifacts( selector );
478 checkArtifactListWithVersionSelector1( results );
481 private void checkArtifactListWithVersionSelector1( List<? extends Artifact> results )
483 assertNotNull( results );
484 assertEquals( 2, results.size( ) );
485 Artifact mainArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "jdbc-2.0.jar" ) ).findFirst( ).get( );
486 assertNotNull( mainArtifact );
487 assertEquals( BaseArtifactTypes.MAIN, mainArtifact.getArtifactType( ) );
488 Artifact metaArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata-repository.xml" ) ).findFirst( ).get( );
489 assertNotNull( metaArtifact );
490 assertEquals( MavenTypes.REPOSITORY_METADATA, metaArtifact.getArtifactType( ) );
494 public void testGetArtifactStreamWithVersionSelector2() {
495 ItemSelector selector = ArchivaItemSelector.builder( )
496 .withNamespace( "org.apache.axis2" )
497 .withProjectId( "axis2" )
498 .withVersion( "1.3-SNAPSHOT" ).build();
499 try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
501 assertNotNull( stream );
502 List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
503 checkArtifactListWithVersionSelector2( results );
508 public void testGetArtifactListWithVersionSelector2() {
509 ItemSelector selector = ArchivaItemSelector.builder( )
510 .withNamespace( "org.apache.axis2" )
511 .withProjectId( "axis2" )
512 .withVersion( "1.3-SNAPSHOT" ).build();
513 List<? extends Artifact> results = repoContent.getArtifacts( selector );
514 checkArtifactListWithVersionSelector2( results );
517 private void checkArtifactListWithVersionSelector2( List<? extends Artifact> results )
519 assertNotNull( results );
520 assertEquals( 39, results.size( ) );
522 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom" ) )
523 .findFirst( ).get( );
525 assertNotNull( artifact );
526 assertEquals( "pom", artifact.getExtension( ) );
527 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
528 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
529 assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
530 assertEquals( ".pom", artifact.getRemainder( ) );
531 assertEquals( "axis2", artifact.getId( ) );
532 assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
533 assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
534 assertEquals( "", artifact.getClassifier( ) );
535 assertEquals( "pom", artifact.getType( ) );
538 artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom.md5" ) )
539 .findFirst( ).get( );
541 assertNotNull( artifact );
542 assertEquals( "md5", artifact.getExtension( ) );
543 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
544 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
545 assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
546 assertEquals( ".pom.md5", artifact.getRemainder( ) );
547 assertEquals( "axis2", artifact.getId( ) );
548 assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
549 assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
550 assertEquals( "", artifact.getClassifier( ) );
551 assertEquals( "md5", artifact.getType( ) );
555 artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata.xml" ) )
556 .findFirst( ).get( );
557 assertNotNull( artifact );
558 assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
559 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
560 assertEquals( "xml", artifact.getExtension( ) );
564 public void testGetArtifactListWithArtifactSelector1() {
565 ItemSelector selector = ArchivaItemSelector.builder( )
566 .withNamespace( "org.apache.axis2" )
567 .withProjectId( "axis2" )
568 .withVersion( "1.3-SNAPSHOT" )
569 .withArtifactVersion( "1.3-20070731.113304-21" )
570 .withExtension( "pom" )
572 List<? extends Artifact> results = repoContent.getArtifacts( selector );
573 checkArtifactListWithArtifactSelector1( results );
577 public void testGetArtifactStreamWithArtifactSelector1() {
578 ItemSelector selector = ArchivaItemSelector.builder( )
579 .withNamespace( "org.apache.axis2" )
580 .withProjectId( "axis2" )
581 .withVersion( "1.3-SNAPSHOT" )
582 .withArtifactVersion( "1.3-20070731.113304-21" )
583 .withExtension( "pom" )
585 try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
587 checkArtifactListWithArtifactSelector1( results.collect( Collectors.toList()) );
591 private void checkArtifactListWithArtifactSelector1( List<? extends Artifact> results )
593 assertNotNull( results );
594 assertEquals( 1, results.size( ) );
595 Artifact artifact = results.get( 0 );
596 assertEquals( "pom", artifact.getExtension( ) );
597 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
601 public void testGetArtifactListWithArtifactSelector2() {
602 ItemSelector selector = ArchivaItemSelector.builder( )
603 .withNamespace( "org.apache.axis2" )
604 .withProjectId( "axis2" )
605 .withVersion( "1.3-SNAPSHOT" )
606 .withArtifactVersion( "1.3-20070731.113304-21" )
607 .withExtension( "pom" )
608 .includeRelatedArtifacts()
610 List<? extends Artifact> results = repoContent.getArtifacts( selector );
612 checkArtifactListWithArtifactSelector2( results );
617 public void testGetArtifactStreamWithArtifactSelector2() {
618 ItemSelector selector = ArchivaItemSelector.builder( )
619 .withNamespace( "org.apache.axis2" )
620 .withProjectId( "axis2" )
621 .withVersion( "1.3-SNAPSHOT" )
622 .withArtifactVersion( "1.3-20070731.113304-21" )
623 .withExtension( "pom" )
624 .includeRelatedArtifacts()
626 try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
628 checkArtifactListWithArtifactSelector2( results.collect( Collectors.toList()) );
632 private void checkArtifactListWithArtifactSelector2( List<? extends Artifact> results )
634 assertNotNull( results );
635 assertEquals( 3, results.size( ) );
636 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom" ) )
637 .findFirst( ).get( );
638 assertNotNull( artifact );
639 assertEquals( "pom", artifact.getExtension( ) );
640 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
642 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom.sha1" ) )
643 .findFirst( ).get( );
644 assertNotNull( artifact );
645 assertEquals( "sha1", artifact.getExtension( ) );
646 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
651 public void testArtifactListWithProjectSelector() {
652 ItemSelector selector = ArchivaItemSelector.builder( )
653 .withNamespace( "org.apache.maven.shared" )
654 .withProjectId( "maven-downloader" )
656 List<? extends Artifact> results = repoContent.getArtifacts( selector );
657 checkArtifactListWithProjectSelector( results );
662 public void testArtifactStreamWithProjectSelector() {
663 ItemSelector selector = ArchivaItemSelector.builder( )
664 .withNamespace( "org.apache.maven.shared" )
665 .withProjectId( "maven-downloader" )
667 Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
668 checkArtifactListWithProjectSelector( results.collect( Collectors.toList()) );
672 private void checkArtifactListWithProjectSelector( List<? extends Artifact> results )
674 assertNotNull( results );
675 assertEquals( 27, results.size( ) );
677 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-metadata.xml" ) )
678 .findFirst( ).get( );
679 assertNotNull( artifact );
680 assertEquals( "xml", artifact.getExtension( ) );
681 assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
683 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar" ) )
684 .findFirst( ).get( );
685 assertNotNull( artifact );
686 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
687 assertEquals( "sources", artifact.getClassifier( ) );
688 assertEquals( "java-source", artifact.getType( ) );
690 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar.sha1" ) )
691 .findFirst( ).get( );
692 assertNotNull( artifact );
693 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
694 assertEquals( "sources", artifact.getClassifier( ) );
695 assertEquals( "sha1", artifact.getType( ) );
696 assertEquals( ".jar.sha1", artifact.getRemainder( ) );
700 public void testArtifactListWithNamespaceSelector() {
701 ItemSelector selector = ArchivaItemSelector.builder( )
702 .withNamespace( "org.multilevel" )
704 List<? extends Artifact> results = repoContent.getArtifacts( selector );
705 assertNotNull( results );
706 assertEquals( 3, results.size( ) );
707 assertTrue( results.get( 0 ).getFileName( ).startsWith( "testproj1" ) );
711 public void testArtifactListWithNamespaceSelectorRecursive() {
712 ItemSelector selector = ArchivaItemSelector.builder( )
713 .withNamespace( "org.multilevel" )
716 List<? extends Artifact> results = repoContent.getArtifacts( selector );
717 checkArtifactListWithNamespaceSelectorRecursive( results );
721 public void testArtifactStreamWithNamespaceSelectorRecursive() {
722 ItemSelector selector = ArchivaItemSelector.builder( )
723 .withNamespace( "org.multilevel" )
726 Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
727 checkArtifactListWithNamespaceSelectorRecursive( results.collect( Collectors.toList()) );
730 private void checkArtifactListWithNamespaceSelectorRecursive( List<? extends Artifact> results )
732 assertNotNull( results );
733 assertEquals( 6, results.size( ) );
735 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "testproj2-1.0.pom" ) )
736 .findFirst( ).get( );
737 assertNotNull( artifact );
738 assertEquals( 6, artifact.getAsset( ).getParent( ).getPath( ).split( "/" ).length );
740 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "testproj1-1.0.pom" ) )
741 .findFirst( ).get( );
742 assertNotNull( artifact );
743 assertEquals( 5, artifact.getAsset( ).getParent( ).getPath( ).split( "/" ).length );
748 public void testArtifactListWithArtifactSelector1() {
749 ItemSelector selector = ArchivaItemSelector.builder( )
750 .withNamespace( "org.apache.maven" )
751 .withProjectId( "test" )
752 .withVersion( "1.0-SNAPSHOT" )
753 .withArtifactId( "test" )
754 .withArtifactVersion( "1.0-20050611.112233-1" )
757 List<? extends Artifact> results = repoContent.getArtifacts( selector );
759 assertNotNull( results );
760 assertEquals( 1, results.size( ) );
762 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1.jar" ) )
764 assertNotNull( artifact );
765 assertEquals( "", artifact.getClassifier( ) );
769 public void testArtifactListWithArtifactSelector2() {
770 ItemSelector selector = ArchivaItemSelector.builder( )
771 .withNamespace( "org.apache.maven" )
772 .withProjectId( "test" )
773 .withVersion( "1.0-SNAPSHOT" )
774 .withClassifier( "*" )
775 .withArtifactId( "test" )
776 .withArtifactVersion( "1.0-20050611.112233-1" )
779 List<? extends Artifact> results = repoContent.getArtifacts( selector );
781 assertNotNull( results );
782 assertEquals( 2, results.size( ) );
784 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
786 assertNotNull( artifact );
787 assertEquals( "javadoc", artifact.getClassifier( ) );
788 assertEquals( "javadoc", artifact.getType( ) );
792 public void testArtifactListWithArtifactSelector3() {
793 ItemSelector selector = ArchivaItemSelector.builder( )
794 .withNamespace( "org.apache.maven" )
795 .withProjectId( "test" )
796 .withVersion( "1.0-SNAPSHOT" )
797 .withClassifier( "*" )
798 .withArtifactVersion( "1.0-20050611.112233-1" )
801 List<? extends Artifact> results = repoContent.getArtifacts( selector );
803 assertNotNull( results );
804 assertEquals( 3, results.size( ) );
806 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
808 assertNotNull( artifact );
809 assertEquals( "javadoc", artifact.getClassifier( ) );
810 assertEquals( "javadoc", artifact.getType( ) );
812 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
814 assertNotNull( artifact );
815 assertEquals( "", artifact.getClassifier( ) );
816 assertEquals( "wrong-artifactId", artifact.getId( ) );
820 public void testArtifactListWithArtifactSelectorAndRelated() {
821 ItemSelector selector = ArchivaItemSelector.builder( )
822 .withNamespace( "org.apache.maven" )
823 .withProjectId( "samplejar" )
824 .withVersion( "1.0" )
825 .withArtifactVersion( "1.0" )
826 .withArtifactId( "samplejar" )
827 .withExtension( "jar" )
828 .includeRelatedArtifacts()
831 List<? extends Artifact> results = repoContent.getArtifacts( selector );
833 assertNotNull( results );
834 assertEquals( 3, results.size( ) );
836 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar" ) )
838 assertNotNull( artifact );
839 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
841 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.md5" ) )
843 assertNotNull( artifact );
844 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
845 assertEquals( "md5", artifact.getExtension( ) );
847 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.sha1" ) )
849 assertNotNull( artifact );
850 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
851 assertEquals( "sha1", artifact.getExtension( ) );