Adding version test

This commit is contained in:
Martin Stockhammer 2020-03-08 17:27:58 +01:00
parent 8befca5a49
commit c2f785a209
2 changed files with 24 additions and 3 deletions

View 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( ) );
}
/*

View 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 )