use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class ShareableNodesTest method testAddShareableMixin.
public void testAddShareableMixin() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1);
testRootNode.save();
EventResult result = new EventResult(log);
addEventListener(result);
n1.addMixin(mixShareable);
testRootNode.save();
Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
for (int i = 0; i < events.length; i++) {
assertFalse("must not contain node added event", events[i].getType() == Event.NODE_ADDED);
assertFalse("must not contain node removed event", events[i].getType() == Event.NODE_REMOVED);
}
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class VersionEventsTest method testCheckinOtherWorkspace.
/**
* Test if checkin creates events also on a different workspace than the one
* where the checkin was executed.
*/
public void testCheckinOtherWorkspace() throws RepositoryException {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
Session s = getHelper().getReadOnlySession(workspaceName);
try {
EventResult listener = new EventResult(log);
ObservationManager obsMgr = s.getWorkspace().getObservationManager();
obsMgr.addEventListener(listener, Event.NODE_ADDED, "/", true, null, null, false);
Version v = n1.checkin();
obsMgr.removeEventListener(listener);
Event[] events = listener.getEvents(1000);
Set paths = new HashSet();
for (int i = 0; i < events.length; i++) {
paths.add(events[i].getPath());
}
assertTrue("missing 'node removed': " + v.getPath(), paths.contains(v.getPath()));
String frozenPath = v.getPath() + "/" + jcrFrozenNode;
assertTrue("missing 'node removed': " + frozenPath, paths.contains(frozenPath));
} finally {
s.logout();
}
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class VersionEventsTest method testCheckin.
/**
* Test if checkin of a node creates two add node events: one for the
* version and one for the frozen node.
*/
public void testCheckin() throws RepositoryException {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_ADDED);
Version v = n1.checkin();
removeEventListener(listener);
Event[] events = listener.getEvents(1000);
Set paths = new HashSet();
for (int i = 0; i < events.length; i++) {
paths.add(events[i].getPath());
}
assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
String frozenPath = v.getPath() + "/" + jcrFrozenNode;
assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit-oak by apache.
the class ObservationTest method testEventRemovedNode.
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-4196">OAK-4196</a>
*/
@Test
public void testEventRemovedNode() throws Exception {
// withdraw the READ privilege on childNPath
deny(path, readPrivileges);
assertFalse(testSession.nodeExists(childNPath));
// 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 order to provoke events being generated
superuser.getItem(childNPath).remove();
superuser.save();
// since the testUser does not have read-permission on the removed
// childNPath, no corresponding event must be generated.
Event[] evts = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
for (Event evt : evts) {
if (evt.getType() == Event.NODE_REMOVED && evt.getPath().equals(childNPath)) {
fail("TestUser does not have READ permission on " + childNPath);
}
}
} finally {
obsMgr.removeEventListener(listener);
}
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class AbstractWriteTest method testEventGeneration.
public void testEventGeneration() throws RepositoryException, NotExecutableException {
/*
precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
Session testSession = getTestSession();
// withdraw the READ privilege
Privilege[] dnPrivs = privilegesFromName(Privilege.JCR_READ);
withdrawPrivileges(path, dnPrivs, getRestrictions(superuser, path));
// testUser registers a event listener for 'path
ObservationManager obsMgr = testSession.getWorkspace().getObservationManager();
EventResult listener = new EventResult(((JUnitTest) this).log);
try {
obsMgr.addEventListener(listener, Event.NODE_REMOVED, path, true, new String[0], new String[0], true);
// superuser removes the node with childNPath in order to provoke
// events being generated
superuser.getItem(childNPath).remove();
superuser.save();
obsMgr.removeEventListener(listener);
// since the testUser does not have read-permission on the removed
// node, no corresponding event must be generated.
Event[] evts = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
for (Event evt : evts) {
if (evt.getType() == Event.NODE_REMOVED && evt.getPath().equals(childNPath)) {
fail("TestUser does not have READ permission below " + path + " -> events below must not show up.");
}
}
} finally {
obsMgr.removeEventListener(listener);
}
}
Aggregations