Search in sources :

Example 11 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider 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 DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class SimpleDistributionAgentTest method testGetExistingNamedQueue.

@Test
public void testGetExistingNamedQueue() throws Exception {
    String name = "sample-agent";
    DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
    DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
    DistributionRequestAuthorizationStrategy authorizationStrategy = mock(DistributionRequestAuthorizationStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueueDispatchingStrategy dispatchingStrategy = mock(DistributionQueueDispatchingStrategy.class);
    when(dispatchingStrategy.getQueueNames()).thenReturn(Arrays.asList("priority"));
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, authorizationStrategy, queueProvider, dispatchingStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue("priority")).thenReturn(queue);
    assertNotNull(agent.getQueue("priority"));
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) SimpleDistributionQueue(org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) Test(org.junit.Test)

Example 13 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class QueueingDistributionPackageProcessorTest method testGetAllResponses.

@Test
public void testGetAllResponses() throws Exception {
    String callingUser = "mr-who-cares";
    String requestId = "id231";
    long startTime = System.currentTimeMillis();
    DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
    DistributionQueueDispatchingStrategy scheduleQueueStrategy = mock(DistributionQueueDispatchingStrategy.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    String agentName = "dummy";
    QueueingDistributionPackageProcessor exporterProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, eventFactory, scheduleQueueStrategy, queueProvider, log, agentName);
    List<DistributionResponse> allResponses = exporterProcessor.getAllResponses();
    assertNotNull(allResponses);
    assertEquals(0, allResponses.size());
}
Also used : DistributionQueueDispatchingStrategy(org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) DistributionResponse(org.apache.sling.distribution.DistributionResponse) Test(org.junit.Test)

Example 14 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithFailingItemDelivery.

@Test
public void testPackageAdditionWithFailingItemDelivery() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem queueItem = mock(DistributionQueueItem.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(queueItem)).thenReturn(new DistributionQueueEntry(null, queueItem, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 15 with DistributionQueueProvider

use of org.apache.sling.distribution.queue.DistributionQueueProvider in project sling by apache.

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithSucceedingItemDelivery.

@Test
public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(any(DistributionQueueItem.class))).thenReturn(new DistributionQueueEntry(null, null, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Aggregations

DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)25 Test (org.junit.Test)20 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)17 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)13 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)13 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)13 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)13 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)12 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)12 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)8 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)8 SlingRepository (org.apache.sling.jcr.api.SlingRepository)8 SimpleDistributionQueue (org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue)7 HashMap (java.util.HashMap)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 DistributionRequest (org.apache.sling.distribution.DistributionRequest)5 DistributionResponse (org.apache.sling.distribution.DistributionResponse)5 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)5 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)5