archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
/**
     * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
     *
     * @throws Exception
     */
Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
@throws Exception
Test the snapshot clean consumer on a repository set to NOT clean / delete snapshots based on released versions . @throws Exception
@Test
    public void testReleasedSnapshotsWereNotCleaned()
        throws Exception
    {
        KnownRepositoryContentConsumer repoPurgeConsumer =
            applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count",
                                        KnownRepositoryContentConsumer.class );
        org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME );
        ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
        acf.setDeleteReleasedSnapshots( false ); 
        addRepoToConfiguration( "retention-count", repoConfiguration );
        repoPurgeConsumer.beginScan( repoConfiguration, null );
        String repoRoot = prepareTestRepos();
        String projectNs = "org.apache.maven.plugins";
        String projectPath = projectNs.replaceAll("\\.","/");
        String projectName = "maven-plugin-plugin";
        String projectVersion = "2.3-SNAPSHOT";
        String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
        Path repo = getTestRepoRootPath();
        Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
        List<ArtifactMetadata> ml = getArtifactMetadataFromDir( TEST_REPO_ID, projectName, repo, vDir );
        when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
            projectNs, projectName, projectVersion )).thenReturn(ml);
        repoPurgeConsumer.processFile(
            CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
        verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
        ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
        verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
        verify(metadataRepository, never()).removeFacetFromArtifact( eq(repositorySession), any(), any(), any(), any(), any(MetadataFacet.class) );
        assertExists( projectRoot + "/2.3-SNAPSHOT" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" );
        assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" );
        Path artifactMetadataFile = Paths.get( projectRoot + "/maven-metadata.xml" );
        String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
        XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/latest" ).isEqualTo( "2.3-SNAPSHOT" );
        XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/versions/version" ).isEqualTo( "2.3-SNAPSHOT" );
        XmlAssert.assertThat(metadataXml).valueByXPath("//metadata/versioning/lastUpdated").isEqualTo ( "20070315032817" );
        removeRepoFromConfiguration( "retention-count", repoConfiguration );
    }
@ Test public void testReleasedSnapshotsWereNotCleaned ( ) throws Exception { KnownRepositoryContentConsumer repoPurgeConsumer = applicationContext . getBean ( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count" , KnownRepositoryContentConsumer . class ) ; org . apache . archiva . repository . ManagedRepository repoConfiguration = getRepoConfiguration ( TEST_REPO_ID , TEST_REPO_NAME ) ; ArtifactCleanupFeature acf = repoConfiguration . getFeature ( ArtifactCleanupFeature . class ) . get ( ) ; acf . setDeleteReleasedSnapshots ( false ) ; addRepoToConfiguration ( "retention-count" , repoConfiguration ) ; repoPurgeConsumer . beginScan ( repoConfiguration , null ) ; String repoRoot = prepareTestRepos ( ) ; String projectNs = "org.apache.maven.plugins" ; String projectPath = projectNs . replaceAll ( "\\." , "/" ) ; String projectName = "maven-plugin-plugin" ; String projectVersion = "2.3-SNAPSHOT" ; String projectRoot = repoRoot + "/" + projectPath + "/" + projectName ; Path repo = getTestRepoRootPath ( ) ; Path vDir = repo . resolve ( projectPath ) . resolve ( projectName ) . resolve ( projectVersion ) ; List < ArtifactMetadata > ml = getArtifactMetadataFromDir ( TEST_REPO_ID , projectName , repo , vDir ) ; when ( metadataRepository . getArtifacts ( repositorySession , TEST_REPO_ID , projectNs , projectName , projectVersion ) ) . thenReturn ( ml ) ; repoPurgeConsumer . processFile ( CleanupReleasedSnapshotsRepositoryPurgeTest . PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ) ; verify ( metadataRepository , never ( ) ) . removeProjectVersion ( eq ( repositorySession ) , eq ( TEST_REPO_ID ) , eq ( projectNs ) , eq ( projectName ) , eq ( projectVersion ) ) ; ArgumentCaptor < ArtifactMetadata > metadataArg = ArgumentCaptor . forClass ( ArtifactMetadata . class ) ; verify ( metadataRepository , never ( ) ) . removeTimestampedArtifact ( eq ( repositorySession ) , any ( ) , any ( ) ) ; verify ( metadataRepository , never ( ) ) . removeFacetFromArtifact ( eq ( repositorySession ) , any ( ) , any ( ) , any ( ) , any ( ) , any ( MetadataFacet . class ) ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ) ; assertExists ( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ) ; Path artifactMetadataFile = Paths . get ( projectRoot + "/maven-metadata.xml" ) ; String metadataXml = org . apache . archiva . common . utils . FileUtils . readFileToString ( artifactMetadataFile , Charset . defaultCharset ( ) ) ; XmlAssert . assertThat ( metadataXml ) . valueByXPath ( "//metadata/versioning/latest" ) . isEqualTo ( "2.3-SNAPSHOT" ) ; XmlAssert . assertThat ( metadataXml ) . valueByXPath ( "//metadata/versioning/versions/version" ) . isEqualTo ( "2.3-SNAPSHOT" ) ; XmlAssert . assertThat ( metadataXml ) . valueByXPath ( "//metadata/versioning/lastUpdated" ) . isEqualTo ( "20070315032817" ) ; removeRepoFromConfiguration ( "retention-count" , repoConfiguration ) ; }
Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions.
Test the snapshot clean consumer on a repository set to NOT clean / delete snapshots based on released versions .
// Set to NOT delete released snapshots. // Provide the metadata list // check if the snapshot wasn't removed // check if metadata file wasn't updated