Search in sources :

Example 16 with RemoteRepository

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

the class RemoteRepositoriesServiceTest method addAndUpdateAndDeleteRemoteRepository.

@Test
public void addAndUpdateAndDeleteRemoteRepository() throws Exception {
    RemoteRepositoriesService service = getRemoteRepositoriesService();
    WebClient.client(service).header("Authorization", authorizationHeader);
    int initialSize = service.getRemoteRepositories().size();
    service.addRemoteRepository(getRemoteRepository());
    assertNotNull(service.getRemoteRepository("id-new"));
    assertEquals(getRemoteRepository().getName(), service.getRemoteRepository("id-new").getName());
    assertEquals(getRemoteRepository().getUrl(), service.getRemoteRepository("id-new").getUrl());
    assertEquals(getRemoteRepository().getLayout(), service.getRemoteRepository("id-new").getLayout());
    assertEquals(getRemoteRepository().getUserName(), service.getRemoteRepository("id-new").getUserName());
    assertEquals(getRemoteRepository().getPassword(), service.getRemoteRepository("id-new").getPassword());
    assertEquals(getRemoteRepository().getTimeout(), service.getRemoteRepository("id-new").getTimeout());
    assertEquals(initialSize + 1, service.getRemoteRepositories().size());
    RemoteRepository repo = getRemoteRepository();
    repo.setName("name changed");
    repo.setPassword("new password");
    repo.setUserName("new username");
    repo.setUrl("http://foo.new.org");
    repo.setDescription("foo bar");
    service.updateRemoteRepository(repo);
    assertEquals(repo.getName(), service.getRemoteRepository("id-new").getName());
    assertEquals(repo.getUrl(), service.getRemoteRepository("id-new").getUrl());
    assertEquals(repo.getLayout(), service.getRemoteRepository("id-new").getLayout());
    assertEquals(repo.getUserName(), service.getRemoteRepository("id-new").getUserName());
    assertEquals(repo.getPassword(), service.getRemoteRepository("id-new").getPassword());
    assertEquals(repo.getTimeout(), service.getRemoteRepository("id-new").getTimeout());
    assertEquals(repo.getDescription(), service.getRemoteRepository("id-new").getDescription());
    service.deleteRemoteRepository("id-new");
    assertNull(service.getRemoteRepository("id-new"));
    assertEquals(initialSize, service.getRemoteRepositories().size());
}
Also used : RemoteRepositoriesService(org.apache.archiva.rest.api.services.RemoteRepositoriesService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Test(org.junit.Test)

Example 17 with RemoteRepository

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

the class Maven3DependencyTreeBuilder method buildDependencyTree.

@Override
public void buildDependencyTree(List<String> repositoryIds, String groupId, String artifactId, String version, DependencyVisitor dependencyVisitor) throws DependencyTreeBuilderException {
    Artifact projectArtifact = factory.createProjectArtifact(groupId, artifactId, version);
    ManagedRepository repository = null;
    try {
        repository = findArtifactInRepositories(repositoryIds, projectArtifact);
    } catch (RepositoryAdminException e) {
        // FIXME better exception
        throw new DependencyTreeBuilderException("Cannot build project dependency tree " + e.getMessage(), e);
    }
    if (repository == null) {
        // metadata could not be resolved
        return;
    }
    List<RemoteRepository> remoteRepositories = new ArrayList<>();
    Map<String, NetworkProxy> networkProxies = new HashMap<>();
    try {
        // MRM-1411
        // TODO: this is a workaround for a lack of proxy capability in the resolvers - replace when it can all be
        // handled there. It doesn't cache anything locally!
        Map<String, List<ProxyConnector>> proxyConnectorsMap = proxyConnectorAdmin.getProxyConnectorAsMap();
        List<ProxyConnector> proxyConnectors = proxyConnectorsMap.get(repository.getId());
        if (proxyConnectors != null) {
            for (ProxyConnector proxyConnector : proxyConnectors) {
                remoteRepositories.add(remoteRepositoryAdmin.getRemoteRepository(proxyConnector.getTargetRepoId()));
                NetworkProxy networkProxyConfig = networkProxyAdmin.getNetworkProxy(proxyConnector.getProxyId());
                if (networkProxyConfig != null) {
                    // key/value: remote repo ID/proxy info
                    networkProxies.put(proxyConnector.getTargetRepoId(), networkProxyConfig);
                }
            }
        }
    } catch (RepositoryAdminException e) {
        throw new DependencyTreeBuilderException(e.getMessage(), e);
    }
    // FIXME take care of relative path
    ResolveRequest resolveRequest = new ResolveRequest();
    resolveRequest.dependencyVisitor = dependencyVisitor;
    resolveRequest.localRepoDir = repository.getLocation();
    resolveRequest.groupId = groupId;
    resolveRequest.artifactId = artifactId;
    resolveRequest.version = version;
    resolveRequest.remoteRepositories = remoteRepositories;
    resolveRequest.networkProxies = networkProxies;
    resolve(resolveRequest);
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) List(java.util.List) ArrayList(java.util.ArrayList) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 18 with RemoteRepository

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

the class NetworkProxyAdminTest method addAndDeleteWithRemoteRepoLinked.

/**
 * ensure we cleanup remote repos linked to a network proxy
 */
@Test
public void addAndDeleteWithRemoteRepoLinked() throws Exception {
    mockAuditListener.clearEvents();
    int initialSize = networkProxyAdmin.getNetworkProxies().size();
    NetworkProxy networkProxy = getNetworkProxyTest("foo");
    networkProxyAdmin.addNetworkProxy(networkProxy, getFakeAuditInformation());
    assertEquals(initialSize + 1, networkProxyAdmin.getNetworkProxies().size());
    networkProxy = networkProxyAdmin.getNetworkProxy("foo");
    assertNotNull(networkProxy);
    RemoteRepository remoteRepository = getRemoteRepository();
    remoteRepository.setRemoteDownloadNetworkProxyId(networkProxy.getId());
    remoteRepositoryAdmin.addRemoteRepository(remoteRepository, getFakeAuditInformation());
    networkProxyAdmin.deleteNetworkProxy("foo", getFakeAuditInformation());
    remoteRepository = remoteRepositoryAdmin.getRemoteRepository(getRemoteRepository().getId());
    assertNull(remoteRepository.getRemoteDownloadNetworkProxyId());
    remoteRepositoryAdmin.deleteRemoteRepository(getRemoteRepository().getId(), getFakeAuditInformation());
}
Also used : RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Example 19 with RemoteRepository

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

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

the class RemoteRepositoryAdminTest method getById.

@Test
public void getById() throws Exception {
    RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository("central");
    assertNotNull(central);
    assertEquals("https://repo.maven.apache.org/maven2", central.getUrl());
    assertEquals(60, central.getTimeout());
    assertNull(central.getUserName());
    assertNull(central.getPassword());
}
Also used : RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) AbstractRepositoryAdminTest(org.apache.archiva.admin.repository.AbstractRepositoryAdminTest) Test(org.junit.Test)

Aggregations

RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)23 Test (org.junit.Test)16 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)7 Path (java.nio.file.Path)6 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)6 RemoteRepositoriesService (org.apache.archiva.rest.api.services.RemoteRepositoriesService)5 ArrayList (java.util.ArrayList)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)3 HashMap (java.util.HashMap)2 ProxyConnectorRule (org.apache.archiva.admin.model.beans.ProxyConnectorRule)2 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)2 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2