use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class SimpleDistributionAgentTest method testDistributionWithDisallowedRoot.
@Test
public void testDistributionWithDisallowedRoot() 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, "/home");
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);
assertFalse(response.isSuccessful());
}
use of org.apache.sling.distribution.DistributionRequest 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());
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class AbstractJcrEventTrigger method addToList.
void addToList(DistributionRequest request, List<DistributionRequest> requestList) {
DistributionRequest lastRequest = requestList.isEmpty() ? null : requestList.get(requestList.size() - 1);
log.debug("adding request {} to {}", request, requestList);
if (lastRequest == null || !lastRequest.getRequestType().equals(request.getRequestType())) {
requestList.add(request);
} else if (hasDeepPaths(request) || hasDeepPaths(lastRequest)) {
requestList.add(request);
} else {
Set<String> allPaths = new TreeSet<String>();
allPaths.addAll(Arrays.asList(lastRequest.getPaths()));
allPaths.addAll(Arrays.asList(request.getPaths()));
addMissingPaths(allPaths);
lastRequest = new SimpleDistributionRequest(lastRequest.getRequestType(), allPaths.toArray(new String[allPaths.size()]));
requestList.set(requestList.size() - 1, lastRequest);
}
log.debug("current requests {}", requestList);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class JcrEventDistributionTrigger method processEvent.
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
DistributionRequest distributionRequest = null;
String eventPath = event.getPath();
String replicatingPath = getNodePathFromEvent(event);
if (!isIgnoredPath(replicatingPath)) {
if (VltUtils.findParent(replicatingPath, "rep:policy") != null) {
// distribute all policies
replicatingPath = VltUtils.findParent(replicatingPath, "rep:policy") + "/rep:policy";
distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, replicatingPath);
} else if (VltUtils.findParent(replicatingPath, "rep:membersList") != null || eventPath.endsWith("/rep:members")) {
// group member list structure is an implementation detail and it is safer to distribute the entire group.
String groupPath = VltUtils.findParent(replicatingPath, "rep:membersList");
if (groupPath != null) {
replicatingPath = groupPath;
}
distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, true, replicatingPath);
} else {
distributionRequest = new SimpleDistributionRequest(Event.NODE_REMOVED == event.getType() ? DistributionRequestType.DELETE : DistributionRequestType.ADD, deep, replicatingPath);
}
log.info("distributing {}", distributionRequest);
}
return distributionRequest;
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class TriggerAgentRequestHandlerTest method testHandlePassive.
@Test
public void testHandlePassive() throws Exception {
DistributionAgent agent = mock(DistributionAgent.class);
SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
DefaultDistributionLog log = mock(DefaultDistributionLog.class);
TriggerAgentRequestHandler triggerAgentRequestHandler = new TriggerAgentRequestHandler(agent, authenticationInfo, log, false);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest request = mock(DistributionRequest.class);
triggerAgentRequestHandler.handle(resourceResolver, request);
}
Aggregations