use of org.apache.sling.api.resource.ResourceResolverFactory 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.api.resource.ResourceResolverFactory 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"));
}
use of org.apache.sling.api.resource.ResourceResolverFactory in project sling by apache.
the class ImportingDistributionPackageProcessorTest method testProcess.
@Test
public void testProcess() throws Exception {
DistributionPackageImporter importer = mock(DistributionPackageImporter.class);
SlingRepository repository = mock(SlingRepository.class);
String agentService = "agentService";
ResourceResolverFactory resourceResolverFactory = mock(ResourceResolverFactory.class);
String subServiceName = "ssn";
SimpleDistributionAgentAuthenticationInfo authInfo = new SimpleDistributionAgentAuthenticationInfo(repository, agentService, resourceResolverFactory, subServiceName);
String callingUser = "foo";
String requestId = "123";
DefaultDistributionLog log = mock(DefaultDistributionLog.class);
ImportingDistributionPackageProcessor processor = new ImportingDistributionPackageProcessor(importer, authInfo, callingUser, requestId, log);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
Map<String, Object> map = new HashMap<String, Object>();
map.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, "/");
map.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.TEST);
DistributionPackageInfo info = new DistributionPackageInfo("foo", map);
when(distributionPackage.getInfo()).thenReturn(info);
processor.process(distributionPackage);
}
use of org.apache.sling.api.resource.ResourceResolverFactory in project sling by apache.
the class MergedResourceProviderTestForOverridingPicker method setup.
/*
* Tree is:
* /apps/a/1/a
* /apps/a/1/b
* /apps/a/1/b/1
* /apps/a/1/d
* /apps/a/1/d/1
* /apps/a/1/d/1/a
* /apps/a/1/d/1/b/1
* /apps/a/1/c
* /apps/a/2/c
* /apps/a/3
*
* /apps/a/2 has the super type of /apps/a/1
* /apps/a/3 has the super type of /apps/a/2
*
* /apps/a/4 has the super type of /apps/a/4/b/4
* /apps/x has the super type of x/y
*/
@Before
public void setup() throws Exception {
final MockResourceResolverFactoryOptions options = new MockResourceResolverFactoryOptions();
options.setSearchPaths(new String[] { "/apps", "/libs" });
final ResourceResolverFactory factory = new MockResourceResolverFactory(options);
this.resolver = factory.getAdministrativeResourceResolver(null);
MockHelper.create(this.resolver).resource("/apps").resource("a").resource("1").p("a", "1").p("b", "1").resource("a").p("1", "a").p("2", "b").resource(".b").p("1", "a").p("2", "b").resource("1").resource("/apps/a/1/d").p("a", "1").p("b", "2").resource("1").p("1", "a").p("2", "b").resource("a").resource("/apps/a/1/d/1/b").resource("1").resource("/apps/a/1/c").p("1", "a").p("2", "b").resource("/apps/a/2").p(SUPER_TYPE, "a/1").p("b", "2").p(MergedResourceConstants.PN_HIDE_CHILDREN, new String[] { "b" }).resource("c").p("1", "c").resource("/apps/a/3").p(SUPER_TYPE, "a/2").resource("/apps/a/4").p(SUPER_TYPE, "/apps/a/4/b/4").resource("b").resource("4").resource("d").resource("/apps/x").p(SUPER_TYPE, "x/y").resource("y").resource("z").commit();
this.provider = new MergingResourceProvider("/override", new OverridingResourcePicker(), false, true);
this.ctx = new BasicResolveContext(resolver);
}
use of org.apache.sling.api.resource.ResourceResolverFactory in project sling by apache.
the class CommonMergedResourceProviderTest method setup.
@Before
public void setup() throws LoginException, PersistenceException {
final ResourceResolverFactory factory = new MockResourceResolverFactory();
this.resolver = factory.getResourceResolver(null);
this.ctx = new BasicResolveContext<Void>(resolver);
MockHelper.create(this.resolver).resource("/apps").resource("base").resource("/apps/overlay").commit();
base = this.resolver.getResource("/apps/base");
overlay = this.resolver.getResource("/apps/overlay");
this.provider = new CRUDMergingResourceProvider("/merged", new SimpleMergedResourcePicker(), false);
}
Aggregations