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