]> source.dussan.org Git - archiva.git/commitdiff
Adding version test
authorMartin Stockhammer <martin_s@apache.org>
Sun, 8 Mar 2020 16:27:58 +0000 (17:27 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 8 Mar 2020 16:27:58 +0000 (17:27 +0100)
archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java

index 417dab7d22d430a47816e777070da0aa7cfda461..6970d0eb5674f533a58d3999deba48ba587028b2 100644 (file)
@@ -260,6 +260,8 @@ public class ManagedDefaultRepositoryContent
 
 
 
+
+
     public Artifact createArtifact(final StorageAsset artifactPath, final ItemSelector selector,
         final String classifier, final String extension) {
         Version version = getVersion(selector);
@@ -566,9 +568,14 @@ public class ManagedDefaultRepositoryContent
         TBD
      */
     @Override
-    public List<? extends Version> getVersions( Project project )
+    public List<? extends Version> getVersions( final Project project )
     {
-        return null;
+        StorageAsset asset = getAsset( project.getNamespace( ).getNamespace( ), project.getId( ) );
+        return asset.list( ).stream( ).filter( a -> a.isContainer( ) )
+            .map( a -> ArchivaVersion.withAsset( a )
+                .withProject( project )
+                .withVersion( a.getName() ).build() )
+            .collect( Collectors.toList( ) );
     }
 
     /*
index ba66d57aa547a574809d60fd8f2d5a94a654e3d7..588bb47267ec1a66cd2a9875961475b423eddb6b 100644 (file)
@@ -31,6 +31,9 @@ import org.apache.archiva.repository.LayoutException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
 import org.apache.archiva.repository.RepositoryContent;
 import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.content.Project;
+import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
 import org.apache.archiva.repository.maven.MavenManagedRepository;
 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
 import org.apache.commons.io.FileUtils;
@@ -49,6 +52,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import static org.junit.Assert.*;
 
@@ -213,12 +217,22 @@ public class ManagedDefaultRepositoryContentTest
         Set<String> testedVersionSet = repoContent.getVersions( reference );
 
         // Sort the list (for asserts)
+        VersionComparator comparator = new VersionComparator( );
         List<String> testedVersions = new ArrayList<>();
         testedVersions.addAll( testedVersionSet );
-        Collections.sort( testedVersions, new VersionComparator() );
+        Collections.sort( testedVersions, comparator );
 
         // Test the expected array of versions, to the actual tested versions
         assertEquals( "available versions", expectedVersions, testedVersions );
+
+        ItemSelector selector = ArchivaItemSelector.builder( )
+            .withNamespace( "org.apache.archiva.metadata.tests" )
+            .withProjectId( artifactId )
+            .build( );
+        Project project = repoContent.getProject( selector );
+        assertNotNull( project );
+        List<String> versions = repoContent.getVersions( project ).stream().map(v -> v.getVersion()).sorted( comparator ).collect( Collectors.toList());
+        assertArrayEquals( expectedVersions.toArray(), versions.toArray( ) );
     }
 
     private void assertVersions( String artifactId, String version, String[] expectedVersions )