use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method testReorder.
@Test
public void testReorder() throws RepositoryException, InterruptedException, ExecutionException {
Node testNode = getNode(TEST_PATH);
Node nodeA = testNode.addNode("a", "nt:unstructured");
Node nodeB = testNode.addNode("b", "nt:unstructured");
testNode.getSession().save();
ExpectationListener listener = new ExpectationListener();
observationManager.addEventListener(listener, NODE_MOVED, "/", true, null, null, false);
listener.expect(new Expectation("orderBefore") {
@Override
public boolean onEvent(Event event) throws Exception {
if (event.getType() != NODE_MOVED || event.getInfo() == null) {
return false;
}
Map<?, ?> info = event.getInfo();
if (PathUtils.concat(TEST_PATH, "a").equals(event.getPath())) {
return "a".equals(info.get("srcChildRelPath")) && "b".equals(info.get("destChildRelPath"));
} else if (PathUtils.concat(TEST_PATH, "b").equals(event.getPath())) {
return "b".equals(info.get("srcChildRelPath")) && "a".equals(info.get("destChildRelPath"));
} else {
return false;
}
}
});
testNode.orderBefore(nodeA.getName(), null);
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 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 javax.jcr.observation.Event 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());
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method observationOnRootNode.
@Test
public void observationOnRootNode() throws Exception {
ExpectationListener listener = new ExpectationListener();
observationManager.addEventListener(listener, PROPERTY_ADDED, "/", true, null, null, false);
try {
// add property to root node
Node root = getNode("/");
listener.expectAdd(root.setProperty("prop", "value"));
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 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());
}
Aggregations