use of org.apache.sling.distribution.transport.DistributionTransportSecret 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);
}
use of org.apache.sling.distribution.transport.DistributionTransportSecret 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);
}
use of org.apache.sling.distribution.transport.DistributionTransportSecret in project sling by apache.
the class SimpleHttpDistributionTransport method getExecutor.
private Executor getExecutor(DistributionTransportContext distributionContext) {
if (distributionContext.containsKey(contextKeyExecutor)) {
return distributionContext.get(contextKeyExecutor, Executor.class);
}
Executor executor = Executor.newInstance();
DistributionTransportSecret secret = secretProvider.getSecret(distributionEndpoint.getUri());
executor = authenticate(secret, executor);
distributionContext.put(contextKeyExecutor, executor);
return executor;
}
use of org.apache.sling.distribution.transport.DistributionTransportSecret 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);
}
Aggregations