From 99bd81ac000598105529473a53f62a5b53d885a5 Mon Sep 17 00:00:00 2001 From: Martin Schreier Date: Thu, 13 Jan 2022 21:00:33 +0100 Subject: [PATCH] Updating mapper for managed repo --- .../v2/model/map/MavenRepositoryMapper.java | 65 +++-- .../model/map/MavenRepositoryMapperTest.java | 231 ++++++++++++++++++ 2 files changed, 279 insertions(+), 17 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/test/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapperTest.java diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java index d9f00fc4d..1e4ed68a0 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/v2/model/map/MavenRepositoryMapper.java @@ -22,6 +22,7 @@ import org.apache.archiva.repository.ManagedRepository; import org.apache.archiva.repository.ReleaseScheme; import org.apache.archiva.repository.RepositoryType; import org.apache.archiva.repository.features.ArtifactCleanupFeature; +import org.apache.archiva.repository.features.IndexCreationFeature; import org.apache.archiva.repository.features.StagingRepositoryFeature; import org.apache.archiva.rest.api.v2.model.MavenManagedRepository; import org.springframework.stereotype.Service; @@ -48,24 +49,32 @@ public class MavenRepositoryMapper extends RestServiceMapper + */ +class MavenRepositoryMapperTest +{ + + @Test + void map( ) + { + MavenRepositoryMapper mapper = new MavenRepositoryMapper( ); + MavenManagedRepository repo = new MavenManagedRepository( ); + repo.setId( "repo01" ); + repo.setName( "Repo 01" ); + repo.setDescription( "This is repo 01" ); + repo.setLocation( "/data/repo01" ); + repo.setHasStagingRepository( true ); + repo.setSchedulingDefinition( "0,1,2 * * * *" ); + repo.setPackedIndexPath( ".index" ); + repo.setIndexPath( ".indexer" ); + repo.setIndex( true ); + repo.setDeleteSnapshotsOfRelease( false ); + repo.setBlocksRedeployments( false ); + repo.setReleaseSchemes( Arrays.asList( ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name() ) ); + repo.setCharacteristic( Repository.CHARACTERISTIC_MANAGED ); + repo.setScanned( true ); + repo.setRetentionPeriod( Period.ofDays( 10 ) ); + repo.setRetentionCount( 15 ); + repo.setSkipPackedIndexCreation( false ); + repo.setStagingRepository( "stage-repo01" ); + ManagedRepositoryConfiguration result = mapper.map( repo ); + + assertNotNull( result ); + assertEquals( "repo01", result.getId( ) ); + assertEquals( "Repo 01", result.getName( ) ); + assertEquals( "This is repo 01", result.getDescription( ) ); + assertEquals( "/data/repo01", result.getLocation( ) ); + assertTrue( result.isStageRepoNeeded( ) ); + assertEquals( "0,1,2 * * * *", result.getRefreshCronExpression( ) ); + assertEquals( ".indexer", result.getIndexDir( ) ); + assertEquals( ".index", result.getPackedIndexDir( ) ); + assertFalse( result.isDeleteReleasedSnapshots( ) ); + assertFalse( result.isBlockRedeployments( ) ); + assertTrue( result.isSnapshots( ) ); + assertTrue( result.isReleases( ) ); + assertTrue( result.isScanned( ) ); + assertEquals( 10, result.getRetentionPeriod( ) ); + assertEquals( 15, result.getRetentionCount( ) ); + assertFalse( result.isSkipPackedIndexCreation( ) ); + + } + + @Test + void update( ) + { + MavenRepositoryMapper mapper = new MavenRepositoryMapper( ); + MavenManagedRepository repo = new MavenManagedRepository( ); + ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration( ); + repo.setId( "repo01" ); + repo.setName( "Repo 01" ); + repo.setDescription( "This is repo 01" ); + repo.setLocation( "/data/repo01" ); + repo.setHasStagingRepository( true ); + repo.setSchedulingDefinition( "0,1,2 * * * *" ); + repo.setPackedIndexPath( ".index" ); + repo.setIndexPath( ".indexer" ); + repo.setIndex( true ); + repo.setDeleteSnapshotsOfRelease( false ); + repo.setBlocksRedeployments( false ); + repo.setReleaseSchemes( Arrays.asList( ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name() ) ); + repo.setCharacteristic( Repository.CHARACTERISTIC_MANAGED ); + repo.setScanned( true ); + repo.setRetentionPeriod( Period.ofDays( 10 ) ); + repo.setRetentionCount( 15 ); + repo.setSkipPackedIndexCreation( false ); + repo.setStagingRepository( "stage-repo01" ); + mapper.update( repo, result ); + + assertNotNull( result ); + assertEquals( "repo01", result.getId( ) ); + assertEquals( "Repo 01", result.getName( ) ); + assertEquals( "This is repo 01", result.getDescription( ) ); + assertEquals( "/data/repo01", result.getLocation( ) ); + assertTrue( result.isStageRepoNeeded( ) ); + assertEquals( "0,1,2 * * * *", result.getRefreshCronExpression( ) ); + assertEquals( ".indexer", result.getIndexDir( ) ); + assertEquals( ".index", result.getPackedIndexDir( ) ); + assertFalse( result.isDeleteReleasedSnapshots( ) ); + assertFalse( result.isBlockRedeployments( ) ); + assertTrue( result.isSnapshots( ) ); + assertTrue( result.isReleases( ) ); + assertTrue( result.isScanned( ) ); + assertEquals( 10, result.getRetentionPeriod( ) ); + assertEquals( 15, result.getRetentionCount( ) ); + assertFalse( result.isSkipPackedIndexCreation( ) ); + } + + @Test + void reverseMap( ) throws IOException, URISyntaxException, UnsupportedURIException + { + MavenRepositoryMapper mapper = new MavenRepositoryMapper( ); + + Path tmpDir = Files.createTempDirectory( "mapper-test" ); + FilesystemStorage fsStorage = new FilesystemStorage( tmpDir, new DefaultFileLockManager( ) ); + EditableManagedRepository repository = new BasicManagedRepository( Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage ); + repository.setDescription( Locale.getDefault(), "This is repo 02" ); + repository.setBlocksRedeployment( false ); + repository.setLocation( new URI("test-path") ); + repository.setScanned( true ); + repository.setLayout( "maven2" ); + repository.setSchedulingDefinition( "* 3,5,10 * * *" ); + IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class ); + icf.setIndexPath( new URI( ".indexer" ) ); + icf.setPackedIndexPath( new URI( ".index" ) ); + icf.setSkipPackedIndexCreation( false ); + ArtifactCleanupFeature acf = repository.getFeature( ArtifactCleanupFeature.class ); + acf.setDeleteReleasedSnapshots( false ); + acf.setRetentionPeriod( Period.ofDays( 5 ) ); + acf.setRetentionCount( 17 ); + StagingRepositoryFeature srf = repository.getFeature( StagingRepositoryFeature.class ); + srf.setStageRepoNeeded( false ); + + MavenManagedRepository result = mapper.reverseMap( repository ); + assertEquals( "repo02", result.getId( ) ); + assertEquals( "Repo 02", result.getName( ) ); + assertEquals( "This is repo 02", result.getDescription( ) ); + assertFalse( result.isBlocksRedeployments( ) ); + assertEquals( "test-path", result.getLocation( ) ); + assertTrue( result.isScanned( ) ); + assertEquals( "maven2", result.getLayout( ) ); + assertEquals( "* 3,5,10 * * *", result.getSchedulingDefinition( ) ); + assertEquals( ".indexer", result.getIndexPath( ) ); + assertEquals( ".index", result.getPackedIndexPath( ) ); + assertFalse( result.isSkipPackedIndexCreation( ) ); + assertFalse( result.isDeleteSnapshotsOfRelease( ) ); + assertEquals( Period.ofDays( 5 ), result.getRetentionPeriod( ) ); + assertEquals( 17, result.getRetentionCount( ) ); + assertFalse( result.hasStagingRepository( ) ); + + } + + @Test + void reverseUpdate( ) throws IOException, URISyntaxException, UnsupportedURIException + { + MavenRepositoryMapper mapper = new MavenRepositoryMapper( ); + MavenManagedRepository result = new MavenManagedRepository( ); + Path tmpDir = Files.createTempDirectory( "mapper-test" ); + FilesystemStorage fsStorage = new FilesystemStorage( tmpDir, new DefaultFileLockManager( ) ); + EditableManagedRepository repository = new BasicManagedRepository( Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage ); + repository.setDescription( Locale.getDefault(), "This is repo 02" ); + repository.setBlocksRedeployment( false ); + repository.setLocation( new URI("test-path") ); + repository.setScanned( true ); + repository.setLayout( "maven2" ); + repository.setSchedulingDefinition( "* 3,5,10 * * *" ); + IndexCreationFeature icf = repository.getFeature( IndexCreationFeature.class ); + icf.setIndexPath( new URI( ".indexer" ) ); + icf.setPackedIndexPath( new URI( ".index" ) ); + icf.setSkipPackedIndexCreation( false ); + ArtifactCleanupFeature acf = repository.getFeature( ArtifactCleanupFeature.class ); + acf.setDeleteReleasedSnapshots( false ); + acf.setRetentionPeriod( Period.ofDays( 5 ) ); + acf.setRetentionCount( 17 ); + StagingRepositoryFeature srf = repository.getFeature( StagingRepositoryFeature.class ); + srf.setStageRepoNeeded( false ); + + mapper.reverseUpdate( repository, result ); + + assertEquals( "repo02", result.getId( ) ); + assertEquals( "Repo 02", result.getName( ) ); + assertEquals( "This is repo 02", result.getDescription( ) ); + assertFalse( result.isBlocksRedeployments( ) ); + assertEquals( "test-path", result.getLocation( ) ); + assertTrue( result.isScanned( ) ); + assertEquals( "maven2", result.getLayout( ) ); + assertEquals( "* 3,5,10 * * *", result.getSchedulingDefinition( ) ); + assertEquals( ".indexer", result.getIndexPath( ) ); + assertEquals( ".index", result.getPackedIndexPath( ) ); + assertFalse( result.isSkipPackedIndexCreation( ) ); + assertFalse( result.isDeleteSnapshotsOfRelease( ) ); + assertEquals( Period.ofDays( 5 ), result.getRetentionPeriod( ) ); + assertEquals( 17, result.getRetentionCount( ) ); + assertFalse( result.hasStagingRepository( ) ); + + } +} \ No newline at end of file -- 2.39.5