Search in sources :

Example 16 with ResourceResolverFactory

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());
}
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 17 with ResourceResolverFactory

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"));
}
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 18 with ResourceResolverFactory

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);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Example 19 with ResourceResolverFactory

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);
}
Also used : ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) MockResourceResolverFactoryOptions(org.apache.sling.testing.resourceresolver.MockResourceResolverFactoryOptions) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) OverridingResourcePicker(org.apache.sling.resourcemerger.impl.picker.OverridingResourcePicker) Before(org.junit.Before)

Example 20 with ResourceResolverFactory

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);
}
Also used : ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) Before(org.junit.Before)

Aggregations

ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)41 Test (org.junit.Test)26 SlingRepository (org.apache.sling.jcr.api.SlingRepository)22 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)16 DistributionRequest (org.apache.sling.distribution.DistributionRequest)13 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)12 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)12 Before (org.junit.Before)10 Event (javax.jcr.observation.Event)8 Scheduler (org.apache.sling.commons.scheduler.Scheduler)8 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)8 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)8 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)8 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)7 SimpleDistributionQueue (org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueue)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)7 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)6 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)6 Resource (org.apache.sling.api.resource.Resource)5