use of javax.jcr.observation.Event in project jackrabbit by apache.
the class ReorderTest method testNodeReorderComplex.
/**
* Tests if reordering a child node triggers a {@link javax.jcr.observation.Event#NODE_REMOVED}
* and a {@link javax.jcr.observation.Event#NODE_ADDED} event with same name siblings. Furthermore
* a node is removed in the same save scope.
* <p>
* Because of the one reorder operation, three nodes change their index. And
* actually four nodes change their context position. The minimal events
* that may be triggered only includes one pair of remove/add node events
* (plus the additional event for the removed node).
*/
public void testNodeReorderComplex() throws RepositoryException, NotExecutableException {
if (!testRootNode.getDefinition().getDeclaringNodeType().hasOrderableChildNodes()) {
throw new NotExecutableException("Node at '" + testRoot + "' does not support orderable child nodes.");
}
/**
* Initial tree:
* + testroot
* + nodename1[1]
* + nodename1[2]
* + nodename2
* + nodename1[3]
* + nodename1[4]
* + nodename3
*
* After reorder:
* + testroot
* + nodename1[1]
* + nodename2
* + nodename1[2] (was 3)
* + nodename1[3] (was 4)
* + nodename1[4] (was 2)
*/
Node n = testRootNode.addNode(nodeName1, testNodeType);
if (!n.getDefinition().allowsSameNameSiblings()) {
throw new NotExecutableException("Node at " + testRoot + " does not allow same name siblings with name " + nodeName1);
}
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName2, testNodeType);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName3, testNodeType);
testRootNode.save();
EventResult addNodeListener = new EventResult(log);
EventResult removeNodeListener = new EventResult(log);
addEventListener(addNodeListener, Event.NODE_ADDED);
addEventListener(removeNodeListener, Event.NODE_REMOVED);
testRootNode.orderBefore(nodeName1 + "[2]", null);
testRootNode.getNode(nodeName3).remove();
testRootNode.save();
removeEventListener(addNodeListener);
removeEventListener(removeNodeListener);
Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
// not deterministic, there exist various re-order seqences. the minimal
// is:
// nodename1[2] has been reordered to the end + nodeName3 has been removed
checkNodeAdded(added, new String[] { nodeName1 + "[4]" }, null);
checkNodeRemoved(removed, new String[] { nodeName1 + "[2]", nodeName3 }, null);
}
use of javax.jcr.observation.Event 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 javax.jcr.observation.Event 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 javax.jcr.observation.Event 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 javax.jcr.observation.Event in project jackrabbit by apache.
the class ServerAdapterFactory method getRemoteEvent.
/**
* Creates a {@link ServerEventCollection ServerEventCollection} instances.
* {@inheritDoc}
*/
public RemoteEventCollection getRemoteEvent(long listenerId, EventIterator events) throws RemoteException {
RemoteEventCollection.RemoteEvent[] remoteEvents;
if (events != null) {
List<ServerEventCollection.ServerEvent> eventList = new ArrayList<ServerEventCollection.ServerEvent>();
while (events.hasNext()) {
Event event = events.nextEvent();
eventList.add(new ServerEventCollection.ServerEvent(event, this));
}
remoteEvents = eventList.toArray(new RemoteEventCollection.RemoteEvent[eventList.size()]);
} else {
// for
remoteEvents = new RemoteEventCollection.RemoteEvent[0];
// safety
}
return new ServerEventCollection(listenerId, remoteEvents, this);
}
Aggregations