Search in sources :

Example 36 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testReleasedSnapshotsExistsInSameRepo.

@Test
public void testReleasedSnapshotsExistsInSameRepo() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    repositoryRegistry.removeRepository(TEST_REPO_ID);
    repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
    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);
    Set<String> deletedVersions = new HashSet<>();
    deletedVersions.add("2.3-SNAPSHOT");
    // test listeners for the correct artifacts
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar");
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurge.process(PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    // complete snapshot version removal for released
    verify(metadataRepository, times(1)).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.3"));
    // check if the snapshot was removed
    assertDeleted(projectRoot + "/2.3-SNAPSHOT");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5");
    assertDeleted(projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1");
    // check if the released version was not removed
    assertExists(projectRoot + "/2.3");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.md5");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.sha1");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.md5");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.sha1");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.md5");
    assertExists(projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.sha1");
    // check if metadata file was updated
    Path artifactMetadataFile = Paths.get(projectRoot + "/maven-metadata.xml");
    String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString(artifactMetadataFile, Charset.defaultCharset());
    String expectedVersions = "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/release", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("2.3", "//metadata/versioning/latest", metadataXml);
    System.out.println(metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070315032817", "//metadata/versioning/lastUpdated", metadataXml);
}
Also used : Path(java.nio.file.Path) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class RepositoryPurgeConsumerTest method testConsumerByRetentionCount.

@Test
public void testConsumerByRetentionCount() 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 atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    // force days older off to allow retention count purge to execute.
    atf.setRetentionPeriod(Period.ofDays(0));
    atf.setRetentionCount(TEST_RETENTION_COUNT);
    addRepoToConfiguration("retention-count", repoConfiguration);
    repoPurgeConsumer.beginScan(repoConfiguration, null);
    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;
    String versionRoot = projectRoot + "/" + projectVersion;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo, vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    Set<String> deletedVersions = new HashSet<>();
    deletedVersions.add("1.0RC1-20070504.153317-1");
    deletedVersions.add("1.0RC1-20070504.160758-2");
    repoPurgeConsumer.processFile(PATH_TO_BY_RETENTION_COUNT_ARTIFACT);
    // Verify the metadataRepository invocations
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
    List<ArtifactMetadata> metaL = metadataArg.getAllValues();
    for (ArtifactMetadata meta : metaL) {
        assertTrue(meta.getId().startsWith(projectName));
        assertTrue(deletedVersions.contains(meta.getVersion()));
    }
    // assert if removed from repo
    assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar");
    assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.jar");
    assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
    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-javadoc.jar");
    assertDeleted(versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2-javadoc.zip");
    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");
    // assert if not removed from repo
    assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar");
    assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.jar");
    assertExists(versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3-javadoc.zip");
    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");
    removeRepoFromConfiguration("retention-count", repoConfiguration);
}
Also used : Path(java.nio.file.Path) KnownRepositoryContentConsumer(org.apache.archiva.consumers.KnownRepositoryContentConsumer) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class DaysOldRepositoryPurgeTest method testOrderOfDeletion.

@Test
public void testOrderOfDeletion() throws Exception {
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    List<RepositoryListener> listeners = Collections.singletonList(listener);
    repoPurge = new DaysOldRepositoryPurge(getRepository(), atf.getRetentionPeriod().getDays(), atf.getRetentionCount(), repositorySession, listeners);
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-assembly-plugin";
    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");
    setLastModified(projectRoot + "/" + projectVersion + "/", OLD_TIMESTAMP);
    // test listeners for the correct artifacts
    String[] exts = { ".md5", ".sha1", "" };
    for (int i = 0; i < exts.length; i++) {
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" + exts[i]);
    }
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurge.process(PATH_TO_TEST_ORDER_OF_DELETION);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, times(deletedVersions.size())).removeArtifact(metadataArg.capture(), eq(projectVersion));
    List<ArtifactMetadata> metaL = metadataArg.getAllValues();
    for (ArtifactMetadata meta : metaL) {
        assertTrue(meta.getId().startsWith(projectName));
        assertTrue(deletedVersions.contains(meta.getVersion()));
    }
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1");
    assertDeleted(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5");
    // the following should not have been deleted
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1");
    assertExists(projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5");
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) Path(java.nio.file.Path) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class DaysOldRepositoryPurgeTest method testByLastModified.

@Test
public void testByLastModified() throws Exception {
    org.apache.archiva.repository.ManagedRepository repoConfiguration = getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME);
    ArtifactCleanupFeature atf = repoConfiguration.getFeature(ArtifactCleanupFeature.class).get();
    repoPurge = new DaysOldRepositoryPurge(getRepository(), atf.getRetentionPeriod().getDays(), atf.getRetentionCount(), repositorySession, Collections.singletonList(listener));
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-install-plugin";
    String projectVersion = "2.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("2.2-SNAPSHOT");
    deletedVersions.add("2.2-20061118.060401-2");
    setLastModified(projectRoot + "/" + projectVersion + "/", OLD_TIMESTAMP);
    // test listeners for the correct artifacts
    String[] exts = { ".md5", ".sha1", "" };
    for (int i = 0; i < exts.length; i++) {
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.jar" + exts[i]);
        listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-install-plugin", "2.2-20061118.060401-2", "maven-install-plugin-2.2-20061118.060401-2.pom" + exts[i]);
    }
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurge.process(PATH_TO_BY_DAYS_OLD_ARTIFACT);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, times(2)).removeArtifact(metadataArg.capture(), eq(projectVersion));
    List<ArtifactMetadata> metaL = metadataArg.getAllValues();
    for (ArtifactMetadata meta : metaL) {
        assertTrue(meta.getId().startsWith(projectName));
        assertTrue(deletedVersions.contains(meta.getVersion()));
    }
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1");
    // shouldn't be deleted because even if older than 30 days (because retention count = 2)
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5");
    assertExists(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5");
    assertDeleted(projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1");
}
Also used : Path(java.nio.file.Path) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with ArtifactMetadata

use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.

the class RetentionCountRepositoryPurgeTest method testOrderOfDeletion.

@Test
public void testOrderOfDeletion() throws Exception {
    String repoRoot = prepareTestRepos();
    String projectNs = "org.apache.maven.plugins";
    String projectPath = projectNs.replaceAll("\\.", "/");
    String projectName = "maven-assembly-plugin";
    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;
    // test listeners for the correct artifacts
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5");
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1");
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.jar");
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5");
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1");
    listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.apache.maven.plugins", "maven-assembly-plugin", "1.1.2-20070427.065136-1", "maven-assembly-plugin-1.1.2-20070427.065136-1.pom");
    listenerControl.replay();
    // Provide the metadata list
    List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, projectVersion)).thenReturn(ml);
    repoPurge.process(PATH_TO_TEST_ORDER_OF_DELETION);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion));
    ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
    verify(metadataRepository, times(deletedVersions.size())).removeArtifact(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 + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar");
    assertDeleted(versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1");
    assertDeleted(versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5");
    assertDeleted(versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom");
    assertDeleted(versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1");
    assertDeleted(versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5");
    // the following should not have been deleted
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1");
    assertExists(versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5");
}
Also used : Path(java.nio.file.Path) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)96 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)23 Path (java.nio.file.Path)20 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)17 Date (java.util.Date)15 HashSet (java.util.HashSet)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)10 MavenArtifactFacet (org.apache.archiva.metadata.model.maven2.MavenArtifactFacet)9 HashMap (java.util.HashMap)8 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Node (javax.jcr.Node)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 IOException (java.io.IOException)5 RepositoryException (javax.jcr.RepositoryException)5