archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
/**
     * Test if the artifact to be processed is a pom
     */
Test if the artifact to be processed is a pom
Test if the artifact to be processed is a pom
@Test
    public void testIfAPomWasFound()
        throws Exception
    {
        String repoRoot = prepareTestRepos();
        String projectNs = "org.codehaus.castor";
        String projectPath = projectNs.replaceAll("\\.","/");
        String projectName = "castor-anttasks";
        String projectVersion = "1.1.2-SNAPSHOT";
        String projectRoot = repoRoot + "/" + projectPath+"/"+projectName;
        Path repo = getTestRepoRootPath();
        Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
        Set<String> deletedVersions = new HashSet<>();
        deletedVersions.add("1.1.2-20070427.065136-1");
        String versionRoot = projectRoot + "/" + projectVersion;
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                                 "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.jar" );
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
        listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                                 "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
        listenerControl.replay();
        List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
        when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
            projectNs, projectName, projectVersion )).thenReturn(ml);
        repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
        listenerControl.verify();
        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, times(deletedVersions.size())).removeTimestampedArtifact( eq(repositorySession), metadataArg.capture(), eq(projectVersion) );
        List<ArtifactMetadata> metaL = metadataArg.getAllValues();
        for (ArtifactMetadata meta : metaL) {
            assertTrue(meta.getId().startsWith(projectName));
            assertTrue(deletedVersions.contains(meta.getVersion()));
        }
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" );
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" );
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" );
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" );
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" );
        assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" );
        assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" );
    }
@ Test public void testIfAPomWasFound ( ) throws Exception { String repoRoot = prepareTestRepos ( ) ; String projectNs = "org.codehaus.castor" ; String projectPath = projectNs . replaceAll ( "\\." , "/" ) ; String projectName = "castor-anttasks" ; String projectVersion = "1.1.2-SNAPSHOT" ; String projectRoot = repoRoot + "/" + projectPath + "/" + projectName ; Path repo = getTestRepoRootPath ( ) ; Path vDir = repo . resolve ( projectPath ) . resolve ( projectName ) . resolve ( projectVersion ) ; Set < String > deletedVersions = new HashSet < > ( ) ; deletedVersions . add ( "1.1.2-20070427.065136-1" ) ; String versionRoot = projectRoot + "/" + projectVersion ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.jar.md5" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.jar" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.pom.md5" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.codehaus.castor" , "castor-anttasks" , "1.1.2-SNAPSHOT" , "castor-anttasks-1.1.2-20070427.065136-1.pom" ) ; listenerControl . replay ( ) ; List < ArtifactMetadata > ml = getArtifactMetadataFromDir ( TEST_REPO_ID , projectName , repo . getParent ( ) , vDir ) ; when ( metadataRepository . getArtifacts ( repositorySession , TEST_REPO_ID , projectNs , projectName , projectVersion ) ) . thenReturn ( ml ) ; repoPurge . process ( PATH_TO_BY_RETENTION_COUNT_POM ) ; listenerControl . verify ( ) ; 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 , times ( deletedVersions . size ( ) ) ) . removeTimestampedArtifact ( eq ( repositorySession ) , metadataArg . capture ( ) , eq ( projectVersion ) ) ; List < ArtifactMetadata > metaL = metadataArg . getAllValues ( ) ; for ( ArtifactMetadata meta : metaL ) { assertTrue ( meta . getId ( ) . startsWith ( projectName ) ) ; assertTrue ( deletedVersions . contains ( meta . getVersion ( ) ) ) ; } assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" ) ; assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" ) ; assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" ) ; assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" ) ; assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" ) ; assertDeleted ( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" ) ; assertExists ( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" ) ; }
Test if the artifact to be processed is a pom
Test if the artifact to be processed is a pom
// test listeners for the correct artifacts // Provide the metadata list // Verify the metadataRepository invocations // assert if removed from repo // assert if not removed from repo