Search in sources :

Example 41 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoryGroupAdminTest method addAndUpdateAndDeleteGroup.

@Test
public void addAndUpdateAndDeleteGroup() throws Exception {
    try {
        ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
        ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
        managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
        managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
        RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one")).mergedIndexTtl(20).mergedIndexPath("/.nonDefaultPath");
        mockAuditListener.clearEvents();
        repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
        assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
        assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
        assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
        assertEquals(Arrays.asList("test-new-one"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
        assertEquals(20, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
        assertEquals("/.nonDefaultPath", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
        repositoryGroup = repositoryGroupAdmin.getRepositoryGroup("repo-group-one");
        assertNotNull(repositoryGroup);
        repositoryGroup.addRepository(managedRepositoryTwo.getId());
        repositoryGroupAdmin.updateRepositoryGroup(repositoryGroup, getFakeAuditInformation());
        assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
        assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
        assertEquals(2, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
        assertEquals(Arrays.asList("test-new-one", "test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
        repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
        assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
        assertEquals(3, mockAuditListener.getAuditEvents().size());
        assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
        assertEquals(AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get(1).getAction());
        assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(2).getAction());
    } finally {
        mockAuditListener.clearEvents();
        managedRepositoryAdmin.deleteManagedRepository("test-new-one", getFakeAuditInformation(), true);
        managedRepositoryAdmin.deleteManagedRepository("test-new-two", getFakeAuditInformation(), true);
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 42 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultRepositoryGroupAdmin method getGroupToRepositoryMap.

@Override
public Map<String, List<String>> getGroupToRepositoryMap() throws RepositoryAdminException {
    Map<String, List<String>> map = new HashMap<>();
    for (ManagedRepository repo : getManagedRepositoryAdmin().getManagedRepositories()) {
        for (RepositoryGroup group : getRepositoriesGroups()) {
            if (!group.getRepositories().contains(repo.getId())) {
                String groupId = group.getId();
                List<String> repos = map.get(groupId);
                if (repos == null) {
                    repos = new ArrayList<>();
                    map.put(groupId, repos);
                }
                repos.add(repo.getId());
            }
        }
    }
    return map;
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 43 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ManagedRepositoryAdminTest method getAllManagedRepos.

@Test
public void getAllManagedRepos() throws Exception {
    mockAuditListener.clearEvents();
    List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    assertTrue(repos.size() > 0);
    log.info("repos {}", repos);
    // check default internal
    ManagedRepository internal = findManagedRepoById(repos, "internal");
    assertNotNull(internal);
    assertTrue(internal.isReleases());
    assertFalse(internal.isSnapshots());
    mockAuditListener.clearEvents();
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) Test(org.junit.Test) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)

Example 44 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ManagedRepositoryAdminTest method addDeleteManagedRepoWithStaged.

@Test
public void addDeleteManagedRepoWithStaged() throws Exception {
    Path repoDir = clearRepoLocation(repoLocation);
    mockAuditListener.clearEvents();
    List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    int initialSize = repos.size();
    assertTrue(initialSize > 0);
    ManagedRepository repo = new ManagedRepository(Locale.getDefault());
    repo.setId(repoId);
    repo.setName("test repo");
    repo.setLocation(repoLocation);
    repo.setCronExpression("0 0 * * * ?");
    managedRepositoryAdmin.addManagedRepository(repo, true, getFakeAuditInformation());
    repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    assertEquals(initialSize + 2, repos.size());
    assertNotNull(managedRepositoryAdmin.getManagedRepository(repoId));
    assertTemplateRoleExists(repoId);
    assertTrue(Files.exists(repoDir));
    assertNotNull(managedRepositoryAdmin.getManagedRepository(repoId + STAGE_REPO_ID_END));
    assertTemplateRoleExists(repoId + STAGE_REPO_ID_END);
    assertTrue(Files.exists(Paths.get(repoLocation + STAGE_REPO_ID_END)));
    managedRepositoryAdmin.deleteManagedRepository(repoId, getFakeAuditInformation(), true);
    assertFalse(Files.exists(repoDir));
    assertFalse(Files.exists(Paths.get(repoLocation + STAGE_REPO_ID_END)));
    assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
    repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    assertEquals(initialSize, repos.size());
    assertTemplateRoleNotExists(repoId);
    assertTemplateRoleNotExists(repoId + STAGE_REPO_ID_END);
    mockAuditListener.clearEvents();
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) Test(org.junit.Test) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)

Example 45 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ManagedRepositoryAdminTest method addDeleteManagedRepo.

@Test
public void addDeleteManagedRepo() throws Exception {
    mockAuditListener.clearEvents();
    Path repoDir = clearRepoLocation(repoLocation);
    List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    int initialSize = repos.size();
    assertTrue(initialSize > 0);
    ManagedRepository repo = new ManagedRepository(Locale.getDefault());
    repo.setId(repoId);
    repo.setName("test repo");
    repo.setLocation(repoLocation);
    repo.setCronExpression("0 0 * * * ?");
    repo.setDescription("cool repo");
    managedRepositoryAdmin.addManagedRepository(repo, false, getFakeAuditInformation());
    repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    assertEquals(initialSize + 1, repos.size());
    ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repoId);
    assertNotNull(managedRepository);
    assertEquals("test repo", managedRepository.getName());
    assertEquals("cool repo", managedRepository.getDescription());
    assertTemplateRoleExists(repoId);
    managedRepositoryAdmin.deleteManagedRepository(repoId, getFakeAuditInformation(), false);
    // deleteContents false
    assertTrue(Files.exists(repoDir));
    repos = managedRepositoryAdmin.getManagedRepositories();
    assertNotNull(repos);
    assertEquals(initialSize, repos.size());
    assertTemplateRoleNotExists(repoId);
    assertEquals(2, mockAuditListener.getAuditEvents().size());
    assertAuditListenerCallAddAndDelete();
    mockAuditListener.clearEvents();
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) Test(org.junit.Test) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)

Aggregations

ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)46 Test (org.junit.Test)23 Path (java.nio.file.Path)20 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)11 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)10 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)10 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)9 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)8 ArrayList (java.util.ArrayList)7 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3