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);
}
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);
}
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);
}
Aggregations