Search in sources :

Example 6 with DistributionTransportSecretProvider

use of org.apache.sling.distribution.transport.DistributionTransportSecretProvider in project sling by apache.

the class SimpleHttpDistributionTransportTest method testDeliverPackage.

@Test
public void testDeliverPackage() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    InputStream stream = mock(InputStream.class);
    when(distributionPackage.createInputStream()).thenReturn(stream);
    DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
    when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
    when(distributionContext.containsKey(any(String.class))).thenReturn(true);
    simpleHttpDistributionTransport.deliverPackage(resourceResolver, distributionPackage, distributionContext);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) URI(java.net.URI) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 7 with DistributionTransportSecretProvider

use of org.apache.sling.distribution.transport.DistributionTransportSecretProvider in project sling by apache.

the class RemoteDistributionPackageExporterTest method testFailedPackageRetrieval.

@Test
public void testFailedPackageRetrieval() throws Exception {
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    String[] endpoints = new String[0];
    RemoteDistributionPackageExporter remotedistributionPackageExporter = new RemoteDistributionPackageExporter(mock(DefaultDistributionLog.class), packageBuilder, distributionTransportSecretProvider, endpoints, 1, new HttpConfiguration(10000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = remotedistributionPackageExporter.getPackage(resourceResolver, "123");
    assertNull(distributionPackage);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) Test(org.junit.Test)

Example 8 with DistributionTransportSecretProvider

use of org.apache.sling.distribution.transport.DistributionTransportSecretProvider in project sling by apache.

the class RemoteDistributionPackageImporterTest method testDummyImport.

@Test
public void testDummyImport() throws Exception {
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Map<String, String> endpoints = new HashMap<String, String>();
    RemoteDistributionPackageImporter remotedistributionPackageImporter = new RemoteDistributionPackageImporter(mock(DefaultDistributionLog.class), distributionTransportSecretProvider, endpoints, new HttpConfiguration(10000));
    endpoints.put("default", "http://endpoint");
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo info = new DistributionPackageInfo("/foo");
    when(distributionPackage.getInfo()).thenReturn(info);
    remotedistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) Test(org.junit.Test)

Aggregations

DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)8 Test (org.junit.Test)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)6 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)5 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)5 HashMap (java.util.HashMap)4 DistributionRequest (org.apache.sling.distribution.DistributionRequest)4 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)4 URI (java.net.URI)3 HttpResponse (org.apache.http.HttpResponse)3 Executor (org.apache.http.client.fluent.Executor)3 Request (org.apache.http.client.fluent.Request)3 Response (org.apache.http.client.fluent.Response)3 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)3 DistributionTransportSecret (org.apache.sling.distribution.transport.DistributionTransportSecret)3 HttpConfiguration (org.apache.sling.distribution.transport.impl.HttpConfiguration)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 StatusLine (org.apache.http.StatusLine)2