Search in sources :

Example 11 with RepositoriesService

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();
    }
}
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 12 with RepositoriesService

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

Example 13 with RepositoriesService

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");
    }
}
Also used : MergeRepositoriesService(org.apache.archiva.rest.api.services.MergeRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) RemoteRepositoriesService(org.apache.archiva.rest.api.services.RemoteRepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService)

Example 14 with RepositoriesService

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()));
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) 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)

Example 15 with RepositoriesService

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()));
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) 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