Search in sources :

Example 16 with ProxyConnector

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

the class ProxyConnectorAdminTest method addAndUpdateAndDelete.

@Test
public void addAndUpdateAndDelete() throws Exception {
    mockAuditListener.clearEvents();
    RemoteRepository remoteRepository = getRemoteRepository("test-new-one");
    remoteRepositoryAdmin.addRemoteRepository(remoteRepository, getFakeAuditInformation());
    assertEquals("not proxyConnectors 1 " + proxyConnectorAdmin.getProxyConnectors(), 1, proxyConnectorAdmin.getProxyConnectors().size());
    assertFalse(proxyConnectorAdmin.getProxyConnectors().isEmpty());
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setSourceRepoId("snapshots");
    proxyConnector.setTargetRepoId("central");
    proxyConnector.setWhiteListPatterns(Arrays.asList("foo", "bar"));
    proxyConnectorAdmin.addProxyConnector(proxyConnector, getFakeAuditInformation());
    assertFalse(proxyConnectorAdmin.getProxyConnectors().isEmpty());
    assertEquals(2, proxyConnectorAdmin.getProxyConnectors().size());
    assertNotNull(proxyConnectorAdmin.getProxyConnector("snapshots", "central"));
    assertEquals(Arrays.asList("foo", "bar"), proxyConnectorAdmin.getProxyConnector("snapshots", "central").getWhiteListPatterns());
    proxyConnectorAdmin.deleteProxyConnector(proxyConnector, getFakeAuditInformation());
    proxyConnector.setTargetRepoId(remoteRepository.getId());
    proxyConnectorAdmin.addProxyConnector(proxyConnector, getFakeAuditInformation());
    assertNull(proxyConnectorAdmin.getProxyConnector("snapshots", "central"));
    assertNotNull(remoteRepository.getId(), proxyConnectorAdmin.getProxyConnector("snapshots", remoteRepository.getId()));
    proxyConnectorAdmin.deleteProxyConnector(proxyConnector, getFakeAuditInformation());
    assertNull(proxyConnectorAdmin.getProxyConnector("snapshots", "central"));
    assertEquals(1, proxyConnectorAdmin.getProxyConnectors().size());
    assertFalse(proxyConnectorAdmin.getProxyConnectors().isEmpty());
    assertEquals(5, mockAuditListener.getAuditEvents().size());
    assertEquals(AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get(0).getAction());
    assertEquals(AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get(1).getAction());
    assertEquals("root", mockAuditListener.getAuditEvents().get(2).getUserId());
    assertEquals("archiva-localhost", mockAuditListener.getAuditEvents().get(2).getRemoteIP());
    assertEquals(AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get(2).getAction());
    assertEquals(AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get(3).getAction());
    assertEquals(AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get(4).getAction());
    assertEquals("root", mockAuditListener.getAuditEvents().get(4).getUserId());
    remoteRepositoryAdmin.deleteRemoteRepository(remoteRepository.getId(), getFakeAuditInformation());
    mockAuditListener.clearEvents();
}
Also used : RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 17 with ProxyConnector

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

the class ProxyConnectorAdminTest method findProxyConnector.

@Test
public void findProxyConnector() throws Exception {
    ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector("internal", "central");
    assertNotNull(proxyConnector);
}
Also used : ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 18 with ProxyConnector

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

the class DefaultProxyConnectorAdmin method getProxyConnectors.

@Override
public List<ProxyConnector> getProxyConnectors() throws RepositoryAdminException {
    List<ProxyConnectorConfiguration> proxyConnectorConfigurations = getArchivaConfiguration().getConfiguration().getProxyConnectors();
    List<ProxyConnector> proxyConnectors = new ArrayList<>(proxyConnectorConfigurations.size());
    for (ProxyConnectorConfiguration configuration : proxyConnectorConfigurations) {
        proxyConnectors.add(getProxyConnector(configuration));
    }
    Collections.sort(proxyConnectors, ProxyConnectorOrderComparator.getInstance());
    return proxyConnectors;
}
Also used : ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 19 with ProxyConnector

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

the class DefaultProxyConnectorAdmin method getProxyConnectorAsMap.

@Override
public Map<String, List<ProxyConnector>> getProxyConnectorAsMap() throws RepositoryAdminException {
    Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<>();
    Iterator<ProxyConnector> it = getProxyConnectors().iterator();
    while (it.hasNext()) {
        ProxyConnector proxyConfig = it.next();
        String key = proxyConfig.getSourceRepoId();
        List<ProxyConnector> connectors = proxyConnectorMap.get(key);
        if (connectors == null) {
            connectors = new ArrayList<>(1);
            proxyConnectorMap.put(key, connectors);
        }
        connectors.add(proxyConfig);
        Collections.sort(connectors, ProxyConnectorOrderComparator.getInstance());
    }
    return proxyConnectorMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 20 with ProxyConnector

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

the class DefaultProxyConnectorRuleAdmin method getProxyConnectorRules.

@Override
public List<ProxyConnectorRule> getProxyConnectorRules() throws RepositoryAdminException {
    List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = getArchivaConfiguration().getConfiguration().getProxyConnectorRuleConfigurations();
    if (proxyConnectorRuleConfigurations.isEmpty()) {
        return Collections.emptyList();
    }
    List<ProxyConnectorRule> proxyConnectorRules = new ArrayList<>(proxyConnectorRuleConfigurations.size());
    for (ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations) {
        ProxyConnectorRule proxyConnectorRule = new ProxyConnectorRule();
        proxyConnectorRule.setPattern(proxyConnectorRuleConfiguration.getPattern());
        proxyConnectorRule.setProxyConnectorRuleType(getProxyConnectorRuleType(proxyConnectorRuleConfiguration.getRuleType()));
        for (ProxyConnectorConfiguration proxyConnectorConfiguration : proxyConnectorRuleConfiguration.getProxyConnectors()) {
            ProxyConnector proxyConnector = new ProxyConnector();
            proxyConnector.setSourceRepoId(proxyConnectorConfiguration.getSourceRepoId());
            proxyConnector.setTargetRepoId(proxyConnectorConfiguration.getTargetRepoId());
            proxyConnectorRule.getProxyConnectors().add(proxyConnector);
        }
        proxyConnectorRules.add(proxyConnectorRule);
    }
    return proxyConnectorRules;
}
Also used : ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorRule(org.apache.archiva.admin.model.beans.ProxyConnectorRule) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Aggregations

ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)20 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)7 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ProxyConnectorRule (org.apache.archiva.admin.model.beans.ProxyConnectorRule)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)4 Path (java.nio.file.Path)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.ProxyConnectorRuleConfiguration)3 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 Configuration (org.apache.archiva.configuration.Configuration)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)2