use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class SimpleDistributionAgentTest method testDistributionWithWorkingDistributionStrategy.
@Test
public void testDistributionWithWorkingDistributionStrategy() 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 distributionHandler = mock(DistributionQueueDispatchingStrategy.class);
DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "subServiceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, distributionHandler, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, null, 0);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
final DistributionPackage distributionPackage = mock(DistributionPackage.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
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);
assertNotNull(response);
assertEquals("[QUEUED]", response.getMessage());
assertEquals(DistributionRequestState.ACCEPTED, response.getState());
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo 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);
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class AsyncDeliveryDispatchingStrategyTest method testAddWithOneItemInRunningQueues.
@Test
public void testAddWithOneItemInRunningQueues() throws Exception {
Map<String, String> deliveryMappings = new HashMap<String, String>();
String queue1 = "queue1";
deliveryMappings.put(queue1, "delivery1");
String queue2 = "queue2";
deliveryMappings.put(queue2, "delivery2");
AsyncDeliveryDispatchingStrategy asyncDeliveryDispatchingStrategy = new AsyncDeliveryDispatchingStrategy(deliveryMappings);
// setup package
SharedDistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
when(distributionPackage.getId()).thenReturn("1221312");
DistributionPackageInfo info = new DistributionPackageInfo("dummy", new HashMap<String, Object>());
when(distributionPackage.getInfo()).thenReturn(info);
// setup queues
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionQueue dq1 = mock(DistributionQueue.class);
DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
DistributionQueueEntry entry = new DistributionQueueEntry("1242112", new DistributionQueueItem(distributionPackage.getId(), new HashMap<String, Object>()), status);
when(dq1.add(any(DistributionQueueItem.class))).thenReturn(entry);
DistributionQueueStatus status1 = new DistributionQueueStatus(1, DistributionQueueState.RUNNING);
when(dq1.getStatus()).thenReturn(status1);
when(queueProvider.getQueue(queue1)).thenReturn(dq1);
DistributionQueue dq2 = mock(DistributionQueue.class);
when(dq2.add(any(DistributionQueueItem.class))).thenReturn(entry);
DistributionQueueStatus status2 = new DistributionQueueStatus(1, DistributionQueueState.RUNNING);
when(dq2.getStatus()).thenReturn(status2);
when(queueProvider.getQueue(queue2)).thenReturn(dq2);
Iterable<DistributionQueueItemStatus> statuses = asyncDeliveryDispatchingStrategy.add(distributionPackage, queueProvider);
assertNotNull(statuses);
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class JobHandlingUtilsTest method testFullPropertiesFromPackageCreation.
@Test
public void testFullPropertiesFromPackageCreation() throws Exception {
DistributionPackageInfo packageInfo = new DistributionPackageInfo("vlt");
packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/foo" });
packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
packageInfo.put(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, "vlt");
DistributionQueueItem queueItem = new DistributionQueueItem("an-id", packageInfo);
Map<String, Object> fullPropertiesFromPackage = JobHandlingUtils.createFullProperties(queueItem);
assertNotNull(fullPropertiesFromPackage);
assertEquals(5, fullPropertiesFromPackage.size());
assertNotNull(fullPropertiesFromPackage.get("distribution.request.paths"));
assertNotNull(fullPropertiesFromPackage.get("distribution.item.id"));
assertNotNull(fullPropertiesFromPackage.get("distribution.package.size"));
assertNotNull(fullPropertiesFromPackage.get("distribution.package.type"));
assertNotNull(fullPropertiesFromPackage.get("distribution.request.type"));
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class JobHandlingDistributionQueueTest method testPackageAddition.
@SuppressWarnings("unchecked")
@Test
public void testPackageAddition() throws Exception {
JobManager jobManager = mock(JobManager.class);
JobBuilder builder = mock(JobBuilder.class);
when(builder.properties(any(Map.class))).thenReturn(builder);
Job job = mock(Job.class);
when(job.getId()).thenReturn("id-123");
when(builder.add()).thenReturn(job);
String topic = JobHandlingDistributionQueue.DISTRIBUTION_QUEUE_TOPIC + "/aname";
when(jobManager.createJob(topic)).thenReturn(builder);
when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet());
when(builder.properties(any(Map.class))).thenReturn(builder);
DistributionQueue queue = new JobHandlingDistributionQueue("aname", topic, jobManager, true, DistributionQueueType.ORDERED);
DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/foo" });
packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
DistributionQueueItem distributionQueueItem = new DistributionQueueItem("an-id", packageInfo);
assertNotNull(queue.add(distributionQueueItem));
}
Aggregations