Search in sources :

Example 11 with RepositoryGroup

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

the class RepositoryGroupAdminTest method testAddAndUpdateGroupWithInvalidMergedIndexTtl.

@Test(expected = RepositoryAdminException.class)
public void testAddAndUpdateGroupWithInvalidMergedIndexTtl() 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", "test-new-two"));
        mockAuditListener.clearEvents();
        repositoryGroupAdmin.addRepositoryGroup(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());
        // verify if default values were saved
        assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
        assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
        repositoryGroup = repositoryGroupAdmin.getRepositoryGroup("repo-group-one");
        assertNotNull(repositoryGroup);
        repositoryGroup.mergedIndexTtl(-1);
        repositoryGroupAdmin.updateRepositoryGroup(repositoryGroup, getFakeAuditInformation());
    } 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 12 with RepositoryGroup

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

the class RepositoryGroupAdminTest method addAndDeleteGroup.

@Test
public void addAndDeleteGroup() throws Exception {
    try {
        Repository repo = repositoryRegistry.getRepository("test-new-one");
        if (repo != null) {
            repositoryRegistry.removeRepository(repo);
        }
        repo = repositoryRegistry.getRepository("test-new-two");
        if (repo != null) {
            repositoryRegistry.removeRepository(repo);
        }
        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", "test-new-two"));
        // repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", null);
        mockAuditListener.clearEvents();
        repositoryGroupAdmin.addRepositoryGroup(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());
        // verify if default values were saved
        assertEquals(30, repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexTtl());
        assertEquals(".indexer", repositoryGroupAdmin.getRepositoriesGroups().get(0).getMergedIndexPath());
        repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
        assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
        assertEquals(2, mockAuditListener.getAuditEvents().size());
        assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
        assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(1).getAction());
    } finally {
        mockAuditListener.clearEvents();
        repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-one"));
        repositoryRegistry.removeRepository(repositoryRegistry.getManagedRepository("test-new-two"));
    }
}
Also used : Repository(org.apache.archiva.repository.Repository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) 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 13 with RepositoryGroup

use of org.apache.archiva.admin.model.beans.RepositoryGroup 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 14 with RepositoryGroup

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

the class DefaultRepositoryGroupAdmin method addRepositoryToGroup.

@Override
public Boolean addRepositoryToGroup(String repositoryGroupId, String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
    RepositoryGroup repositoryGroup = getRepositoryGroup(repositoryGroupId);
    if (repositoryGroup == null) {
        throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot add repository to it");
    }
    if (repositoryGroup.getRepositories().contains(repositoryId)) {
        throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " already contain repository with id" + repositoryId);
    }
    validateManagedRepositoriesExists(Arrays.asList(repositoryId));
    repositoryGroup.addRepository(repositoryId);
    updateRepositoryGroup(repositoryGroup, auditInformation, false);
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.ADD_REPO_TO_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 15 with RepositoryGroup

use of org.apache.archiva.admin.model.beans.RepositoryGroup 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)

Aggregations

RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)16 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)9 Test (org.junit.Test)8 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)3 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 Configuration (org.apache.archiva.configuration.Configuration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2