Search in sources :

Example 6 with RepositoryRegistry

use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testNonArtifactFile.

@Test
public void testNonArtifactFile() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
    repositoryRegistry.removeRepository(managedRepository);
    repositoryRegistry.putRepository(getRepoConfiguration(TEST_REPO_ID, TEST_REPO_NAME));
    String repoRoot = prepareTestRepos();
    // test listeners for the correct artifacts
    listenerControl.replay();
    Path file = Paths.get(repoRoot, INDEX_PATH);
    if (!Files.exists(file)) {
        // help windauze to create directory with .
        Files.createDirectories(file.getParent());
        Files.createFile(file);
    }
    assertTrue(Files.exists(file));
    repoPurge.process(INDEX_PATH);
    listenerControl.verify();
    assertTrue(Files.exists(file));
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) Test(org.junit.Test)

Example 7 with RepositoryRegistry

use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method testHigherSnapshotExistsInSameRepo.

@Test
public void testHigherSnapshotExistsInSameRepo() throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    ManagedRepository managedRepository = repositoryRegistry.getManagedRepository(TEST_REPO_ID);
    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-source-plugin";
    String projectVersion = "2.0.2";
    String projectRoot = repoRoot + "/" + projectPath + "/" + projectName;
    Path repo = getTestRepoRootPath();
    Path vDir = repo.resolve(projectPath).resolve(projectName).resolve(projectVersion);
    Path vDir2 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.3-SNAPSHOT");
    Path vDir3 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.4-SNAPSHOT");
    // test listeners for the correct artifacts - no deletions
    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);
    List<ArtifactMetadata> m2 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir2);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.3-SNAPSHOT")).thenReturn(ml);
    List<ArtifactMetadata> m3 = getArtifactMetadataFromDir(TEST_REPO_ID, projectName, repo.getParent(), vDir3);
    when(metadataRepository.getArtifacts(TEST_REPO_ID, projectNs, projectName, "2.0.4-SNAPSHOT")).thenReturn(ml);
    repoPurge.process(CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO);
    listenerControl.verify();
    // Verify the metadataRepository invocations
    // No removal
    verify(metadataRepository, never()).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.0.3-SNAPSHOT"));
    verify(metadataRepository, never()).removeProjectVersion(eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq("2.0.4-SNAPSHOT"));
    verify(metadataRepository, never()).removeArtifact(any(ArtifactMetadata.class), any(String.class));
    verify(metadataRepository, never()).removeArtifact(any(String.class), any(String.class), any(String.class), any(String.class), any(MetadataFacet.class));
    // check if the snapshot was not removed
    assertExists(projectRoot + "/2.0.3-SNAPSHOT");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1");
    // check if the released version was not removed
    assertExists(projectRoot + "/2.0.4-SNAPSHOT");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5");
    assertExists(projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1");
    // check if metadata file was not updated (because nothing was removed)
    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.0.3-SNAPSHOT</version>" + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
    XMLAssert.assertXpathEvaluatesTo("2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml);
    XMLAssert.assertXpathsEqual("//expected/versions/version", expectedVersions, "//metadata/versioning/versions/version", metadataXml);
    XMLAssert.assertXpathEvaluatesTo("20070427033345", "//metadata/versioning/lastUpdated", metadataXml);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 8 with RepositoryRegistry

use of org.apache.archiva.repository.RepositoryRegistry in project archiva by apache.

the class RepositoryPurgeConsumerTest method addRepoToConfiguration.

private void addRepoToConfiguration(String configHint, org.apache.archiva.repository.ManagedRepository repoConfiguration) throws Exception {
    RepositoryRegistry repositoryRegistry = applicationContext.getBean(RepositoryRegistry.class);
    repositoryRegistry.putRepository(repoConfiguration);
}
Also used : RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry)

Aggregations

RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)8 Path (java.nio.file.Path)6 Test (org.junit.Test)4 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 HashSet (java.util.HashSet)2 ManagedRepositoryAdmin (org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin)2 DefaultManagedRepositoryAdmin (org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)1 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)1 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)1