Search in sources :

Example 11 with DistributionPackageInfo

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

the class SimpleDistributionAgentTest method testDistributionWithAllowedRoot.

@Test
public void testDistributionWithAllowedRoot() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy packageExporterStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy queueDistributionStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(queueDistributionStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "default")));
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, queueDistributionStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, new String[] { "/content" }, 0);
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/content");
    final DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
    when(distributionPackage.getInfo()).thenReturn(packageInfo);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    queueDistributionStrategy.add(distributionPackage, queueProvider);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Object[] args = invocationOnMock.getArguments();
            ((DistributionPackageProcessor) args[2]).process(distributionPackage);
            return null;
        }
    }).when(packageExporter).exportPackages(any(ResourceResolver.class), any(DistributionRequest.class), any(DistributionPackageProcessor.class));
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(new SimpleDistributionQueue(name, "name"));
    DistributionResponse response = agent.execute(resourceResolver, request);
    assertTrue(response.isSuccessful());
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) SimpleDistributionQueue(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue) SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DistributionResponse(org.apache.sling.distribution.DistributionResponse) Test(org.junit.Test)

Example 12 with DistributionPackageInfo

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

the class ReferencePackageTest method testAcquire.

@Test
public void testAcquire() throws Exception {
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    String type = "dummy";
    when(distributionPackage.getType()).thenReturn(type);
    DistributionPackageInfo info = new DistributionPackageInfo(type, new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
    assertNotNull(referencePackage);
    referencePackage.acquire("queue1", "queue2");
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) Test(org.junit.Test)

Example 13 with DistributionPackageInfo

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

the class ReferencePackageTest method testGetId.

@Test
public void testGetId() throws Exception {
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    String type = "dummy";
    when(distributionPackage.getType()).thenReturn(type);
    DistributionPackageInfo info = new DistributionPackageInfo(type, new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
    assertNotNull(referencePackage);
    String id = referencePackage.getId();
    assertNotNull(id);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) Test(org.junit.Test)

Example 14 with DistributionPackageInfo

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

the class ReferencePackageTest method testCreateInputStream.

@Test
public void testCreateInputStream() throws Exception {
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    String type = "dummy";
    when(distributionPackage.getType()).thenReturn(type);
    DistributionPackageInfo info = new DistributionPackageInfo(type, new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
    assertNotNull(referencePackage);
    InputStream inputStream = referencePackage.createInputStream();
    assertNotNull(inputStream);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 15 with DistributionPackageInfo

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

the class ReferencePackageTest method testClose.

@Test
public void testClose() throws Exception {
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    String type = "dummy";
    when(distributionPackage.getType()).thenReturn(type);
    DistributionPackageInfo info = new DistributionPackageInfo(type, new HashMap<String, Object>());
    when(distributionPackage.getInfo()).thenReturn(info);
    ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
    assertNotNull(referencePackage);
    referencePackage.close();
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) Test(org.junit.Test)

Aggregations

DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)35 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)25 Test (org.junit.Test)25 HashMap (java.util.HashMap)12 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)10 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)9 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)9 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)8 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)7 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)7 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)7 InputStream (java.io.InputStream)6 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)6 DistributionException (org.apache.sling.distribution.common.DistributionException)6 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)6 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)6 SlingRepository (org.apache.sling.jcr.api.SlingRepository)6 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)5