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.ContentItem;
36 import org.apache.archiva.repository.content.ItemSelector;
37 import org.apache.archiva.repository.content.Namespace;
38 import org.apache.archiva.repository.content.Project;
39 import org.apache.archiva.repository.content.Version;
40 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
41 import org.apache.archiva.repository.maven.MavenManagedRepository;
42 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
43 import org.apache.archiva.repository.storage.StorageAsset;
44 import org.apache.commons.io.FileUtils;
45 import org.junit.Before;
46 import org.junit.Test;
48 import javax.inject.Inject;
49 import javax.inject.Named;
50 import javax.naming.Name;
51 import java.io.IOException;
52 import java.net.URISyntaxException;
53 import java.nio.file.Files;
54 import java.nio.file.Path;
55 import java.nio.file.Paths;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.Collections;
59 import java.util.Comparator;
60 import java.util.List;
62 import java.util.stream.Collectors;
63 import java.util.stream.Stream;
65 import static org.junit.Assert.*;
68 * ManagedDefaultRepositoryContentTest
70 public class ManagedDefaultRepositoryContentTest
71 extends AbstractManagedRepositoryContentTest
73 private ManagedDefaultRepositoryContent repoContent;
79 @Named ( "archivaConfiguration#default" )
80 ArchivaConfiguration archivaConfiguration;
83 List<? extends ArtifactMappingProvider> artifactMappingProviders;
86 MavenContentHelper contentHelper;
89 FileLockManager fileLockManager;
91 private Path getRepositoryPath(String repoName) {
94 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
96 catch ( URISyntaxException e )
98 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
106 Path repoDir = getRepositoryPath( "default-repository" );
108 MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
110 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
111 fileType.addPattern( "**/*.xml" );
112 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
114 fileTypes.afterConfigurationChange( null, "fileType", null );
116 repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
117 repoContent.setMavenContentHelper( contentHelper );
119 //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
123 public void testGetVersionsBadArtifact()
126 assertGetVersions( "bad_artifact", Collections.emptyList() );
130 public void testGetVersionsMissingMultipleVersions()
133 assertGetVersions( "missing_metadata_b", Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) );
137 public void testGetVersionsSimple()
140 assertVersions( "proxied_multi", "2.1", new String[]{ "2.1" } );
144 public void testGetVersionsSimpleYetIncomplete()
147 assertGetVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) );
151 public void testGetVersionsSimpleYetMissing()
154 assertGetVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) );
158 public void testGetVersionsSnapshotA()
161 assertVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
162 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
163 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
164 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
165 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
169 public void testToMetadataPathFromProjectReference()
171 ProjectReference reference = new ProjectReference();
172 reference.setGroupId( "com.foo" );
173 reference.setArtifactId( "foo-tool" );
175 assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
179 public void testToMetadataPathFromVersionReference()
181 VersionedReference reference = new VersionedReference();
182 reference.setGroupId( "com.foo" );
183 reference.setArtifactId( "foo-tool" );
184 reference.setVersion( "1.0" );
186 assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
191 public void testToPathOnNullArtifactReference()
195 ArtifactReference reference = null;
196 repoContent.toPath( reference );
197 fail( "Should have failed due to null artifact reference." );
199 catch ( IllegalArgumentException e )
206 public void testExcludeMetadataFile()
209 assertVersions( "include_xml", "1.0", new String[]{ "1.0" } );
212 private void assertGetVersions( String artifactId, List<String> expectedVersions )
215 ProjectReference reference = new ProjectReference();
216 reference.setGroupId( "org.apache.archiva.metadata.tests" );
217 reference.setArtifactId( artifactId );
219 // Use the test metadata-repository, which is already setup for
220 // These kind of version tests.
221 Path repoDir = getRepositoryPath( "metadata-repository" );
222 (( EditableManagedRepository)repoContent.getRepository()).setLocation( repoDir.toAbsolutePath().toUri() );
224 // Request the versions.
225 Set<String> testedVersionSet = repoContent.getVersions( reference );
227 // Sort the list (for asserts)
228 VersionComparator comparator = new VersionComparator( );
229 List<String> testedVersions = new ArrayList<>();
230 testedVersions.addAll( testedVersionSet );
231 Collections.sort( testedVersions, comparator );
233 // Test the expected array of versions, to the actual tested versions
234 assertEquals( "available versions", expectedVersions, testedVersions );
236 ItemSelector selector = ArchivaItemSelector.builder( )
237 .withNamespace( "org.apache.archiva.metadata.tests" )
238 .withProjectId( artifactId )
240 Project project = repoContent.getProject( selector );
241 assertNotNull( project );
242 List<String> versions = repoContent.getVersions( project ).stream().map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
243 assertArrayEquals( expectedVersions.toArray(), versions.toArray( ) );
246 private void assertVersions( String artifactId, String version, String[] expectedVersions )
249 VersionedReference reference = new VersionedReference();
250 reference.setGroupId( "org.apache.archiva.metadata.tests" );
251 reference.setArtifactId( artifactId );
252 reference.setVersion( version );
254 // Use the test metadata-repository, which is already setup for
255 // These kind of version tests.
256 Path repoDir = getRepositoryPath( "metadata-repository" );
257 ((EditableManagedRepository)repoContent.getRepository()).setLocation( repoDir.toAbsolutePath().toUri() );
259 // Request the versions.
260 Set<String> testedVersionSet = repoContent.getVersions( reference );
262 // Sort the list (for asserts later)
263 final VersionComparator comparator = new VersionComparator( );
264 List<String> testedVersions = new ArrayList<>();
265 testedVersions.addAll( testedVersionSet );
266 Collections.sort( testedVersions, comparator );
268 // Test the expected array of versions, to the actual tested versions
269 assertEquals( "Assert Versions: length/size", expectedVersions.length, testedVersions.size() );
271 for ( int i = 0; i < expectedVersions.length; i++ )
273 String actualVersion = testedVersions.get( i );
274 assertEquals( "Versions[" + i + "]", expectedVersions[i], actualVersion );
278 ItemSelector selector = ArchivaItemSelector.builder( )
279 .withNamespace( "org.apache.archiva.metadata.tests" )
280 .withProjectId( artifactId )
281 .withVersion( version )
283 List<String> versions = repoContent.getVersions( selector ).stream()
284 .map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
285 assertArrayEquals( expectedVersions, versions.toArray( ) );
291 public void getTestGetProjectWithIllegalArgs() {
292 ItemSelector selector = ArchivaItemSelector.builder( )
293 .withNamespace( "org.apache" )
294 .withVersion( "1.0" )
298 repoContent.getProject( selector );
299 assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
300 } catch (IllegalArgumentException e) {
302 assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
307 public void getTestGetVersionWithIllegalArgs() {
308 ItemSelector selector = ArchivaItemSelector.builder( )
309 .withNamespace( "org.apache.maven" )
310 .withVersion( "1.0" )
314 repoContent.getVersion( selector );
315 assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
316 } catch (IllegalArgumentException e) {
318 assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
322 selector = ArchivaItemSelector.builder( )
323 .withNamespace( "org.apache.maven" )
324 .withProjectId( "shared" )
328 repoContent.getVersion( selector );
329 assertFalse( "Should throw IllegalArgumentException if no version is given", true );
330 } catch (IllegalArgumentException e) {
332 assertTrue( e.getMessage( ).contains( "Version must be set" ) );
337 public void getTestGetArtifactWithIllegalArgs() {
338 ItemSelector selector = ArchivaItemSelector.builder( )
339 .withNamespace( "org.apache.maven" )
340 .withVersion( "1.0" )
341 .withArtifactId( "shared" )
342 .withArtifactVersion("1.0")
346 repoContent.getArtifact( selector );
347 assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
348 } catch (IllegalArgumentException e) {
350 assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
354 selector = ArchivaItemSelector.builder( )
355 .withNamespace( "org.apache.maven" )
356 .withProjectId( "shared" )
357 .withArtifactId( "shared" )
358 .withArtifactVersion("1.0")
362 repoContent.getArtifact( selector );
363 assertFalse( "Should throw IllegalArgumentException if no version is given", true );
364 } catch (IllegalArgumentException e) {
366 assertTrue( e.getMessage( ).contains( "Version must be set" ) );
369 selector = ArchivaItemSelector.builder( )
370 .withNamespace( "org.apache.maven" )
371 .withProjectId( "shared" )
373 .withArtifactVersion("1.0")
377 repoContent.getArtifact( selector );
378 assertFalse( "Should throw IllegalArgumentException if no artifact id is given", true );
379 } catch (IllegalArgumentException e) {
381 assertTrue( e.getMessage( ).contains( "Artifact id must be set" ) );
388 public void testGetProjects() {
389 ItemSelector selector = ArchivaItemSelector.builder( )
390 .withNamespace( "org.apache.maven" ).build();
391 Namespace ns = repoContent.getNamespace( selector );
393 List<? extends Project> projects = repoContent.getProjects( ns );
394 assertEquals( 12, projects.size( ) );
395 String[] expected = new String[]{
396 "A", "B", "C", "archiva", "discovery", "maven-parent", "samplejar", "shared", "some-ejb", "test",
399 Object[] actual = projects.stream( ).map( p -> p.getId( ) ).sorted( ).toArray( );
400 assertArrayEquals( expected, actual);
404 public void testGetProjectsWithSelector() {
405 ItemSelector selector = ArchivaItemSelector.builder( )
406 .withNamespace( "org.apache.maven" ).build();
407 List<? extends Project> projects = repoContent.getProjects( selector );
408 assertEquals( 12, projects.size( ) );
409 String[] expected = new String[]{
410 "A", "B", "C", "archiva", "discovery", "maven-parent", "samplejar", "shared", "some-ejb", "test",
413 Object[] actual = projects.stream( ).map( p -> p.getId( ) ).sorted( ).toArray( );
414 assertArrayEquals( expected, actual);
418 public void testGetVersionsWithIllegalSelector() {
419 ItemSelector selector = ArchivaItemSelector.builder( )
420 .withNamespace( "org.apache.maven" ).build();
423 List<? extends Version> versions = repoContent.getVersions( selector );
424 assertFalse( "IllegalArgumentException expected, when project id not set", true );
425 } catch (IllegalArgumentException e) {
426 assertEquals( "Project id not set, while retrieving versions.", e.getMessage( ) );
431 public void testGetVersionsWithSelector() {
432 ItemSelector selector = ArchivaItemSelector.builder( )
433 .withNamespace( "org.apache.maven" )
434 .withProjectId( "samplejar" ).build();
435 List<? extends Version> versions = repoContent.getVersions( selector );
436 assertNotNull( versions );
437 assertEquals( 2, versions.size( ) );
442 protected ArtifactReference toArtifactReference( String path )
443 throws LayoutException
445 return repoContent.toArtifactReference( path );
449 protected ItemSelector toItemSelector( String path ) throws LayoutException
451 return repoContent.toItemSelector( path );
455 protected String toPath( ArtifactReference reference )
457 return repoContent.toPath( reference );
461 protected String toPath( ItemSelector selector ) {
462 return repoContent.toPath( selector );
466 protected ManagedRepositoryContent getManaged( )
472 protected RepositoryContent getContent( )
477 private Path setupRepoCopy( String source, String target) throws IOException
479 Path defaultRepo = getRepositoryPath( source );
480 Path newRepo = defaultRepo.getParent( ).resolve( target );
481 FileUtils.copyDirectory( defaultRepo.toFile( ), newRepo.toFile( ) );
483 MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", newRepo );
485 FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
486 fileType.addPattern( "**/*.xml" );
487 assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
489 fileTypes.afterConfigurationChange( null, "fileType", null );
491 repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
497 public void testDeleteArtifactWithType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
499 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
500 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
501 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
502 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
503 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
504 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
506 ArtifactReference ref = new ArtifactReference( );
507 ref.setGroupId( "org.apache.maven" );
508 ref.setArtifactId( "samplejar" );
509 ref.setVersion( "1.0" );
510 ref.setType( "jar" );
512 repoContent.deleteArtifact( ref );
514 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
515 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
516 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
517 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
518 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
525 public void testDeleteArtifactWithClassifier() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
527 Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
528 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
529 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
530 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
531 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
532 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
533 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
535 ArtifactReference ref = new ArtifactReference( );
536 ref.setGroupId( "org.apache.maven" );
537 ref.setArtifactId( "samplejar" );
538 ref.setVersion( "1.0" );
539 ref.setClassifier( "source" );
540 ref.setType( "jar" );
542 repoContent.deleteArtifact( ref );
544 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
545 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
546 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
547 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
548 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
549 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
554 public void testDeleteArtifactWithoutType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
556 Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" );
557 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
558 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) );
559 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
560 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
561 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
562 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
564 ArtifactReference ref = new ArtifactReference( );
565 ref.setGroupId( "org.apache.maven" );
566 ref.setArtifactId( "samplejar" );
567 ref.setVersion( "1.0" );
569 repoContent.deleteArtifact( ref );
571 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
572 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) );
578 public void testDeleteVersion() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
580 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
581 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
582 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
583 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
584 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
585 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
587 VersionedReference ref = new VersionedReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" ).version( "1.0" );
589 repoContent.deleteVersion( ref );
591 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
596 public void testDeleteProject() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
598 Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" );
599 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) );
600 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) );
601 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) );
602 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) );
603 assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) );
605 ProjectReference ref = new ProjectReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" );
607 repoContent.deleteProject( ref );
609 assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
614 public void testGetArtifactStreamWithVersionSelector() {
615 ItemSelector selector = ArchivaItemSelector.builder( )
616 .withNamespace( "javax.sql" )
617 .withProjectId( "jdbc" )
618 .withVersion( "2.0" ).build();
619 try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
621 assertNotNull( stream );
622 List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
623 checkArtifactListWithVersionSelector1( results );
628 public void testGetArtifactListWithVersionSelector() {
629 ItemSelector selector = ArchivaItemSelector.builder( )
630 .withNamespace( "javax.sql" )
631 .withProjectId( "jdbc" )
632 .withVersion( "2.0" ).build();
633 List<? extends Artifact> results = repoContent.getArtifacts( selector );
634 checkArtifactListWithVersionSelector1( results );
637 private void checkArtifactListWithVersionSelector1( List<? extends Artifact> results )
639 assertNotNull( results );
640 assertEquals( 2, results.size( ) );
641 Artifact mainArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "jdbc-2.0.jar" ) ).findFirst( ).get( );
642 assertNotNull( mainArtifact );
643 assertEquals( BaseArtifactTypes.MAIN, mainArtifact.getArtifactType( ) );
644 Artifact metaArtifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata-repository.xml" ) ).findFirst( ).get( );
645 assertNotNull( metaArtifact );
646 assertEquals( MavenTypes.REPOSITORY_METADATA, metaArtifact.getArtifactType( ) );
650 public void testGetArtifactStreamWithVersionSelector2() {
651 ItemSelector selector = ArchivaItemSelector.builder( )
652 .withNamespace( "org.apache.axis2" )
653 .withProjectId( "axis2" )
654 .withVersion( "1.3-SNAPSHOT" ).build();
655 try(Stream<? extends Artifact> stream = repoContent.newArtifactStream( selector ))
657 assertNotNull( stream );
658 List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
659 checkArtifactListWithVersionSelector2( results );
664 public void testGetArtifactListWithVersionSelector2() {
665 ItemSelector selector = ArchivaItemSelector.builder( )
666 .withNamespace( "org.apache.axis2" )
667 .withProjectId( "axis2" )
668 .withVersion( "1.3-SNAPSHOT" ).build();
669 List<? extends Artifact> results = repoContent.getArtifacts( selector );
670 checkArtifactListWithVersionSelector2( results );
673 private void checkArtifactListWithVersionSelector2( List<? extends Artifact> results )
675 assertNotNull( results );
676 assertEquals( 39, results.size( ) );
678 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom" ) )
679 .findFirst( ).get( );
681 assertNotNull( artifact );
682 assertEquals( "pom", artifact.getExtension( ) );
683 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
684 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
685 assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
686 assertEquals( ".pom", artifact.getRemainder( ) );
687 assertEquals( "axis2", artifact.getId( ) );
688 assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
689 assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
690 assertEquals( "", artifact.getClassifier( ) );
691 assertEquals( "pom", artifact.getType( ) );
694 artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom.md5" ) )
695 .findFirst( ).get( );
697 assertNotNull( artifact );
698 assertEquals( "md5", artifact.getExtension( ) );
699 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
700 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
701 assertEquals( "1.3-20070725.210059-1", artifact.getArtifactVersion( ) );
702 assertEquals( ".pom.md5", artifact.getRemainder( ) );
703 assertEquals( "axis2", artifact.getId( ) );
704 assertEquals( "axis2", artifact.getVersion( ).getProject( ).getId( ) );
705 assertEquals( "org.apache.axis2", artifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ) );
706 assertEquals( "", artifact.getClassifier( ) );
707 assertEquals( "md5", artifact.getType( ) );
711 artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "maven-metadata.xml" ) )
712 .findFirst( ).get( );
713 assertNotNull( artifact );
714 assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
715 assertEquals( "1.3-SNAPSHOT", artifact.getVersion( ).getVersion( ) );
716 assertEquals( "xml", artifact.getExtension( ) );
720 public void testGetArtifactListWithArtifactSelector1() {
721 ItemSelector selector = ArchivaItemSelector.builder( )
722 .withNamespace( "org.apache.axis2" )
723 .withProjectId( "axis2" )
724 .withVersion( "1.3-SNAPSHOT" )
725 .withArtifactVersion( "1.3-20070731.113304-21" )
726 .withExtension( "pom" )
728 List<? extends Artifact> results = repoContent.getArtifacts( selector );
729 checkArtifactListWithArtifactSelector1( results );
733 public void testGetArtifactStreamWithArtifactSelector1() {
734 ItemSelector selector = ArchivaItemSelector.builder( )
735 .withNamespace( "org.apache.axis2" )
736 .withProjectId( "axis2" )
737 .withVersion( "1.3-SNAPSHOT" )
738 .withArtifactVersion( "1.3-20070731.113304-21" )
739 .withExtension( "pom" )
741 try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
743 checkArtifactListWithArtifactSelector1( results.collect( Collectors.toList()) );
747 private void checkArtifactListWithArtifactSelector1( List<? extends Artifact> results )
749 assertNotNull( results );
750 assertEquals( 1, results.size( ) );
751 Artifact artifact = results.get( 0 );
752 assertEquals( "pom", artifact.getExtension( ) );
753 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
757 public void testGetArtifactListWithArtifactSelector2() {
758 ItemSelector selector = ArchivaItemSelector.builder( )
759 .withNamespace( "org.apache.axis2" )
760 .withProjectId( "axis2" )
761 .withVersion( "1.3-SNAPSHOT" )
762 .withArtifactVersion( "1.3-20070731.113304-21" )
763 .withExtension( "pom" )
764 .includeRelatedArtifacts()
766 List<? extends Artifact> results = repoContent.getArtifacts( selector );
768 checkArtifactListWithArtifactSelector2( results );
773 public void testGetArtifactStreamWithArtifactSelector2() {
774 ItemSelector selector = ArchivaItemSelector.builder( )
775 .withNamespace( "org.apache.axis2" )
776 .withProjectId( "axis2" )
777 .withVersion( "1.3-SNAPSHOT" )
778 .withArtifactVersion( "1.3-20070731.113304-21" )
779 .withExtension( "pom" )
780 .includeRelatedArtifacts()
782 try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
784 checkArtifactListWithArtifactSelector2( results.collect( Collectors.toList()) );
788 private void checkArtifactListWithArtifactSelector2( List<? extends Artifact> results )
790 assertNotNull( results );
791 assertEquals( 3, results.size( ) );
792 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom" ) )
793 .findFirst( ).get( );
794 assertNotNull( artifact );
795 assertEquals( "pom", artifact.getExtension( ) );
796 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
798 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "axis2-1.3-20070731.113304-21.pom.sha1" ) )
799 .findFirst( ).get( );
800 assertNotNull( artifact );
801 assertEquals( "sha1", artifact.getExtension( ) );
802 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
807 public void testArtifactListWithProjectSelector() {
808 ItemSelector selector = ArchivaItemSelector.builder( )
809 .withNamespace( "org.apache.maven.shared" )
810 .withProjectId( "maven-downloader" )
812 List<? extends Artifact> results = repoContent.getArtifacts( selector );
813 checkArtifactListWithProjectSelector( results );
818 public void testArtifactStreamWithProjectSelector() {
819 ItemSelector selector = ArchivaItemSelector.builder( )
820 .withNamespace( "org.apache.maven.shared" )
821 .withProjectId( "maven-downloader" )
823 Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
824 checkArtifactListWithProjectSelector( results.collect( Collectors.toList()) );
828 private void checkArtifactListWithProjectSelector( List<? extends Artifact> results )
830 assertNotNull( results );
831 assertEquals( 27, results.size( ) );
833 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-metadata.xml" ) )
834 .findFirst( ).get( );
835 assertNotNull( artifact );
836 assertEquals( "xml", artifact.getExtension( ) );
837 assertEquals( BaseArtifactTypes.METADATA, artifact.getArtifactType( ) );
839 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar" ) )
840 .findFirst( ).get( );
841 assertNotNull( artifact );
842 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
843 assertEquals( "sources", artifact.getClassifier( ) );
844 assertEquals( "java-source", artifact.getType( ) );
846 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "maven-downloader-1.0-sources.jar.sha1" ) )
847 .findFirst( ).get( );
848 assertNotNull( artifact );
849 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
850 assertEquals( "sources", artifact.getClassifier( ) );
851 assertEquals( "sha1", artifact.getType( ) );
852 assertEquals( ".jar.sha1", artifact.getRemainder( ) );
856 public void testArtifactListWithNamespaceSelector() {
857 ItemSelector selector = ArchivaItemSelector.builder( )
858 .withNamespace( "org.multilevel" )
860 List<? extends Artifact> results = repoContent.getArtifacts( selector );
861 assertNotNull( results );
862 assertEquals( 3, results.size( ) );
863 assertTrue( results.get( 0 ).getFileName( ).startsWith( "testproj1" ) );
867 public void testArtifactListWithNamespaceSelectorRecursive() {
868 ItemSelector selector = ArchivaItemSelector.builder( )
869 .withNamespace( "org.multilevel" )
872 List<? extends Artifact> results = repoContent.getArtifacts( selector );
873 checkArtifactListWithNamespaceSelectorRecursive( results );
877 public void testArtifactStreamWithNamespaceSelectorRecursive() {
878 ItemSelector selector = ArchivaItemSelector.builder( )
879 .withNamespace( "org.multilevel" )
882 Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
883 checkArtifactListWithNamespaceSelectorRecursive( results.collect( Collectors.toList()) );
886 private void checkArtifactListWithNamespaceSelectorRecursive( List<? extends Artifact> results )
888 assertNotNull( results );
889 assertEquals( 6, results.size( ) );
891 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "testproj2-1.0.pom" ) )
892 .findFirst( ).get( );
893 assertNotNull( artifact );
894 assertEquals( 6, artifact.getAsset( ).getParent( ).getPath( ).split( "/" ).length );
896 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "testproj1-1.0.pom" ) )
897 .findFirst( ).get( );
898 assertNotNull( artifact );
899 assertEquals( 5, artifact.getAsset( ).getParent( ).getPath( ).split( "/" ).length );
904 public void testArtifactListWithArtifactSelector1() {
905 ItemSelector selector = ArchivaItemSelector.builder( )
906 .withNamespace( "org.apache.maven" )
907 .withProjectId( "test" )
908 .withVersion( "1.0-SNAPSHOT" )
909 .withArtifactId( "test" )
910 .withArtifactVersion( "1.0-20050611.112233-1" )
913 List<? extends Artifact> results = repoContent.getArtifacts( selector );
915 assertNotNull( results );
916 assertEquals( 1, results.size( ) );
918 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1.jar" ) )
920 assertNotNull( artifact );
921 assertEquals( "", artifact.getClassifier( ) );
925 public void testArtifactListWithArtifactSelector2() {
926 ItemSelector selector = ArchivaItemSelector.builder( )
927 .withNamespace( "org.apache.maven" )
928 .withProjectId( "test" )
929 .withVersion( "1.0-SNAPSHOT" )
930 .withClassifier( "*" )
931 .withArtifactId( "test" )
932 .withArtifactVersion( "1.0-20050611.112233-1" )
935 List<? extends Artifact> results = repoContent.getArtifacts( selector );
937 assertNotNull( results );
938 assertEquals( 2, results.size( ) );
940 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
942 assertNotNull( artifact );
943 assertEquals( "javadoc", artifact.getClassifier( ) );
944 assertEquals( "javadoc", artifact.getType( ) );
948 public void testArtifactListWithArtifactSelector3() {
949 ItemSelector selector = ArchivaItemSelector.builder( )
950 .withNamespace( "org.apache.maven" )
951 .withProjectId( "test" )
952 .withVersion( "1.0-SNAPSHOT" )
953 .withClassifier( "*" )
954 .withArtifactVersion( "1.0-20050611.112233-1" )
957 List<? extends Artifact> results = repoContent.getArtifacts( selector );
959 assertNotNull( results );
960 assertEquals( 3, results.size( ) );
962 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
964 assertNotNull( artifact );
965 assertEquals( "javadoc", artifact.getClassifier( ) );
966 assertEquals( "javadoc", artifact.getType( ) );
968 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
970 assertNotNull( artifact );
971 assertEquals( "", artifact.getClassifier( ) );
972 assertEquals( "wrong-artifactId", artifact.getId( ) );
976 public void testArtifactListWithArtifactSelector4() {
977 ItemSelector selector = ArchivaItemSelector.builder( )
978 .withNamespace( "org.apache.maven" )
979 .withProjectId( "test" )
980 .withVersion( "1.0-SNAPSHOT" )
981 .withClassifier( "" )
984 List<? extends Artifact> results = repoContent.getArtifacts( selector );
986 assertNotNull( results );
987 assertEquals( 5, results.size( ) );
989 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
991 assertNotNull( artifact );
992 assertEquals( "javadoc", artifact.getClassifier( ) );
993 assertEquals( "javadoc", artifact.getType( ) );
995 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
997 assertNotNull( artifact );
998 assertEquals( "", artifact.getClassifier( ) );
999 assertEquals( "wrong-artifactId", artifact.getId( ) );
1001 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.1122x-1.jar" ) )
1003 assertNotNull( artifact );
1004 assertEquals( "", artifact.getClassifier( ) );
1005 assertEquals( "wrong-artifactId", artifact.getId( ) );
1006 assertEquals( "", artifact.getArtifactVersion( ) );
1008 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.1122x-1.jar" ) )
1010 assertNotNull( artifact );
1011 assertEquals( "", artifact.getClassifier( ) );
1012 assertEquals( "test", artifact.getId( ) );
1013 assertEquals( "1.0-20050611.1122x-1", artifact.getArtifactVersion( ) );
1018 public void testArtifactListWithArtifactSelectorWithClassifier() {
1019 ItemSelector selector = ArchivaItemSelector.builder( )
1020 .withNamespace( "org.apache.maven" )
1021 .withProjectId( "test" )
1022 .withVersion( "1.0-SNAPSHOT" )
1023 .withArtifactId( "test" )
1024 .withClassifier( "javadoc" )
1025 .withArtifactVersion( "1.0-20050611.112233-1" )
1028 List<? extends Artifact> results = repoContent.getArtifacts( selector );
1030 assertNotNull( results );
1031 assertEquals( 1, results.size( ) );
1033 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
1035 assertNotNull( artifact );
1036 assertEquals( "javadoc", artifact.getClassifier( ) );
1037 assertEquals( "javadoc", artifact.getType( ) );
1041 public void testArtifactListWithArtifactSelectorWrongArtifact() {
1042 ItemSelector selector = ArchivaItemSelector.builder( )
1043 .withNamespace( "org.apache.maven" )
1044 .withProjectId( "test" )
1045 .withVersion( "1.0-SNAPSHOT" )
1046 .withArtifactId( "wrong-artifactId" )
1047 .withArtifactVersion( "1.0-20050611.112233-1" )
1050 List<? extends Artifact> results = repoContent.getArtifacts( selector );
1052 assertNotNull( results );
1053 assertEquals( 1, results.size( ) );
1055 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
1057 assertNotNull( artifact );
1061 public void testArtifactListWithArtifactSelectorVersionPattern() {
1062 ItemSelector selector = ArchivaItemSelector.builder( )
1063 .withNamespace( "org.apache.maven" )
1064 .withProjectId( "test" )
1065 .withVersion( "1.0-SNAPSHOT" )
1066 .withArtifactVersion( "1.0-*" )
1069 List<? extends Artifact> results = repoContent.getArtifacts( selector );
1071 assertNotNull( results );
1072 assertEquals( 5, results.size( ) );
1074 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
1076 assertNotNull( artifact );
1080 public void testGetArtifactFromContentItem() {
1081 ItemSelector selector = ArchivaItemSelector.builder( )
1082 .withNamespace( "org.apache.maven" ).build();
1083 Namespace ns = repoContent.getNamespace( selector );
1084 List<? extends Artifact> artifacts = repoContent.getArtifacts( ns );
1085 assertNotNull( artifacts );
1086 assertEquals( 39, artifacts.size( ) );
1087 List<? extends Artifact> artifacts2 = repoContent.getArtifacts( (ContentItem)ns );
1088 assertArrayEquals( artifacts.toArray(), artifacts2.toArray() );
1090 selector = ArchivaItemSelector.builder( )
1091 .withNamespace( "org.apache.maven.shared" )
1092 .withProjectId( "maven-downloader" )
1094 Project project = repoContent.getProject( selector );
1095 artifacts = repoContent.getArtifacts( project );
1096 assertNotNull( artifacts );
1097 assertEquals( 27, artifacts.size( ) );
1098 artifacts2 = repoContent.getArtifacts( (ContentItem)project );
1099 assertArrayEquals( artifacts.toArray(), artifacts2.toArray() );
1101 selector = ArchivaItemSelector.builder( )
1102 .withNamespace( "org.apache.maven.shared" )
1103 .withProjectId( "maven-downloader" )
1104 .withVersion( "1.1" )
1106 Version version = repoContent.getVersion( selector );
1107 artifacts = repoContent.getArtifacts( version );
1108 assertNotNull( artifacts );
1109 assertEquals( 12, artifacts.size( ) );
1110 artifacts2 = repoContent.getArtifacts( (ContentItem)version );
1111 assertArrayEquals( artifacts.toArray(), artifacts2.toArray() );
1116 public void testGetRelatedArtifactsFromArtifact() {
1117 ItemSelector selector = ArchivaItemSelector.builder( )
1118 .withNamespace( "org.apache.maven.shared" )
1119 .withProjectId( "maven-downloader" )
1120 .withVersion( "1.1" )
1121 .withExtension( "jar" )
1122 .withArtifactId( "maven-downloader" ).build( );
1124 Artifact artifact = repoContent.getArtifact( selector );
1125 assertNotNull( artifact );
1126 List<? extends Artifact> artifacts = repoContent.getArtifacts( artifact );
1127 assertNotNull( artifacts );
1128 assertEquals( 2, artifacts.size( ) );
1133 public void testToItemFromPath() throws LayoutException
1135 String path = "/org/apache/maven/shared";
1136 ContentItem item = repoContent.toItem( path );
1137 assertNotNull( item );
1138 assertTrue( item instanceof Namespace );
1140 path = "/org/apache/maven/shared/maven-downloader";
1141 item = repoContent.toItem( path );
1142 assertNotNull( item );
1143 assertTrue( item instanceof Project );
1145 path = "/org/apache/maven/shared/maven-downloader/1.1";
1146 item = repoContent.toItem( path );
1147 assertNotNull( item );
1148 assertTrue( item instanceof Version );
1150 path = "/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar";
1151 item = repoContent.toItem( path );
1152 assertNotNull( item );
1153 assertTrue( item instanceof Artifact );
1158 public void testToItemFromAssetPath() throws LayoutException
1160 StorageAsset path = repoContent.getRepository().getAsset("/org/apache/maven/shared");
1161 ContentItem item = repoContent.toItem( path );
1162 assertNotNull( item );
1163 assertTrue( item instanceof Namespace );
1165 path = repoContent.getRepository( ).getAsset( "/org/apache/maven/shared/maven-downloader" );
1166 item = repoContent.toItem( path );
1167 assertNotNull( item );
1168 assertTrue( item instanceof Project );
1170 path = repoContent.getRepository( ).getAsset( "/org/apache/maven/shared/maven-downloader/1.1" );
1171 item = repoContent.toItem( path );
1172 assertNotNull( item );
1173 assertTrue( item instanceof Version );
1175 path = repoContent.getRepository( ).getAsset( "/org/apache/maven/shared/maven-downloader/1.1/maven-downloader-1.1.jar" );
1176 item = repoContent.toItem( path );
1177 assertNotNull( item );
1178 assertTrue( item instanceof Artifact );
1183 public void testHasContent() throws LayoutException
1185 ItemSelector selector = ArchivaItemSelector.builder( )
1186 .withNamespace( "org.apache.maven.shared" )
1187 .withProjectId( "maven-downloader" )
1188 .withVersion( "1.1" )
1189 .withArtifactId( "maven-downloader" )
1190 .withExtension( "jar" )
1193 assertTrue( repoContent.hasContent( selector ) );
1195 selector = ArchivaItemSelector.builder( )
1196 .withNamespace( "org.apache.maven.shared" )
1197 .withProjectId( "maven-downloader" )
1198 .withVersion( "1.1" )
1199 .withArtifactId( "maven-downloader" )
1200 .withExtension( "zip" )
1203 assertFalse( repoContent.hasContent( selector ) );
1208 public void testGetItemWithNamespaceSelector() {
1209 ItemSelector selector = ArchivaItemSelector.builder( )
1210 .withNamespace( "org.apache.maven" )
1212 ContentItem item = repoContent.getItem( selector );
1213 assertNotNull( item );
1214 assertTrue( item instanceof Namespace );
1218 public void testGetItemWithProjectSelector() {
1219 ItemSelector selector = ArchivaItemSelector.builder( )
1220 .withNamespace( "org.apache.maven" )
1221 .withProjectId( "shared" )
1223 ContentItem item = repoContent.getItem( selector );
1224 assertNotNull( item );
1225 assertTrue( item instanceof Project );
1229 public void testGetItemWithVersionSelector() {
1230 ItemSelector selector = ArchivaItemSelector.builder( )
1231 .withNamespace( "org.apache.maven" )
1232 .withProjectId( "samplejar" )
1235 ContentItem item = repoContent.getItem( selector );
1236 assertNotNull( item );
1237 assertTrue( item instanceof Version );
1241 public void testGetItemWithArtifactSelector() {
1242 ItemSelector selector = ArchivaItemSelector.builder( )
1243 .withNamespace( "org.apache.maven" )
1244 .withProjectId( "samplejar" )
1246 .withArtifactId( "samplejar" )
1248 ContentItem item = repoContent.getItem( selector );
1249 assertNotNull( item );
1250 assertTrue( item instanceof Artifact );
1254 public void testGetNamespaceFromPath() {
1255 StorageAsset path = repoContent.getRepository( ).getAsset( "/org/apache/axis2" );
1256 Namespace ns = repoContent.getNamespaceFromPath( path );
1257 assertNotNull( ns );
1258 assertEquals( "org.apache.axis2", ns.getNamespace( ) );
1263 public void testArtifactListWithArtifactSelectorAndRelated() {
1264 ItemSelector selector = ArchivaItemSelector.builder( )
1265 .withNamespace( "org.apache.maven" )
1266 .withProjectId( "samplejar" )
1267 .withVersion( "1.0" )
1268 .withArtifactVersion( "1.0" )
1269 .withArtifactId( "samplejar" )
1270 .withExtension( "jar" )
1271 .includeRelatedArtifacts()
1274 List<? extends Artifact> results = repoContent.getArtifacts( selector );
1276 assertNotNull( results );
1277 assertEquals( 3, results.size( ) );
1279 Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar" ) )
1281 assertNotNull( artifact );
1282 assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
1284 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.md5" ) )
1286 assertNotNull( artifact );
1287 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
1288 assertEquals( "md5", artifact.getExtension( ) );
1290 artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.sha1" ) )
1292 assertNotNull( artifact );
1293 assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
1294 assertEquals( "sha1", artifact.getExtension( ) );