use of org.apache.sling.distribution.packaging.DistributionPackageBuilder 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.packaging.DistributionPackageBuilder in project sling by apache.
the class LocalDistributionPackageImporterTest method importPackageWithLargeHeader.
@Test
public void importPackageWithLargeHeader() throws Exception {
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
LocalDistributionPackageImporter localdistributionPackageImporter = new LocalDistributionPackageImporter("mockImporter", distributionEventFactory, packageBuilder);
FileVaultContentSerializer vaultSerializer = new FileVaultContentSerializer("importPackageWithLargeHeader", new PackagingImpl(), ImportMode.UPDATE, AccessControlHandling.IGNORE, new String[0], new String[0], new String[0], false, -1);
DistributionPackageBuilder builder = new FileDistributionPackageBuilder(DistributionRequestType.ADD.name(), vaultSerializer, null, null, null, null);
ResourceResolver resourceResolver = slingContext.resourceResolver();
String[] paths = createPaths(resourceResolver, 1000, "/content/company/de/press-releases/2016/11/04/message");
DistributionPackage pkg = builder.createPackage(resourceResolver, new SimpleDistributionRequest(DistributionRequestType.ADD, paths));
InputStream streamWithHeader = DistributionPackageUtils.createStreamWithHeader(pkg);
localdistributionPackageImporter.importStream(resourceResolver, streamWithHeader);
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder in project sling by apache.
the class LocalDistributionPackageImporterTest method testDummyImport.
@Test
public void testDummyImport() throws Exception {
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
LocalDistributionPackageImporter localdistributionPackageImporter = new LocalDistributionPackageImporter("mockImporter", distributionEventFactory, packageBuilder);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
localdistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder 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.packaging.DistributionPackageBuilder in project sling by apache.
the class LocalDistributionPackageExporterTest method testExport.
@Test
public void testExport() throws Exception {
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
when(packageBuilder.createPackage(any(ResourceResolver.class), any(DistributionRequest.class))).thenReturn(mock(DistributionPackage.class));
LocalDistributionPackageExporter localdistributionPackageExporter = new LocalDistributionPackageExporter(packageBuilder);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
localdistributionPackageExporter.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);
assertEquals(1, distributionPackages.size());
}
Aggregations