Search in sources :

Example 1 with DistributionTransportSecretProvider

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyFailing.

@Test
public void testRetrievePackagesRemotelyFailing() 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);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(404);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(response.returnResponse()).thenReturn(httpResponse);
    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);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, new DistributionTransportContext());
    assertNull(retrievedPackage);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) HttpResponse(org.apache.http.HttpResponse) 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) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) 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 2 with DistributionTransportSecretProvider

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyWorking.

@Test
public void testRetrievePackagesRemotelyWorking() 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);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    HttpEntity entity = mock(HttpEntity.class);
    InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
    when(entity.getContent()).thenReturn(stream);
    when(httpResponse.getEntity()).thenReturn(entity);
    when(response.returnResponse()).thenReturn(httpResponse);
    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);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    when(packageBuilder.readPackage(any(ResourceResolver.class), any(InputStream.class))).thenReturn(distributionPackage);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
    when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
    when(distributionContext.containsKey(any(String.class))).thenReturn(true);
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, distributionContext);
    assertNotNull(retrievedPackage);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) URI(java.net.URI) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) 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) HttpResponse(org.apache.http.HttpResponse) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 3 with DistributionTransportSecretProvider

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

the class RemoteEventDistributionTriggerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    remoteEventdistributionTrigger.unregister(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Example 4 with DistributionTransportSecretProvider

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

the class RemoteEventDistributionTriggerTest method testRegister.

@Test
public void testRegister() throws Exception {
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(options.name(handler.toString())).thenReturn(options);
    when(scheduler.NOW()).thenReturn(options);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    remoteEventdistributionTrigger.register(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Example 5 with DistributionTransportSecretProvider

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

the class RemoteDistributionPackageExporterTest method testNothingExported.

@Test
public void testNothingExported() 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);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
    remotedistributionPackageExporter.exportPackages(resourceResolver, distributionRequest, new DistributionPackageProcessor() {

        @Override
        public void process(DistributionPackage distributionPackage) {
            distributionPackages.add(distributionPackage);
        }

        @Override
        public List<DistributionResponse> getAllResponses() {
            return null;
        }

        @Override
        public int getPackagesCount() {
            return 0;
        }

        @Override
        public long getPackagesSize() {
            return 0;
        }
    });
    assertNotNull(distributionPackages);
    assertTrue(distributionPackages.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) List(java.util.List) 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