Search in sources :

Example 1 with FilterBuilder

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder 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 2 with FilterBuilder

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder in project jackrabbit-oak by apache.

the class ObservationTest method filterDisjunctPaths.

@Test
public void filterDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    assumeTrue(observationManager instanceof JackrabbitObservationManager);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    builder.condition(builder.any(builder.path(TEST_PATH + "/a/b"), builder.path(TEST_PATH + "/x/y")));
    oManager.addEventListener(listener, builder.build());
    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) 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 FilterBuilder

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder in project jackrabbit-oak by apache.

the class ObservationTest method filterPropertyOfChild.

@Test
public void filterPropertyOfChild() throws RepositoryException, ExecutionException, InterruptedException {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    // Events for all items that have a property "b/c/foo" with value "bar"
    builder.condition(builder.property(Selectors.fromThis("b/c"), "foo", new Predicate<PropertyState>() {

        @Override
        public boolean apply(PropertyState property) {
            return "bar".equals(property.getValue(STRING));
        }
    }));
    oManager.addEventListener(listener, builder.build());
    Node testNode = getNode(TEST_PATH);
    Node a = testNode.addNode("a");
    a.addNode("b").addNode("c").setProperty("foo", "bar");
    a.addNode("d");
    Node x = testNode.addNode("x");
    x.addNode("b").addNode("c").setProperty("foo", "baz");
    x.addNode("d");
    listener.expect(a.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 : FilterBuilder(org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Predicate(com.google.common.base.Predicate) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 4 with FilterBuilder

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder in project jackrabbit-oak by apache.

the class ObservationTest method addSubtreeFilter.

@Test
public void addSubtreeFilter() throws RepositoryException, ExecutionException, InterruptedException {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    // Only generate events for the root of added sub trees
    builder.condition(builder.addSubtree());
    oManager.addEventListener(listener, builder.build());
    Node testNode = getNode(TEST_PATH);
    Node a = listener.expectAdd(testNode.addNode("a"));
    a.addNode("c");
    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 5 with FilterBuilder

use of org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder in project jackrabbit-oak by apache.

the class ObservationTest method filterPropertyOfParent.

@Test
public void filterPropertyOfParent() throws RepositoryException, ExecutionException, InterruptedException {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    FilterBuilder builder = new FilterBuilder();
    // Events for all items whose parent has a property named "foo" with value "bar"
    builder.condition(builder.property(Selectors.PARENT, "foo", new Predicate<PropertyState>() {

        @Override
        public boolean apply(PropertyState property) {
            return "bar".equals(property.getValue(STRING));
        }
    }));
    oManager.addEventListener(listener, builder.build());
    Node testNode = getNode(TEST_PATH);
    Node a = testNode.addNode("a");
    Node x = testNode.addNode("x");
    a.setProperty("foo", "bar");
    x.setProperty("foo", "baz");
    a.addNode("b");
    x.addNode("y");
    listener.expect(a.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    listener.expect(a.getPath() + "/foo", PROPERTY_ADDED);
    listener.expect(a.getPath() + "/b", 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 : FilterBuilder(org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) Predicate(com.google.common.base.Predicate) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Aggregations

FilterBuilder (org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder)6 Node (javax.jcr.Node)5 Event (javax.jcr.observation.Event)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)5 Test (org.junit.Test)5 Predicate (com.google.common.base.Predicate)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)1 ListenerTracker (org.apache.jackrabbit.commons.observation.ListenerTracker)1 ExcludeExternal (org.apache.jackrabbit.oak.plugins.observation.ExcludeExternal)1 ChangeSetFilterImpl (org.apache.jackrabbit.oak.plugins.observation.filter.ChangeSetFilterImpl)1 Condition (org.apache.jackrabbit.oak.plugins.observation.filter.FilterBuilder.Condition)1 Selector (org.apache.jackrabbit.oak.plugins.observation.filter.UniversalFilter.Selector)1