]> source.dussan.org Git - archiva.git/blob
fc273a6838a8a0cdd44afbe837a377c877afc14c
[archiva.git] /
1 package org.apache.archiva.repository.maven.content;
2
3 /*
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
11  *
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
18  * under the License.
19  */
20
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;
47
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;
61 import java.util.Set;
62 import java.util.stream.Collectors;
63 import java.util.stream.Stream;
64
65 import static org.junit.Assert.*;
66
67 /**
68  * ManagedDefaultRepositoryContentTest
69  */
70 public class ManagedDefaultRepositoryContentTest
71     extends AbstractManagedRepositoryContentTest
72 {
73     private ManagedDefaultRepositoryContent repoContent;
74
75     @Inject
76     FileTypes fileTypes;
77
78     @Inject
79     @Named ( "archivaConfiguration#default" )
80     ArchivaConfiguration archivaConfiguration;
81
82     @Inject
83     List<? extends ArtifactMappingProvider> artifactMappingProviders;
84
85     @Inject
86     MavenContentHelper contentHelper;
87
88     @Inject
89     FileLockManager fileLockManager;
90
91     private Path getRepositoryPath(String repoName) {
92         try
93         {
94             return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
95         }
96         catch ( URISyntaxException e )
97         {
98             throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
99         }
100     }
101
102     @Before
103     public void setUp()
104         throws Exception
105     {
106         Path repoDir = getRepositoryPath( "default-repository" );
107
108         MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
109
110         FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
111         fileType.addPattern( "**/*.xml" );
112         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
113
114         fileTypes.afterConfigurationChange( null, "fileType", null );
115
116         repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
117         repoContent.setMavenContentHelper( contentHelper );
118         
119         //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
120     }
121
122     @Test
123     public void testGetVersionsBadArtifact()
124         throws Exception
125     {
126         assertGetVersions( "bad_artifact", Collections.emptyList() );
127     }
128
129     @Test
130     public void testGetVersionsMissingMultipleVersions()
131         throws Exception
132     {
133         assertGetVersions( "missing_metadata_b", Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) );
134     }
135
136     @Test
137     public void testGetVersionsSimple()
138         throws Exception
139     {
140         assertVersions( "proxied_multi", "2.1", new String[]{ "2.1" } );
141     }
142
143     @Test
144     public void testGetVersionsSimpleYetIncomplete()
145         throws Exception
146     {
147         assertGetVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) );
148     }
149
150     @Test
151     public void testGetVersionsSimpleYetMissing()
152         throws Exception
153     {
154         assertGetVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) );
155     }
156
157     @Test
158     public void testGetVersionsSnapshotA()
159         throws Exception
160     {
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" } );
166     }
167
168     @Test
169     public void testToMetadataPathFromProjectReference()
170     {
171         ProjectReference reference = new ProjectReference();
172         reference.setGroupId( "com.foo" );
173         reference.setArtifactId( "foo-tool" );
174
175         assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
176     }
177
178     @Test
179     public void testToMetadataPathFromVersionReference()
180     {
181         VersionedReference reference = new VersionedReference();
182         reference.setGroupId( "com.foo" );
183         reference.setArtifactId( "foo-tool" );
184         reference.setVersion( "1.0" );
185
186         assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
187     }
188
189     @Test
190     @Override
191     public void testToPathOnNullArtifactReference()
192     {
193         try
194         {
195             ArtifactReference reference = null;
196             repoContent.toPath( reference );
197             fail( "Should have failed due to null artifact reference." );
198         }
199         catch ( IllegalArgumentException e )
200         {
201             /* expected path */
202         }
203     }
204
205     @Test
206     public void testExcludeMetadataFile()
207         throws Exception
208     {
209         assertVersions( "include_xml", "1.0", new String[]{ "1.0" } );
210     }
211
212     private void assertGetVersions( String artifactId, List<String> expectedVersions )
213         throws Exception
214     {
215         ProjectReference reference = new ProjectReference();
216         reference.setGroupId( "org.apache.archiva.metadata.tests" );
217         reference.setArtifactId( artifactId );
218
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() );
223
224         // Request the versions.
225         Set<String> testedVersionSet = repoContent.getVersions( reference );
226
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 );
232
233         // Test the expected array of versions, to the actual tested versions
234         assertEquals( "available versions", expectedVersions, testedVersions );
235
236         ItemSelector selector = ArchivaItemSelector.builder( )
237             .withNamespace( "org.apache.archiva.metadata.tests" )
238             .withProjectId( artifactId )
239             .build( );
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( ) );
244     }
245
246     private void assertVersions( String artifactId, String version, String[] expectedVersions )
247         throws Exception
248     {
249         VersionedReference reference = new VersionedReference();
250         reference.setGroupId( "org.apache.archiva.metadata.tests" );
251         reference.setArtifactId( artifactId );
252         reference.setVersion( version );
253
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() );
258
259         // Request the versions.
260         Set<String> testedVersionSet = repoContent.getVersions( reference );
261
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 );
267
268         // Test the expected array of versions, to the actual tested versions
269         assertEquals( "Assert Versions: length/size", expectedVersions.length, testedVersions.size() );
270
271         for ( int i = 0; i < expectedVersions.length; i++ )
272         {
273             String actualVersion = testedVersions.get( i );
274             assertEquals( "Versions[" + i + "]", expectedVersions[i], actualVersion );
275         }
276
277
278         ItemSelector selector = ArchivaItemSelector.builder( )
279             .withNamespace( "org.apache.archiva.metadata.tests" )
280             .withProjectId( artifactId )
281             .withVersion( version )
282             .build( );
283         List<String> versions = repoContent.getVersions( selector ).stream()
284             .map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
285         assertArrayEquals( expectedVersions, versions.toArray( ) );
286
287
288     }
289
290     @Test
291     public void getTestGetProjectWithIllegalArgs() {
292         ItemSelector selector = ArchivaItemSelector.builder( )
293             .withNamespace( "org.apache" )
294             .withVersion( "1.0" )
295             .build();
296         try
297         {
298             repoContent.getProject( selector );
299             assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
300         } catch (IllegalArgumentException e) {
301             // Everything fine
302             assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
303         }
304     }
305
306     @Test
307     public void getTestGetVersionWithIllegalArgs() {
308         ItemSelector selector = ArchivaItemSelector.builder( )
309             .withNamespace( "org.apache.maven" )
310             .withVersion( "1.0" )
311             .build();
312         try
313         {
314             repoContent.getVersion( selector );
315             assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
316         } catch (IllegalArgumentException e) {
317             // Everything fine
318             assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
319         }
320
321
322         selector = ArchivaItemSelector.builder( )
323             .withNamespace( "org.apache.maven" )
324             .withProjectId( "shared" )
325             .build();
326         try
327         {
328             repoContent.getVersion( selector );
329             assertFalse( "Should throw IllegalArgumentException if no version is given", true );
330         } catch (IllegalArgumentException e) {
331             // Everything fine
332             assertTrue( e.getMessage( ).contains( "Version must be set" ) );
333         }
334     }
335
336     @Test
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")
343             .build();
344         try
345         {
346             repoContent.getArtifact( selector );
347             assertFalse( "Should throw IllegalArgumentException if no project id is given", true );
348         } catch (IllegalArgumentException e) {
349             // Everything fine
350             assertTrue( e.getMessage( ).contains( "Project id must be set" ) );
351         }
352
353
354         selector = ArchivaItemSelector.builder( )
355             .withNamespace( "org.apache.maven" )
356             .withProjectId( "shared" )
357             .withArtifactId( "shared" )
358             .withArtifactVersion("1.0")
359             .build();
360         try
361         {
362             repoContent.getArtifact( selector );
363             assertFalse( "Should throw IllegalArgumentException if no version is given", true );
364         } catch (IllegalArgumentException e) {
365             // Everything fine
366             assertTrue( e.getMessage( ).contains( "Version must be set" ) );
367         }
368
369         selector = ArchivaItemSelector.builder( )
370             .withNamespace( "org.apache.maven" )
371             .withProjectId( "shared" )
372             .withVersion("1.0")
373             .withArtifactVersion("1.0")
374             .build();
375         try
376         {
377             repoContent.getArtifact( selector );
378             assertFalse( "Should throw IllegalArgumentException if no artifact id is given", true );
379         } catch (IllegalArgumentException e) {
380             // Everything fine
381             assertTrue( e.getMessage( ).contains( "Artifact id must be set" ) );
382         }
383
384
385     }
386
387     @Test
388     public void testGetProjects() {
389         ItemSelector selector = ArchivaItemSelector.builder( )
390             .withNamespace( "org.apache.maven" ).build();
391         Namespace ns = repoContent.getNamespace( selector );
392         assertNotNull( ns );
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",
397             "testing", "update"
398         };
399         Object[] actual = projects.stream( ).map( p -> p.getId( ) ).sorted( ).toArray( );
400         assertArrayEquals( expected, actual);
401     }
402
403     @Test
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",
411             "testing", "update"
412         };
413         Object[] actual = projects.stream( ).map( p -> p.getId( ) ).sorted( ).toArray( );
414         assertArrayEquals( expected, actual);
415     }
416
417     @Test
418     public void testGetVersionsWithIllegalSelector() {
419         ItemSelector selector = ArchivaItemSelector.builder( )
420             .withNamespace( "org.apache.maven" ).build();
421         try
422         {
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( ) );
427         }
428     }
429
430     @Test
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( ) );
438     }
439
440
441     @Override
442     protected ArtifactReference toArtifactReference( String path )
443         throws LayoutException
444     {
445         return repoContent.toArtifactReference( path );
446     }
447
448     @Override
449     protected ItemSelector toItemSelector( String path ) throws LayoutException
450     {
451         return repoContent.toItemSelector( path );
452     }
453
454     @Override
455     protected String toPath( ArtifactReference reference )
456     {
457         return repoContent.toPath( reference );
458     }
459
460     @Override
461     protected String toPath( ItemSelector selector ) {
462         return repoContent.toPath( selector );
463     }
464
465     @Override
466     protected ManagedRepositoryContent getManaged( )
467     {
468         return repoContent;
469     }
470
471     @Override
472     protected RepositoryContent getContent( )
473     {
474         return repoContent;
475     }
476
477     private Path setupRepoCopy( String source, String target) throws IOException
478     {
479         Path defaultRepo = getRepositoryPath( source );
480         Path newRepo = defaultRepo.getParent( ).resolve( target );
481         FileUtils.copyDirectory( defaultRepo.toFile( ), newRepo.toFile( ) );
482
483         MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", newRepo );
484
485         FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
486         fileType.addPattern( "**/*.xml" );
487         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
488
489         fileTypes.afterConfigurationChange( null, "fileType", null );
490
491         repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager);
492         return newRepo;
493
494     }
495
496     @Test
497     public void testDeleteArtifactWithType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
498     {
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" ) ) );
505
506         ArtifactReference ref = new ArtifactReference( );
507         ref.setGroupId( "org.apache.maven" );
508         ref.setArtifactId( "samplejar" );
509         ref.setVersion( "1.0" );
510         ref.setType( "jar" );
511
512         repoContent.deleteArtifact( ref );
513
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" ) ) );
519
520
521     }
522
523
524     @Test
525     public void testDeleteArtifactWithClassifier() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
526     {
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" ) ) );
534
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" );
541
542         repoContent.deleteArtifact( ref );
543
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" ) ) );
550
551     }
552
553     @Test
554     public void testDeleteArtifactWithoutType() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
555     {
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" ) ) );
563
564         ArtifactReference ref = new ArtifactReference( );
565         ref.setGroupId( "org.apache.maven" );
566         ref.setArtifactId( "samplejar" );
567         ref.setVersion( "1.0" );
568
569         repoContent.deleteArtifact( ref );
570
571         assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
572         assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) );
573
574     }
575
576
577     @Test
578     public void testDeleteVersion() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
579     {
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" ) ) );
586
587         VersionedReference ref = new VersionedReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" ).version( "1.0" );
588
589         repoContent.deleteVersion( ref );
590
591         assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
592
593     }
594
595     @Test
596     public void testDeleteProject() throws IOException, org.apache.archiva.repository.ContentNotFoundException, org.apache.archiva.repository.ContentAccessException
597     {
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" ) ) );
604
605         ProjectReference ref = new ProjectReference( ).groupId( "org.apache.maven" ).artifactId( "samplejar" );
606
607         repoContent.deleteProject( ref );
608
609         assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) );
610
611     }
612
613     @Test
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 ))
620         {
621             assertNotNull( stream );
622             List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
623             checkArtifactListWithVersionSelector1( results );
624         }
625     }
626
627     @Test
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 );
635     }
636
637     private void checkArtifactListWithVersionSelector1( List<? extends Artifact> results )
638     {
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( ) );
647     }
648
649     @Test
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 ))
656         {
657             assertNotNull( stream );
658             List<? extends Artifact> results = stream.collect( Collectors.toList( ) );
659             checkArtifactListWithVersionSelector2( results );
660         }
661     }
662
663     @Test
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 );
671     }
672
673     private void checkArtifactListWithVersionSelector2( List<? extends Artifact> results )
674     {
675         assertNotNull( results );
676         assertEquals( 39, results.size( ) );
677
678         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom" ) )
679             .findFirst( ).get( );
680
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( ) );
692
693         artifact = null;
694         artifact = results.stream( ).filter( a -> a.getFileName( ).equals( "axis2-1.3-20070725.210059-1.pom.md5" ) )
695             .findFirst( ).get( );
696
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( ) );
708
709
710         artifact = null;
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( ) );
717     }
718
719     @Test
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" )
727             .build( );
728         List<? extends Artifact> results = repoContent.getArtifacts( selector );
729         checkArtifactListWithArtifactSelector1( results );
730     }
731
732     @Test
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" )
740             .build( );
741         try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
742         {
743             checkArtifactListWithArtifactSelector1( results.collect( Collectors.toList()) );
744         }
745     }
746
747     private void checkArtifactListWithArtifactSelector1( List<? extends Artifact> results )
748     {
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( ) );
754     }
755
756     @Test
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()
765             .build( );
766         List<? extends Artifact> results = repoContent.getArtifacts( selector );
767
768         checkArtifactListWithArtifactSelector2( results );
769
770     }
771
772     @Test
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()
781             .build( );
782         try(Stream<? extends Artifact> results = repoContent.newArtifactStream( selector ))
783         {
784             checkArtifactListWithArtifactSelector2( results.collect( Collectors.toList()) );
785         }
786     }
787
788     private void checkArtifactListWithArtifactSelector2( List<? extends Artifact> results )
789     {
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( ) );
797
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( ) );
803     }
804
805
806     @Test
807     public void testArtifactListWithProjectSelector() {
808         ItemSelector selector = ArchivaItemSelector.builder( )
809             .withNamespace( "org.apache.maven.shared" )
810             .withProjectId( "maven-downloader" )
811             .build( );
812         List<? extends Artifact> results = repoContent.getArtifacts( selector );
813         checkArtifactListWithProjectSelector( results );
814
815     }
816
817     @Test
818     public void testArtifactStreamWithProjectSelector() {
819         ItemSelector selector = ArchivaItemSelector.builder( )
820             .withNamespace( "org.apache.maven.shared" )
821             .withProjectId( "maven-downloader" )
822             .build( );
823         Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
824         checkArtifactListWithProjectSelector( results.collect( Collectors.toList()) );
825
826     }
827
828     private void checkArtifactListWithProjectSelector( List<? extends Artifact> results )
829     {
830         assertNotNull( results );
831         assertEquals( 27, results.size( ) );
832
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( ) );
838
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( ) );
845
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( ) );
853     }
854
855     @Test
856     public void testArtifactListWithNamespaceSelector() {
857         ItemSelector selector = ArchivaItemSelector.builder( )
858             .withNamespace( "org.multilevel" )
859             .build( );
860         List<? extends Artifact> results = repoContent.getArtifacts( selector );
861         assertNotNull( results );
862         assertEquals( 3, results.size( ) );
863         assertTrue( results.get( 0 ).getFileName( ).startsWith( "testproj1" ) );
864     }
865
866     @Test
867     public void testArtifactListWithNamespaceSelectorRecursive() {
868         ItemSelector selector = ArchivaItemSelector.builder( )
869             .withNamespace( "org.multilevel" )
870             .recurse()
871             .build( );
872         List<? extends Artifact> results = repoContent.getArtifacts( selector );
873         checkArtifactListWithNamespaceSelectorRecursive( results );
874     }
875
876     @Test
877     public void testArtifactStreamWithNamespaceSelectorRecursive() {
878         ItemSelector selector = ArchivaItemSelector.builder( )
879             .withNamespace( "org.multilevel" )
880             .recurse()
881             .build( );
882         Stream<? extends Artifact> results = repoContent.newArtifactStream( selector );
883         checkArtifactListWithNamespaceSelectorRecursive( results.collect( Collectors.toList()) );
884     }
885
886     private void checkArtifactListWithNamespaceSelectorRecursive( List<? extends Artifact> results )
887     {
888         assertNotNull( results );
889         assertEquals( 6, results.size( ) );
890
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 );
895
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 );
900     }
901
902
903     @Test
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" )
911             .build( );
912
913         List<? extends Artifact> results = repoContent.getArtifacts( selector );
914
915         assertNotNull( results );
916         assertEquals( 1, results.size( ) );
917
918         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1.jar" ) )
919             .findFirst().get();
920         assertNotNull( artifact );
921         assertEquals( "", artifact.getClassifier( ) );
922     }
923
924     @Test
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" )
933             .build( );
934
935         List<? extends Artifact> results = repoContent.getArtifacts( selector );
936
937         assertNotNull( results );
938         assertEquals( 2, results.size( ) );
939
940         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
941             .findFirst().get();
942         assertNotNull( artifact );
943         assertEquals( "javadoc", artifact.getClassifier( ) );
944         assertEquals( "javadoc", artifact.getType( ) );
945     }
946
947     @Test
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" )
955             .build( );
956
957         List<? extends Artifact> results = repoContent.getArtifacts( selector );
958
959         assertNotNull( results );
960         assertEquals( 3, results.size( ) );
961
962         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
963             .findFirst().get();
964         assertNotNull( artifact );
965         assertEquals( "javadoc", artifact.getClassifier( ) );
966         assertEquals( "javadoc", artifact.getType( ) );
967
968         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
969             .findFirst().get();
970         assertNotNull( artifact );
971         assertEquals( "", artifact.getClassifier( ) );
972         assertEquals( "wrong-artifactId", artifact.getId( ) );
973     }
974
975     @Test
976     public void testArtifactListWithArtifactSelector4() {
977         ItemSelector selector = ArchivaItemSelector.builder( )
978             .withNamespace( "org.apache.maven" )
979             .withProjectId( "test" )
980             .withVersion( "1.0-SNAPSHOT" )
981             .withClassifier( "" )
982             .build( );
983
984         List<? extends Artifact> results = repoContent.getArtifacts( selector );
985
986         assertNotNull( results );
987         assertEquals( 5, results.size( ) );
988
989         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
990             .findFirst().get();
991         assertNotNull( artifact );
992         assertEquals( "javadoc", artifact.getClassifier( ) );
993         assertEquals( "javadoc", artifact.getType( ) );
994
995         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
996             .findFirst().get();
997         assertNotNull( artifact );
998         assertEquals( "", artifact.getClassifier( ) );
999         assertEquals( "wrong-artifactId", artifact.getId( ) );
1000
1001         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.1122x-1.jar" ) )
1002             .findFirst().get();
1003         assertNotNull( artifact );
1004         assertEquals( "", artifact.getClassifier( ) );
1005         assertEquals( "wrong-artifactId", artifact.getId( ) );
1006         assertEquals( "", artifact.getArtifactVersion( ) );
1007
1008         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.1122x-1.jar" ) )
1009             .findFirst().get();
1010         assertNotNull( artifact );
1011         assertEquals( "", artifact.getClassifier( ) );
1012         assertEquals( "test", artifact.getId( ) );
1013         assertEquals( "1.0-20050611.1122x-1", artifact.getArtifactVersion( ) );
1014
1015     }
1016
1017     @Test
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" )
1026             .build( );
1027
1028         List<? extends Artifact> results = repoContent.getArtifacts( selector );
1029
1030         assertNotNull( results );
1031         assertEquals( 1, results.size( ) );
1032
1033         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "test-1.0-20050611.112233-1-javadoc.jar" ) )
1034             .findFirst().get();
1035         assertNotNull( artifact );
1036         assertEquals( "javadoc", artifact.getClassifier( ) );
1037         assertEquals( "javadoc", artifact.getType( ) );
1038     }
1039
1040     @Test
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" )
1048             .build( );
1049
1050         List<? extends Artifact> results = repoContent.getArtifacts( selector );
1051
1052         assertNotNull( results );
1053         assertEquals( 1, results.size( ) );
1054
1055         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
1056             .findFirst().get();
1057         assertNotNull( artifact );
1058     }
1059
1060     @Test
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-*" )
1067             .build( );
1068
1069         List<? extends Artifact> results = repoContent.getArtifacts( selector );
1070
1071         assertNotNull( results );
1072         assertEquals( 5, results.size( ) );
1073
1074         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "wrong-artifactId-1.0-20050611.112233-1.jar" ) )
1075             .findFirst().get();
1076         assertNotNull( artifact );
1077     }
1078
1079     @Test
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() );
1089
1090         selector = ArchivaItemSelector.builder( )
1091             .withNamespace( "org.apache.maven.shared" )
1092             .withProjectId( "maven-downloader" )
1093             .build();
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() );
1100
1101         selector = ArchivaItemSelector.builder( )
1102             .withNamespace( "org.apache.maven.shared" )
1103             .withProjectId( "maven-downloader" )
1104             .withVersion( "1.1" )
1105             .build( );
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() );
1112
1113     }
1114
1115     @Test
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( );
1123
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( ) );
1129
1130     }
1131
1132     @Test
1133     public void testToItemFromPath() throws LayoutException
1134     {
1135         String path = "/org/apache/maven/shared";
1136         ContentItem item = repoContent.toItem( path );
1137         assertNotNull( item );
1138         assertTrue( item instanceof Namespace );
1139
1140         path = "/org/apache/maven/shared/maven-downloader";
1141         item = repoContent.toItem( path );
1142         assertNotNull( item );
1143         assertTrue( item instanceof Project );
1144
1145         path = "/org/apache/maven/shared/maven-downloader/1.1";
1146         item = repoContent.toItem( path );
1147         assertNotNull( item );
1148         assertTrue( item instanceof Version );
1149
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 );
1154
1155     }
1156
1157     @Test
1158     public void testToItemFromAssetPath() throws LayoutException
1159     {
1160         StorageAsset path = repoContent.getRepository().getAsset("/org/apache/maven/shared");
1161         ContentItem item = repoContent.toItem( path );
1162         assertNotNull( item );
1163         assertTrue( item instanceof Namespace );
1164
1165         path = repoContent.getRepository( ).getAsset( "/org/apache/maven/shared/maven-downloader" );
1166         item = repoContent.toItem( path );
1167         assertNotNull( item );
1168         assertTrue( item instanceof Project );
1169
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 );
1174
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 );
1179
1180     }
1181
1182     @Test
1183     public void testHasContent() throws LayoutException
1184     {
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" )
1191             .build();
1192
1193         assertTrue( repoContent.hasContent( selector ) );
1194
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" )
1201             .build();
1202
1203         assertFalse( repoContent.hasContent( selector ) );
1204
1205     }
1206
1207     @Test
1208     public void testGetItemWithNamespaceSelector() {
1209         ItemSelector selector = ArchivaItemSelector.builder( )
1210             .withNamespace( "org.apache.maven" )
1211             .build( );
1212         ContentItem item = repoContent.getItem( selector );
1213         assertNotNull( item );
1214         assertTrue( item instanceof Namespace );
1215     }
1216
1217     @Test
1218     public void testGetItemWithProjectSelector() {
1219         ItemSelector selector = ArchivaItemSelector.builder( )
1220             .withNamespace( "org.apache.maven" )
1221             .withProjectId( "shared" )
1222             .build( );
1223         ContentItem item = repoContent.getItem( selector );
1224         assertNotNull( item );
1225         assertTrue( item instanceof Project );
1226     }
1227
1228     @Test
1229     public void testGetItemWithVersionSelector() {
1230         ItemSelector selector = ArchivaItemSelector.builder( )
1231             .withNamespace( "org.apache.maven" )
1232             .withProjectId( "samplejar" )
1233             .withVersion("2.0")
1234             .build( );
1235         ContentItem item = repoContent.getItem( selector );
1236         assertNotNull( item );
1237         assertTrue( item instanceof Version );
1238     }
1239
1240     @Test
1241     public void testGetItemWithArtifactSelector() {
1242         ItemSelector selector = ArchivaItemSelector.builder( )
1243             .withNamespace( "org.apache.maven" )
1244             .withProjectId( "samplejar" )
1245             .withVersion("2.0")
1246             .withArtifactId( "samplejar" )
1247             .build( );
1248         ContentItem item = repoContent.getItem( selector );
1249         assertNotNull( item );
1250         assertTrue( item instanceof Artifact );
1251     }
1252
1253     @Test
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( ) );
1259
1260     }
1261
1262     @Test
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()
1272             .build( );
1273
1274         List<? extends Artifact> results = repoContent.getArtifacts( selector );
1275
1276         assertNotNull( results );
1277         assertEquals( 3, results.size( ) );
1278
1279         Artifact artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar" ) )
1280             .findFirst().get();
1281         assertNotNull( artifact );
1282         assertEquals( BaseArtifactTypes.MAIN, artifact.getArtifactType( ) );
1283
1284         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.md5" ) )
1285             .findFirst().get();
1286         assertNotNull( artifact );
1287         assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
1288         assertEquals( "md5", artifact.getExtension( ) );
1289
1290         artifact = results.stream( ).filter( a -> a.getFileName( ).equalsIgnoreCase( "samplejar-1.0.jar.sha1" ) )
1291             .findFirst().get();
1292         assertNotNull( artifact );
1293         assertEquals( BaseArtifactTypes.RELATED, artifact.getArtifactType( ) );
1294         assertEquals( "sha1", artifact.getExtension( ) );
1295
1296     }
1297
1298 }