Search in sources :

Example 1 with ArtifactTransferRequest

use of org.apache.archiva.rest.api.model.ArtifactTransferRequest in project archiva by apache.

the class CopyArtifactTest method copyToAnEmptyRepo.

@Test
public void copyToAnEmptyRepo() throws Exception {
    try {
        initSourceTargetRepo();
        // START SNIPPET: copy-artifact
        // configure the artifact you want to copy
        // if package ommited default will be jar
        ArtifactTransferRequest artifactTransferRequest = new ArtifactTransferRequest();
        artifactTransferRequest.setGroupId("org.apache.karaf.features");
        artifactTransferRequest.setArtifactId("org.apache.karaf.features.core");
        artifactTransferRequest.setVersion("2.2.2");
        artifactTransferRequest.setRepositoryId(SOURCE_REPO_ID);
        artifactTransferRequest.setTargetRepositoryId(TARGET_REPO_ID);
        // retrieve the service
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        // copy the artifact
        Boolean res = repositoriesService.copyArtifact(artifactTransferRequest);
        // END SNIPPET: copy-artifact
        assertTrue(res);
        String targetRepoPath = getManagedRepositoriesService(authorizationHeader).getManagedRepository(TARGET_REPO_ID).getLocation();
        Path artifact = Paths.get(targetRepoPath, "/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.jar");
        assertTrue(Files.exists(artifact));
        Path pom = Paths.get(targetRepoPath, "/org/apache/karaf/features/org.apache.karaf.features.core/2.2.2/org.apache.karaf.features.core-2.2.2.pom");
        assertTrue("not exists " + pom, Files.exists(pom));
    // TODO find a way to force metadata generation and test it !!
    } finally {
        cleanRepos();
    }
}
Also used : ArtifactTransferRequest(org.apache.archiva.rest.api.model.ArtifactTransferRequest) Path(java.nio.file.Path) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) Test(org.junit.Test)

Example 2 with ArtifactTransferRequest

use of org.apache.archiva.rest.api.model.ArtifactTransferRequest in project archiva by apache.

the class CopyArtifactTest method copyNonExistingArtifact.

@Test(expected = InternalServerErrorException.class)
public void copyNonExistingArtifact() throws Throwable {
    try {
        initSourceTargetRepo();
        ArtifactTransferRequest artifactTransferRequest = new ArtifactTransferRequest();
        artifactTransferRequest.setGroupId("org.apache.karaf.features");
        artifactTransferRequest.setArtifactId("org.apache.karaf.features.core");
        artifactTransferRequest.setVersion("3.0.6552");
        artifactTransferRequest.setRepositoryId(SOURCE_REPO_ID);
        artifactTransferRequest.setTargetRepositoryId(TARGET_REPO_ID);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        repositoriesService.copyArtifact(artifactTransferRequest);
    } catch (InternalServerErrorException e) {
        // StringUtils.contains( e.getMessage(), "cannot find artifact" ) );
        throw e;
    } finally {
        cleanRepos();
    }
}
Also used : ArtifactTransferRequest(org.apache.archiva.rest.api.model.ArtifactTransferRequest) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Test(org.junit.Test)

Aggregations

ArtifactTransferRequest (org.apache.archiva.rest.api.model.ArtifactTransferRequest)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 Test (org.junit.Test)2 Path (java.nio.file.Path)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1