Search in sources :

Example 6 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