Search in sources :

Example 16 with RepositoriesService

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

the class RepositoriesServiceTest method deleteArtifactKarmaFailed.

@Test(expected = ForbiddenException.class)
public void deleteArtifactKarmaFailed() throws Exception {
    try {
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(null);
        repositoriesService.deleteArtifact(artifact);
    } catch (ForbiddenException e) {
        assertEquals(403, e.getResponse().getStatus());
        throw e;
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 17 with RepositoriesService

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

the class RepositoriesServiceTest method deleteArtifactWithClassifier.

@Test
public void deleteArtifactWithClassifier() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<Artifact> artifacts = browseService.getArtifactDownloadInfos("commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(3);
    VersionsList versionsList = browseService.getVersionsList("commons-logging", "commons-logging", SOURCE_REPO_ID);
    assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(6);
    log.info("artifacts.size: {}", artifacts.size());
    try {
        Path artifactFile = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar");
        Path artifactFilemd5 = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar.md5");
        Path artifactFilesha1 = Paths.get("target/test-origin-repo/commons-logging/commons-logging/1.0.1/commons-logging-1.0.1-javadoc.jar.sha1");
        assertTrue("artifact not exists:" + artifactFile, Files.exists(artifactFile));
        assertTrue("md5 not exists:" + artifactFilemd5, Files.exists(artifactFilemd5));
        assertTrue("sha1 not exists:" + artifactFilesha1, Files.exists(artifactFilesha1));
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setClassifier("javadoc");
        artifact.setPackaging("jar");
        artifact.setContext(SOURCE_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteArtifact(artifact);
        assertFalse("artifact not deleted exists:" + artifactFile, Files.exists(artifactFile));
        assertFalse("md5 still exists:" + artifactFilemd5, Files.exists(artifactFilemd5));
        assertFalse("sha1 still exists:" + artifactFilesha1, Files.exists(artifactFilesha1));
        artifacts = browseService.getArtifactDownloadInfos("commons-logging", "commons-logging", "1.0.1", SOURCE_REPO_ID);
        log.info("artifact: {}", artifacts);
        assertThat(artifacts).isNotNull().isNotEmpty().hasSize(2);
        versionsList = browseService.getVersionsList("commons-logging", "commons-logging", SOURCE_REPO_ID);
        log.info("versionsList: {}", versionsList);
        assertThat(versionsList.getVersions()).isNotNull().isNotEmpty().hasSize(6);
    } 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 18 with RepositoriesService

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

the class RepositoriesServiceTest method deleteWithRepoNull.

@Test(expected = BadRequestException.class)
public void deleteWithRepoNull() throws Exception {
    try {
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        Artifact artifact = new Artifact();
        artifact.setGroupId("commons-logging");
        artifact.setArtifactId("commons-logging");
        artifact.setVersion("1.0.1");
        artifact.setPackaging("jar");
        repositoriesService.deleteArtifact(artifact);
    } catch (BadRequestException e) {
        assertEquals("not http " + Response.Status.BAD_REQUEST.getStatusCode() + " status", Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
        throw e;
    }
}
Also used : RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) BadRequestException(javax.ws.rs.BadRequestException) Artifact(org.apache.archiva.maven2.model.Artifact) Test(org.junit.Test)

Example 19 with RepositoriesService

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

the class RepositoriesServiceTest method deleteGroupId.

@Test
public void deleteGroupId() throws Exception {
    initSourceTargetRepo();
    try {
        BrowseService browseService = getBrowseService(authorizationHeader, false);
        BrowseResult browseResult = browseService.browseGroupId("org.apache.karaf.features", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        log.info("browseResult: {}", browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isNotEmpty().contains(new BrowseResultEntry("org.apache.karaf.features.org.apache.karaf.features.command", true), new BrowseResultEntry("org.apache.karaf.features.org.apache.karaf.features.core", true));
        Path directory = Paths.get("target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.command");
        assertTrue("directory not exists", Files.exists(directory));
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.deleteGroupId("org.apache.karaf", SOURCE_REPO_ID);
        assertFalse("directory not exists", Files.exists(directory));
        browseResult = browseService.browseGroupId("org.apache.karaf.features", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isEmpty();
        browseResult = browseService.browseGroupId("org.apache.karaf", SOURCE_REPO_ID);
        assertNotNull(browseResult);
        assertThat(browseResult.getBrowseResultEntries()).isNotNull().isEmpty();
        log.info("browseResult empty: {}", browseResult);
    } 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) BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) BrowseService(org.apache.archiva.rest.api.services.BrowseService) BrowseResult(org.apache.archiva.rest.api.model.BrowseResult) Test(org.junit.Test)

Example 20 with RepositoriesService

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

the class RepositoriesServiceTest method scanRepo.

@Test
public void scanRepo() throws Exception {
    RepositoriesService service = getRepositoriesService(authorizationHeader);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(authorizationHeader);
    String repoId = managedRepositoriesService.getManagedRepositories().get(0).getId();
    int timeout = 20000;
    while (timeout > 0 && service.alreadyScanning(repoId)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    assertTrue(service.scanRepository(repoId, true));
}
Also used : ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) 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