use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class SimpleDistributionAgentTest method testDistributionWithFailingDistributionStrategy.
@Test
public void testDistributionWithFailingDistributionStrategy() 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);
Iterable<DistributionQueueItemStatus> states = Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME));
when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states);
DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", 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"));
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("[ERROR]", response.getMessage());
assertEquals(DistributionRequestState.DROPPED, response.getState());
}
use of org.apache.sling.distribution.DistributionRequest 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.DistributionRequest in project sling by apache.
the class TriggerAgentRequestHandlerTest method testHandleActive.
@Test
public void testHandleActive() throws Exception {
DistributionAgent agent = mock(DistributionAgent.class);
SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
DefaultDistributionLog log = mock(DefaultDistributionLog.class);
TriggerAgentRequestHandler triggerAgentRequestHandler = new TriggerAgentRequestHandler(agent, authenticationInfo, log, true);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest request = mock(DistributionRequest.class);
triggerAgentRequestHandler.handle(resourceResolver, request);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategyTest method testPermissionOnAdd.
@Test
public void testPermissionOnAdd() throws Exception {
String jcrPrivilege = "somePermission";
PrivilegeDistributionRequestAuthorizationStrategy strategy = new PrivilegeDistributionRequestAuthorizationStrategy(jcrPrivilege);
DistributionRequest distributionRequest = mock(DistributionRequest.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
AccessControlManager acm = mock(AccessControlManager.class);
Privilege privilege = mock(Privilege.class);
when(acm.privilegeFromName(jcrPrivilege)).thenReturn(privilege);
Privilege jcrReadPrivilege = mock(Privilege.class);
when(acm.privilegeFromName(Privilege.JCR_READ)).thenReturn(jcrReadPrivilege);
when(session.getAccessControlManager()).thenReturn(acm);
when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
String[] paths = new String[] { "/foo" };
for (String path : paths) {
when(acm.hasPrivileges(path, new Privilege[] { privilege, jcrReadPrivilege })).thenReturn(true);
}
when(distributionRequest.getPaths()).thenReturn(paths);
when(distributionRequest.getRequestType()).thenReturn(DistributionRequestType.ADD);
strategy.checkPermission(resourceResolver, distributionRequest);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class PrivilegeDistributionRequestAuthorizationStrategyTest method testNoPermissionOnAdd.
@Test(expected = DistributionException.class)
public void testNoPermissionOnAdd() throws Exception {
String jcrPrivilege = "somePermission";
PrivilegeDistributionRequestAuthorizationStrategy strategy = new PrivilegeDistributionRequestAuthorizationStrategy(jcrPrivilege);
DistributionRequest distributionRequest = mock(DistributionRequest.class);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
AccessControlManager acm = mock(AccessControlManager.class);
Privilege privilege = mock(Privilege.class);
when(acm.privilegeFromName(jcrPrivilege)).thenReturn(privilege);
when(session.getAccessControlManager()).thenReturn(acm);
when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
String[] paths = new String[] { "/foo" };
for (String path : paths) {
when(acm.hasPrivileges(path, new Privilege[] { privilege })).thenReturn(false);
}
when(distributionRequest.getPaths()).thenReturn(paths);
when(distributionRequest.getRequestType()).thenReturn(DistributionRequestType.ADD);
strategy.checkPermission(resourceResolver, distributionRequest);
}
Aggregations