use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method doIncludeAncestorsRemove.
private FilterProvider doIncludeAncestorsRemove(JackrabbitEventFilter filter) throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
Node testNode = getNode(TEST_PATH);
testNode.addNode("a").addNode("b").addNode("c").addNode("d").setProperty("e", 42);
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
oManager.addEventListener(listener, filter);
Node d = testNode.getNode("a").getNode("b").getNode("c").getNode("d");
Property e = d.getProperty("e");
listener.expectRemove(e);
// listener.expectRemove(d.getProperty("jcr:primaryType"));
// d.remove();
listener.expectRemove(d).remove();
testNode.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());
oManager.addEventListener(new EventListener() {
@Override
public void onEvent(EventIterator events) {
while (events.hasNext()) {
System.out.println("/a-listener GOT: " + events.next());
}
}
}, NODE_REMOVED, TEST_PATH + "/a", false, null, null, false);
System.out.println("REGISTERED");
testNode = getNode(TEST_PATH);
Node b = testNode.getNode("a").getNode("b");
listener.expect(b.getPath(), NODE_REMOVED);
listener.optional(new Expectation("/a/b/c is optionally sent depending on filter") {
@Override
public boolean onEvent(Event event) throws Exception {
if (event.getPath().equals(TEST_PATH + "/a/b/c") && event.getType() == NODE_REMOVED) {
return true;
}
return false;
}
});
b.remove();
// but not the jcr:primaryType
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
unexpected = listener.getUnexpected();
assertTrue("Missing events: " + missing, missing.isEmpty());
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
Node a = testNode.getNode("a");
listener.expect(a.getPath(), NODE_REMOVED);
a.remove();
// but not the jcr:primaryType
testNode.getSession().save();
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
return filterProvider;
}
use of javax.jcr.observation.Event in project jackrabbit-oak by apache.
the class ObservationTest method applyNodeTypeOnSelf.
// ------------------------------------------------------------< OakEventFilter tests >---
@Test
public void applyNodeTypeOnSelf() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
Node testNode = getNode(TEST_PATH);
testNode.addNode("a", "nt:unstructured").addNode("b", "oak:Unstructured").addNode("c", "nt:unstructured");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter.setAbsPath("/");
filter.setIsDeep(true);
filter.setNodeTypes(new String[] { "oak:Unstructured" });
filter = FilterFactory.wrap(filter).withApplyNodeTypeOnSelf();
oManager.addEventListener(listener, filter);
testNode.getNode("a").getNode("b").getNode("c").remove();
testNode.getSession().save();
// wait 1 sec to give failures a chance (we're not expecting anything, but perhaps
// something would come, after 1sec more likely than after 0sec)
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());
Node b = testNode.getNode("a").getNode("b");
// OAK-5061 : the event NODE_REMOVED on /a/b is actually expected and was missing in the test:
listener.expect(b.getPath(), NODE_REMOVED);
b.remove();
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
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 testAggregate5.
/**
* OAK-5096 : new test case for OR mode
*/
@Test
public void testAggregate5() 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 bar = parent.addNode("bar", "nt:unstructured");
listener.expect(bar.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node c = bar.addNode("c", "nt:unstructured");
listener.expectAdd(c);
Node foo = c.addNode("foo", "nt:unstructured");
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 includeGlobPaths.
@Test
public void includeGlobPaths() throws Exception {
Node testNode = getNode(TEST_PATH);
testNode.addNode("a1").addNode("b").addNode("c");
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/**");
oManager.addEventListener(listener, filter);
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a2");
testNode.getNode("a1").getNode("b").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());
Node a3 = testNode.addNode("a3");
Node foo = a3.addNode("bar").addNode("foo");
testNode.getSession().save();
filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
// filter.setAbsPath(TEST_PATH + "/a3/bar/foo/x");
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/x");
oManager.addEventListener(listener, filter);
cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
Node x = foo.addNode("x");
listener.expect(x.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/y");
oManager.addEventListener(listener, filter);
cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
Node y = foo.addNode("y");
listener.expect(y.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
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 testEventRemovedNodeWhenDenyEntryIsRemoved.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-4196">OAK-4196</a>
*/
@Test
public void testEventRemovedNodeWhenDenyEntryIsRemoved() throws Exception {
// withdraw the READ privilege on childNPath
deny(childNPath, readPrivileges);
assertFalse(testSession.nodeExists(childNPath));
assertTrue(testSession.nodeExists(childNPath2));
// testUser registers a event listener for changes under testRoot
ObservationManager obsMgr = testSession.getWorkspace().getObservationManager();
EventResult listener = new EventResult(this.log);
try {
obsMgr.addEventListener(listener, Event.NODE_REMOVED, testRoot, true, null, null, true);
// superuser removes the node with childNPath & childNPath2 in
// order to provoke events being generated
superuser.getItem(childNPath).remove();
superuser.getItem(childNPath2).remove();
superuser.save();
// since the events are generated _after_ persisting all the changes
// and the removal also removes the permission entries denying access
// testUser will be notified about the removal because the remaining
// permission setup after the removal grants read access.
Event[] evts = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
List<String> eventPaths = new ArrayList<String>();
for (Event evt : evts) {
if (evt.getType() == Event.NODE_REMOVED) {
eventPaths.add(evt.getPath());
}
}
assertTrue(eventPaths.contains(childNPath));
assertTrue(eventPaths.contains(childNPath2));
} finally {
obsMgr.removeEventListener(listener);
}
}
Aggregations