use of javax.jcr.observation.EventIterator in project jackrabbit by apache.
the class EventIteratorTest method testGetPosition.
/**
* Tests if getPosition() returns the correct values.
*/
public void testGetPosition() throws RepositoryException {
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_ADDED);
testRootNode.addNode(nodeName1, testNodeType);
testRootNode.addNode(nodeName2, testNodeType);
testRootNode.addNode(nodeName3, testNodeType);
testRootNode.getSession().save();
EventIterator events = listener.getEventIterator(DEFAULT_WAIT_TIMEOUT);
removeEventListener(listener);
assertNotNull("No events delivered within " + DEFAULT_WAIT_TIMEOUT + "ms.", events);
assertEquals("Initial call to getPosition() must return 0.", 0, events.getPosition());
events.nextEvent();
assertEquals("Wrong value for getPosition()", 1, events.getPosition());
events.nextEvent();
assertEquals("Wrong value for getPosition()", 2, events.getPosition());
events.nextEvent();
assertEquals("Wrong value for getPosition()", 3, events.getPosition());
}
Aggregations