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();
}
}
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();
}
}
Aggregations