Search in sources :

Example 1 with DistributionRequestHandler

use of org.apache.sling.distribution.trigger.DistributionRequestHandler in project sling by apache.

the class ChainDistributionTriggerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    String pathPrefix = "/prefix";
    BundleContext bundleContext = mock(BundleContext.class);
    DistributionEventDistributeDistributionTrigger chainDistributeDistributionTrigger = new DistributionEventDistributeDistributionTrigger(pathPrefix, bundleContext);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    chainDistributeDistributionTrigger.unregister(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 2 with DistributionRequestHandler

use of org.apache.sling.distribution.trigger.DistributionRequestHandler in project sling by apache.

the class ChainDistributionTriggerTest method testRegister.

@Test
public void testRegister() throws Exception {
    String pathPrefix = "/prefix";
    BundleContext bundleContext = mock(BundleContext.class);
    DistributionEventDistributeDistributionTrigger chainDistributeDistributionTrigger = new DistributionEventDistributeDistributionTrigger(pathPrefix, bundleContext);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    chainDistributeDistributionTrigger.register(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 3 with DistributionRequestHandler

use of org.apache.sling.distribution.trigger.DistributionRequestHandler in project sling by apache.

the class PersistingJcrEventDistributionTriggerTest method testProcessEventWithPrivilegesAndNoNuggetsNode.

@Test
public void testProcessEventWithPrivilegesAndNoNuggetsNode() throws Exception {
    String nuggetsPath = "/var/nuggets";
    String serviceName = "serviceId";
    Session session = mock(Session.class);
    // first time it doesn't exist and should be created
    when(session.nodeExists("/var/nuggets")).thenReturn(false);
    // second time it should exist
    when(session.nodeExists("/var/nuggets")).thenReturn(true);
    Node rootNode = mock(Node.class);
    Node varNode = mock(Node.class);
    Node nuggetsNode = mock(Node.class);
    when(varNode.addNode("nuggets", "sling:Folder")).thenReturn(nuggetsNode);
    when(rootNode.addNode("var", "sling:Folder")).thenReturn(varNode);
    when(session.getRootNode()).thenReturn(rootNode);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(session.hasPermission(any(String.class), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
    when(repository.loginService(serviceName, null)).thenReturn(session);
    String path = "/some/path";
    PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    persistingJcrEventdistributionTrigger.register(handler);
    Node eventNode = mock(Node.class);
    when(nuggetsNode.addNode(any(String.class), any(String.class))).thenReturn(eventNode);
    when(session.getNode(nuggetsPath)).thenReturn(nuggetsNode);
    Event event = mock(Event.class);
    when(event.getPath()).thenReturn("/some/path/generating/event");
    DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
    assertNotNull(distributionRequest);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 4 with DistributionRequestHandler

use of org.apache.sling.distribution.trigger.DistributionRequestHandler in project sling by apache.

the class RemoteEventDistributionTriggerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    remoteEventdistributionTrigger.unregister(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Example 5 with DistributionRequestHandler

use of org.apache.sling.distribution.trigger.DistributionRequestHandler in project sling by apache.

the class RemoteEventDistributionTriggerTest method testRegister.

@Test
public void testRegister() throws Exception {
    DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
    String endpoint = "";
    DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(options.name(handler.toString())).thenReturn(options);
    when(scheduler.NOW()).thenReturn(options);
    RemoteEventDistributionTrigger remoteEventdistributionTrigger = new RemoteEventDistributionTrigger(endpoint, distributionTransportSecretProvider, scheduler);
    remoteEventdistributionTrigger.register(handler);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Scheduler(org.apache.sling.commons.scheduler.Scheduler) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) Test(org.junit.Test)

Aggregations

DistributionRequestHandler (org.apache.sling.distribution.trigger.DistributionRequestHandler)11 Test (org.junit.Test)10 Scheduler (org.apache.sling.commons.scheduler.Scheduler)6 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)4 BundleContext (org.osgi.framework.BundleContext)4 DistributionRequest (org.apache.sling.distribution.DistributionRequest)3 Node (javax.jcr.Node)2 Session (javax.jcr.Session)2 Workspace (javax.jcr.Workspace)2 Event (javax.jcr.observation.Event)2 ObservationManager (javax.jcr.observation.ObservationManager)2 ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)2 DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)2 SlingRepository (org.apache.sling.jcr.api.SlingRepository)2 PrintWriter (java.io.PrintWriter)1 Dictionary (java.util.Dictionary)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1