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 was a jar.
     */
Test if the artifact to be processed was a jar.
Test if the artifact to be processed was a jar .
@Test
    public void testIfAJarWasFound()
        throws Exception
    {
        String repoRoot = prepareTestRepos();
        String projectNs = "org.jruby.plugins";
        String projectPath = projectNs.replaceAll("\\.","/");
        String projectName = "jruby-rake-plugin";
        String projectVersion = "1.0RC1-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.0RC1-20070504.153317-1");
        deletedVersions.add("1.0RC1-20070504.160758-2");
        String versionRoot = projectRoot + "/" + projectVersion;
        String[]  exts = { ".md5", ".sha1", ""};
        for (int i=0 ; i<exts.length; i++) {
            listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                    "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar"+exts[i]);
            listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                    "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom"+exts[i]);
            listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                    "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar"+exts[i]);
            listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                    "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom"+exts[i]);
        }
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar");
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip");
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar");
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
        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_ARTIFACT );
        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 + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" );
        assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" );
        assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" );
    }
@ Test public void testIfAJarWasFound ( ) throws Exception { String repoRoot = prepareTestRepos ( ) ; String projectNs = "org.jruby.plugins" ; String projectPath = projectNs . replaceAll ( "\\." , "/" ) ; String projectName = "jruby-rake-plugin" ; String projectVersion = "1.0RC1-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.0RC1-20070504.153317-1" ) ; deletedVersions . add ( "1.0RC1-20070504.160758-2" ) ; String versionRoot = projectRoot + "/" + projectVersion ; String [ ] exts = { ".md5" , ".sha1" , "" } ; for ( int i = 0 ; i < exts . length ; i ++ ) { listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" + exts [ i ] ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" + exts [ i ] ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" + exts [ i ] ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" + exts [ i ] ) ; } listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.jar" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar" ) ; listener . deleteArtifact ( metadataRepository , getRepository ( ) . getId ( ) , "org.jruby.plugins" , "jruby-rake-plugin" , "1.0RC1-SNAPSHOT" , "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip" ) ; 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_ARTIFACT ) ; 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 + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" ) ; assertDeleted ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" ) ; assertExists ( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" ) ; }
Test if the artifact to be processed was a jar.
Test if the artifact to be processed was a jar .
// 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