Search in sources :

Example 1 with Event

use of javax.jcr.observation.Event in project jackrabbit-oak by apache.

the class ObservationTest method testReorder.

@Test
public void testReorder() throws RepositoryException, InterruptedException, ExecutionException {
    Node testNode = getNode(TEST_PATH);
    Node nodeA = testNode.addNode("a", "nt:unstructured");
    Node nodeB = testNode.addNode("b", "nt:unstructured");
    testNode.getSession().save();
    ExpectationListener listener = new ExpectationListener();
    observationManager.addEventListener(listener, NODE_MOVED, "/", true, null, null, false);
    listener.expect(new Expectation("orderBefore") {

        @Override
        public boolean onEvent(Event event) throws Exception {
            if (event.getType() != NODE_MOVED || event.getInfo() == null) {
                return false;
            }
            Map<?, ?> info = event.getInfo();
            if (PathUtils.concat(TEST_PATH, "a").equals(event.getPath())) {
                return "a".equals(info.get("srcChildRelPath")) && "b".equals(info.get("destChildRelPath"));
            } else if (PathUtils.concat(TEST_PATH, "b").equals(event.getPath())) {
                return "b".equals(info.get("srcChildRelPath")) && "a".equals(info.get("destChildRelPath"));
            } else {
                return false;
            }
        }
    });
    testNode.orderBefore(nodeA.getName(), null);
    testNode.getSession().save();
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Map(java.util.Map) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) TimeoutException(java.util.concurrent.TimeoutException) VersionException(javax.jcr.version.VersionException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) ExecutionException(java.util.concurrent.ExecutionException) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 2 with Event

use of javax.jcr.observation.Event in project jackrabbit-oak by apache.

the class ObservationTest method removeSubtreeFilter.

@Test
public void removeSubtreeFilter() throws RepositoryException, ExecutionException, InterruptedException {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    Node testNode = getNode(TEST_PATH);
    testNode.addNode("a").addNode("c");
    testNode.getSession().save();
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    // Only generate events for the root of deleted sub trees
    builder.condition(builder.deleteSubtree());
    oManager.addEventListener(listener, builder.build());
    listener.expectRemove(testNode.getNode("a")).remove();
    testNode.getSession().save();
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : FilterBuilder(org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 3 with Event

use of javax.jcr.observation.Event in project jackrabbit-oak by apache.

the class ObservationTest method testAggregate4.

@Test
public void testAggregate4() throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**/foo/**" }).withIncludeGlobPaths("/parent/**/bar/**");
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), "/parent");
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    Node a = parent.addNode("a", "nt:unstructured");
    Node b = a.addNode("b", "nt:unstructured");
    Node bar = b.addNode("bar", "oak:Unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expect(bar.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node c = bar.addNode("c", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(c);
    Node foo = c.addNode("foo", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(foo);
    Node jcrContent = foo.addNode("jcr:content", "nt:unstructured");
    listener.expectAdd(jcrContent);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 4 with Event

use of javax.jcr.observation.Event in project jackrabbit-oak by apache.

the class ObservationTest method observationOnRootNode.

@Test
public void observationOnRootNode() throws Exception {
    ExpectationListener listener = new ExpectationListener();
    observationManager.addEventListener(listener, PROPERTY_ADDED, "/", true, null, null, false);
    try {
        // add property to root node
        Node root = getNode("/");
        listener.expectAdd(root.setProperty("prop", "value"));
        root.getSession().save();
        List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
        assertTrue("Missing events: " + missing, missing.isEmpty());
        List<Event> unexpected = listener.getUnexpected();
        assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    } finally {
        observationManager.removeEventListener(listener);
    }
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 5 with Event

use of javax.jcr.observation.Event in project jackrabbit-oak by apache.

the class ObservationTest method testAggregate3.

@Test
public void testAggregate3() throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setAbsPath("/parent");
    filter.setIsDeep(true);
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**" });
    oManager.addEventListener(listener, filter);
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expect(parent.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node child = parent.addNode("child", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(child);
    Node file = child.addNode("file", "oak:Unstructured");
    listener.expect(file.getPath(), "/parent/child/file", NODE_ADDED);
    listener.expect(file.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
    Node jcrContent = file.addNode("jcr:content", "nt:unstructured");
    listener.expect(jcrContent.getPath(), "/parent/child/file", NODE_ADDED);
    listener.expect(jcrContent.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
    Property jcrDataProperty = jcrContent.setProperty("jcr:data", "foo");
    listener.expect(jcrDataProperty.getPath(), "/parent/child/file", PROPERTY_ADDED);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) Property(javax.jcr.Property) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Aggregations

Event (javax.jcr.observation.Event)138 Node (javax.jcr.Node)104 Test (org.junit.Test)56 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)46 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)41 RepositoryException (javax.jcr.RepositoryException)31 Session (javax.jcr.Session)21 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)19 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)17 EventIterator (javax.jcr.observation.EventIterator)16 ObservationManager (javax.jcr.observation.ObservationManager)14 Property (javax.jcr.Property)13 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 ArrayList (java.util.ArrayList)9 EventListener (javax.jcr.observation.EventListener)9 Scheduler (org.apache.sling.commons.scheduler.Scheduler)9 DistributionRequest (org.apache.sling.distribution.DistributionRequest)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)8 ExecutionException (java.util.concurrent.ExecutionException)7 PathNotFoundException (javax.jcr.PathNotFoundException)7