Search in sources :

Example 1 with JackrabbitEventFilter

use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter 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 2 with JackrabbitEventFilter

use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter 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)

Example 3 with JackrabbitEventFilter

use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.

the class ObservationTest method disjunctPaths.

@Test
public void disjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    assumeTrue(observationManager instanceof JackrabbitObservationManager);
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths(TEST_PATH + "/a", TEST_PATH + "/x").setEventTypes(NODE_ADDED);
    oManager.addEventListener(listener, filter);
    Node testNode = getNode(TEST_PATH);
    Node b = testNode.addNode("a").addNode("b");
    b.addNode("c");
    Node y = testNode.addNode("x").addNode("y");
    y.addNode("z");
    listener.expect(b.getPath(), NODE_ADDED);
    listener.expect(y.getPath(), NODE_ADDED);
    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 : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 4 with JackrabbitEventFilter

use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.

the class ObservationTest method includeAncestorsRemove_WithGlobs.

@Test
public void includeAncestorsRemove_WithGlobs() throws Exception {
    OakEventFilter oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/a/b/c/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/a/b/*/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/a/*/*/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/*/b/*/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/*/b/c/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/*/*/c/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/*/*/*/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/a/**/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/**/c/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths("/**/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
    oef = FilterFactory.wrap(new JackrabbitEventFilter());
    oef.setEventTypes(ALL_EVENTS);
    oef.withIncludeGlobPaths(TEST_PATH + "/**/d.jsp");
    oef.setIsDeep(true);
    oef.withIncludeAncestorsRemove();
    doIncludeAncestorsRemove_WithGlobs(oef);
}
Also used : JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) OakEventFilter(org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 5 with JackrabbitEventFilter

use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.

the class ObservationTest method includeRemovedSubtree.

@Test
public void includeRemovedSubtree() 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();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter.setAbsPath("/");
    filter.setIsDeep(true);
    filter = FilterFactory.wrap(filter).withIncludeSubtreeOnRemove();
    oManager.addEventListener(listener, filter);
    listener.expectRemove(testNode.getNode("a").getNode("c"));
    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 : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Aggregations

JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)25 Node (javax.jcr.Node)19 Event (javax.jcr.observation.Event)19 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)19 Test (org.junit.Test)19 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)18 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)7 FilterProvider (org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)6 OakEventFilter (org.apache.jackrabbit.oak.jcr.observation.filter.OakEventFilter)5 Property (javax.jcr.Property)3 Session (javax.jcr.Session)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 NodeDefinition (javax.jcr.nodetype.NodeDefinition)1 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)1 ObservationManager (javax.jcr.observation.ObservationManager)1 ExcludeExternal (org.apache.jackrabbit.oak.plugins.observation.ExcludeExternal)1 EventResult (org.apache.jackrabbit.test.api.observation.EventResult)1