use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method testConsecutiveGlobPaths.
@Test
public void testConsecutiveGlobPaths() throws Exception {
Node testNode = getNode(TEST_PATH);
Node a1 = testNode.addNode("a1");
a1.addNode("b1").addNode("c1");
a1.addNode("b2").addNode("c2");
testNode.addNode("a2").addNode("b").addNode("c");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a2/**").withIncludeGlobPaths(TEST_PATH + "/a1/**");
oManager.addEventListener(listener, filter);
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a1", TEST_PATH + "/a2");
listener.expectRemove(testNode.getNode("a1").getNode("b2")).remove();
listener.expectRemove(testNode.getNode("a2").getNode("b")).remove();
testNode.getSession().save();
Thread.sleep(1000);
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 javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method pathFilterWithTrailingSlash.
@Test
public void pathFilterWithTrailingSlash() throws Exception {
final String path = "/events/only/here";
ExpectationListener listener = new ExpectationListener();
listener.expect(new Expectation(path) {
@Override
public boolean onEvent(Event event) throws Exception {
return PathUtils.isAncestor(path, event.getPath());
}
});
observationManager.addEventListener(listener, NODE_ADDED, path + '/', true, null, null, false);
try {
Node root = getNode("/");
root.addNode("events").addNode("only").addNode("here").addNode("at");
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);
}
}
use of javax.jcr.observation.Event 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 javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method addSubtree.
@Test
public void addSubtree() throws RepositoryException, ExecutionException, InterruptedException {
ExpectationListener listener = new ExpectationListener();
observationManager.addEventListener(listener, ALL_EVENTS, "/", true, null, null, false);
Node n = getNode(TEST_PATH);
Node a = listener.expectAdd(n.addNode("a"));
Node b = listener.expectAdd(a.addNode("b"));
listener.expectAdd(b.addNode("c"));
getAdminSession().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 javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method pathExclude.
@Test
public void pathExclude() throws ExecutionException, InterruptedException, RepositoryException {
assumeTrue(observationManager instanceof JackrabbitObservationManager);
JackrabbitObservationManager oManager = (JackrabbitObservationManager) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAbsPath(TEST_PATH).setIsDeep(true).setExcludedPaths(TEST_PATH + "/c", TEST_PATH + "/d", "/x/y").setEventTypes(ALL_EVENTS);
oManager.addEventListener(listener, filter);
Node n = getNode(TEST_PATH);
listener.expectAdd(listener.expectAdd(listener.expectAdd(n.addNode("a")).addNode("a1")).setProperty("p", "q"));
listener.expectAdd(listener.expectAdd(n.addNode("b")).setProperty("p", "q"));
n.addNode("c").addNode("c1").setProperty("p", "q");
n.addNode("d").setProperty("p", "q");
getAdminSession().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