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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations