Search in sources :

Example 36 with DistributionPackage

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

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class RepositoryDistributionPackageImporterTest method testImportPackageWithoutRequiredPrivileges.

@Test(expected = DistributionException.class)
public void testImportPackageWithoutRequiredPrivileges() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    String serviceName = "admin";
    Session session = mock(Session.class);
    AccessControlManager acm = mock(AccessControlManager.class);
    String privilegeName = "jcr:read";
    Privilege privilege = mock(Privilege.class);
    when(acm.privilegeFromName(privilegeName)).thenReturn(privilege);
    when(session.getAccessControlManager()).thenReturn(acm);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    String path = "/var/something";
    RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("someid");
    repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) AccessControlManager(javax.jcr.security.AccessControlManager) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) Test(org.junit.Test)

Example 38 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class RepositoryDistributionPackageImporterTest method testImportPackageWithUnauthorizedServiceUser.

@Test(expected = DistributionException.class)
public void testImportPackageWithUnauthorizedServiceUser() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    String serviceName = "admin";
    String path = "/var/something";
    String privilegeName = "jcr:read";
    RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getId()).thenReturn("someid");
    repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 39 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class AsyncDeliveryDispatchingStrategyTest method testAddWithNotSharedPackage.

@Test(expected = DistributionException.class)
public void testAddWithNotSharedPackage() throws Exception {
    Map<String, String> deliveryMappings = new HashMap<String, String>();
    deliveryMappings.put("queue1", "delivery1");
    deliveryMappings.put("queue2", "delivery2");
    AsyncDeliveryDispatchingStrategy asyncDeliveryDispatchingStrategy = new AsyncDeliveryDispatchingStrategy(deliveryMappings);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    asyncDeliveryDispatchingStrategy.add(distributionPackage, queueProvider);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) HashMap(java.util.HashMap) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 40 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class SimpleHttpDistributionTransport method retrievePackage.

@Nullable
public RemoteDistributionPackage retrievePackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionTransportContext distributionContext) throws DistributionException {
    log.debug("pulling from {}", distributionEndpoint.getUri());
    try {
        URI distributionURI = RequestUtils.appendDistributionRequest(distributionEndpoint.getUri(), distributionRequest);
        Executor executor = getExecutor(distributionContext);
        // TODO : add queue parameter
        InputStream inputStream = HttpTransportUtils.fetchNextPackage(executor, distributionURI, httpConfiguration);
        if (inputStream == null) {
            return null;
        }
        try {
            final DistributionPackage responsePackage = packageBuilder.readPackage(resourceResolver, inputStream);
            responsePackage.getInfo().put(PACKAGE_INFO_PROPERTY_ORIGIN_URI, distributionURI);
            log.debug("pulled package with info {}", responsePackage.getInfo());
            return new DefaultRemoteDistributionPackage(responsePackage, executor, distributionURI);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } catch (HttpHostConnectException e) {
        log.debug("could not connect to {} - skipping", distributionEndpoint.getUri());
    } catch (Exception ex) {
        log.error("cannot retrieve packages", ex);
    }
    return null;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) AbstractDistributionPackage(org.apache.sling.distribution.packaging.impl.AbstractDistributionPackage) Executor(org.apache.http.client.fluent.Executor) InputStream(java.io.InputStream) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) URI(java.net.URI) DistributionException(org.apache.sling.distribution.common.DistributionException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) RecoverableDistributionException(org.apache.sling.distribution.common.RecoverableDistributionException) HttpResponseException(org.apache.http.client.HttpResponseException) Nullable(javax.annotation.Nullable)

Aggregations

DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)59 Test (org.junit.Test)41 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)25 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)21 DistributionRequest (org.apache.sling.distribution.DistributionRequest)17 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)17 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)16 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)12 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)12 HashMap (java.util.HashMap)11 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)10 DistributionException (org.apache.sling.distribution.common.DistributionException)9 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)9 SlingRepository (org.apache.sling.jcr.api.SlingRepository)9 InputStream (java.io.InputStream)8 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)8 Resource (org.apache.sling.api.resource.Resource)7 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)7