use of org.apache.archiva.rest.api.services.RepositoriesService 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.services.RepositoriesService 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();
}
}
use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.
the class AbstractArchivaRestTest method createStagedNeededRepo.
protected void createStagedNeededRepo(String testRepoId, String repoPath, boolean scan) throws Exception {
createAndIndexRepo(testRepoId, repoPath, true);
if (scan) {
scanRepo(testRepoId);
}
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
repositoriesService.scanRepositoryDirectoriesNow(testRepoId);
if (scan) {
repositoriesService.scanRepositoryNow(testRepoId + "-stage", true);
repositoriesService.scanRepositoryDirectoriesNow(testRepoId + "-stage");
}
}
use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.
the class ManagedRepositoriesServiceTest method addManagedRepo.
@Test
public void addManagedRepo() throws Exception {
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ManagedRepository repo = getTestManagedRepository();
if (service.getManagedRepository(repo.getId()) != null) {
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
service.addManagedRepository(repo);
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals(getTestManagedRepository().getDescription(), repo.getDescription());
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
use of org.apache.archiva.rest.api.services.RepositoriesService in project archiva by apache.
the class ManagedRepositoriesServiceTest method updateManagedRepo.
@Test
public void updateManagedRepo() throws Exception {
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ManagedRepository repo = getTestManagedRepository();
if (service.getManagedRepository(repo.getId()) != null) {
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
service.addManagedRepository(repo);
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals("test", repo.getName());
// toto is foo in French :-)
repo.setName("toto");
service.updateManagedRepository(repo);
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals("toto", repo.getName());
timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
Aggregations