From: Martin Stockhammer Date: Sun, 8 Mar 2020 16:27:58 +0000 (+0100) Subject: Adding version test X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c2f785a2099927f490d4883502e867b05e1ac745;p=archiva.git Adding version test --- diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java index 417dab7d2..6970d0eb5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java @@ -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 getVersions( Project project ) + public List 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( ) ); } /* diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java index ba66d57aa..588bb4726 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java @@ -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 testedVersionSet = repoContent.getVersions( reference ); // Sort the list (for asserts) + VersionComparator comparator = new VersionComparator( ); List 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 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 )