Search in sources :

Example 16 with DistributionPackageBuilder

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);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) 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) 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) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) 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 17 with DistributionPackageBuilder

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);
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) InputStream(java.io.InputStream) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) PackagingImpl(org.apache.jackrabbit.vault.packaging.impl.PackagingImpl) FileVaultContentSerializer(org.apache.sling.distribution.serialization.impl.vlt.FileVaultContentSerializer) Test(org.junit.Test)

Example 18 with DistributionPackageBuilder

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);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) Test(org.junit.Test)

Example 19 with DistributionPackageBuilder

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);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) Test(org.junit.Test)

Example 20 with DistributionPackageBuilder

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());
}
Also used : 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) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)20 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)16 Test (org.junit.Test)15 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)12 DistributionRequest (org.apache.sling.distribution.DistributionRequest)11 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)10 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)9 DistributionContentSerializer (org.apache.sling.distribution.serialization.DistributionContentSerializer)7 Resource (org.apache.sling.api.resource.Resource)6 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)5 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)5 DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)5 InputStream (java.io.InputStream)3 URI (java.net.URI)3 HashMap (java.util.HashMap)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 DistributionException (org.apache.sling.distribution.common.DistributionException)3