Search in sources :

Example 1 with RepositoriesService

use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.

the class RepositoriesServiceTest method deleteArtifact.

@Test
public void deleteArtifact() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
    log.info("artifacts: {}", artifacts);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
    VersionsList versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(2);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar");
        assertTrue("artifact not exists:" + artifactFile.toString(), Files.exists(artifactFile));
        Artifact artifact = new Artifact();
        artifact.setGroupId("org.apache.karaf.features");
        artifact.setArtifactId("org.apache.karaf.features.core");
        artifact.setVersion("2.2.2");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
        assertThat(artifacts).isNotNull().isEmpty();
        versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(1);
    } finally {
        cleanRepos();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) VersionsList(org.apache.archiva.rest.api.model.VersionsList) Test(org.junit.Test)

Example 2 with RepositoriesService

use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.

the class RepositoriesServiceTest method authorizedToDeleteArtifacts.

@Test
public void authorizedToDeleteArtifacts() throws Exception {
    ManagedRepository managedRepository = getTestManagedRepository("SOURCE_REPO_ID", "SOURCE_REPO_ID");
    try {
        getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        assertTrue(repositoriesService.isAuthorizedToDeleteArtifacts(managedRepository.getId()));
    } finally {
        cleanQuietlyRepo(managedRepository.getId());
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 3 with RepositoriesService

use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.

the class RepositoriesServiceTest method notAuthorizedToDeleteArtifacts.

@Test
public void notAuthorizedToDeleteArtifacts() throws Exception {
    ManagedRepository managedRepository = getTestManagedRepository("SOURCE_REPO_ID", "SOURCE_REPO_ID");
    try {
        getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
        RepositoriesService repositoriesService = getRepositoriesService(guestAuthzHeader);
        assertFalse(repositoriesService.isAuthorizedToDeleteArtifacts(managedRepository.getId()));
    } finally {
        cleanQuietlyRepo(managedRepository.getId());
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 4 with RepositoriesService

use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.

the class RepositoriesServiceTest method deleteArtifactVersion.

/**
 * delete a version of an artifact without packaging
 *
 * @throws Exception
 */
@Test
public void deleteArtifactVersion() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
    log.info("artifacts: {}", artifacts);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
    VersionsList versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(2);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar");
        assertTrue("artifact not exists:" + artifactFile, Files.exists(artifactFile));
        Artifact artifact = new Artifact();
        artifact.setGroupId("org.apache.karaf.features");
        artifact.setArtifactId("org.apache.karaf.features.core");
        artifact.setVersion("2.2.2");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        artifacts = browseService.getArtifactDownloadInfos("org.apache.karaf.features", "org.apache.karaf.features.core", "2.2.2", SOURCE_REPO_ID);
        assertThat(artifacts).isNotNull().isEmpty();
        versionsList = browseService.getVersionsList("org.apache.karaf.features", "org.apache.karaf.features.core", SOURCE_REPO_ID);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(1);
    } finally {
        cleanRepos();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) VersionsList(org.apache.archiva.rest.api.model.VersionsList) Test(org.junit.Test)

Example 5 with RepositoriesService

use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.

the class RepositoriesServiceTest method deleteSnapshot.

@Test
public void deleteSnapshot() throws Exception {
    Path targetRepo = initSnapshotRepo();
    try {
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        // repositoriesService.scanRepositoryDirectoriesNow( SNAPSHOT_REPO_ID );
        BrowseService browseService = getBrowseService(authorizationHeader, false);
        List<Artifact> artifacts = browseService.getArtifactDownloadInfos("org.apache.archiva.redback.components", "spring-quartz", "2.0-SNAPSHOT", SNAPSHOT_REPO_ID);
        log.info("artifacts: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(10);
        Path artifactFile = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.jar");
        Path artifactFilemd5 = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.jar.md5");
        Path artifactFilepom = targetRepo.resolve("org/apache/archiva/redback/components/spring-quartz/2.0-SNAPSHOT/spring-quartz-2.0-20120618.214127-1.pom");
        assertTrue(Files.exists(artifactFile));
        assertTrue(Files.exists(artifactFilemd5));
        assertTrue(Files.exists(artifactFilepom));
        // we delete only one snapshot
        Artifact artifact = new Artifact("org.apache.archiva.redback.components", "spring-quartz", "2.0-20120618.214127-1");
        artifact.setPackaging("jar");
        artifact.setRepositoryId(SNAPSHOT_REPO_ID);
        artifact.setContext(SNAPSHOT_REPO_ID);
        repositoriesService.deleteArtifact(artifact);
        artifacts = browseService.getArtifactDownloadInfos("org.apache.archiva.redback.components", "spring-quartz", "2.0-SNAPSHOT", SNAPSHOT_REPO_ID);
        log.info("artifacts: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(8);
        assertFalse(Files.exists(artifactFile));
        assertFalse(Files.exists(artifactFilemd5));
        assertFalse(Files.exists(artifactFilepom));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        cleanSnapshotRepo();
    }
}
Also used : Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Artifact(org.apache.archiva.maven2.model.Artifact) ForbiddenException(javax.ws.rs.ForbiddenException) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.Test)

Aggregations

RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)20 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)18 Test (org.junit.Test)17 Path (java.nio.file.Path)9 Artifact (org.apache.archiva.maven2.model.Artifact)8 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)7 BrowseService (org.apache.archiva.rest.api.services.BrowseService)5 VersionsList (org.apache.archiva.rest.api.model.VersionsList)3 BadRequestException (javax.ws.rs.BadRequestException)2 ForbiddenException (javax.ws.rs.ForbiddenException)2 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 ArtifactTransferRequest (org.apache.archiva.rest.api.model.ArtifactTransferRequest)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RemoteRepositoriesService (org.apache.archiva.rest.api.services.RemoteRepositoriesService)2 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1