use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class VersionEventsTest method testRemoveVersion.
/**
* Test if removing a version triggers two node removed events: one for the
* version and one for the frozen node.
*/
public void testRemoveVersion() throws RepositoryException {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
Version v = n1.checkin();
String versionPath = v.getPath();
n1.remove();
testRootNode.save();
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_REMOVED);
v.getContainingHistory().removeVersion(v.getName());
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' event: " + versionPath, paths.contains(versionPath));
String frozenPath = versionPath + "/" + jcrFrozenNode;
assertTrue("missing 'node removed' event: " + frozenPath, paths.contains(frozenPath));
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class VersionEventsTest method testXARemoveVersion.
/**
* Test if removing a version in an XA transaction triggers two node removed
* events: one for the version and one for the frozen node.
*/
public void testXARemoveVersion() throws Exception {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
Version v = n1.checkin();
String versionPath = v.getPath();
n1.remove();
testRootNode.save();
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_REMOVED);
// use a transaction
UserTransaction utx = new UserTransactionImpl(superuser);
// start transaction
utx.begin();
v.getContainingHistory().removeVersion(v.getName());
// commit transaction
utx.commit();
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' event: " + versionPath, paths.contains(versionPath));
String frozenPath = versionPath + "/" + jcrFrozenNode;
assertTrue("missing 'node removed' event: " + frozenPath, paths.contains(frozenPath));
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class WarningOnSaveWithNotificationThreadTest method testWarning.
public void testWarning() throws Exception {
final List<Exception> exceptions = new ArrayList<Exception>();
EventResult result = new EventResult(log) {
@Override
public void onEvent(EventIterator events) {
try {
Session s = getHelper().getSuperuserSession();
try {
s.getNode(testRoot).addNode("bar");
s.save();
} finally {
s.logout();
}
} catch (RepositoryException e) {
exceptions.add(e);
}
super.onEvent(events);
}
};
addEventListener(result);
Tail tail = Tail.start(new File("target", "jcr.log"), MESSAGE);
try {
testRootNode.addNode("foo");
superuser.save();
removeEventListener(result);
result.getEvents(5000);
assertTrue("Warn message expected in log file.", tail.getLines().iterator().hasNext());
} finally {
tail.close();
}
if (!exceptions.isEmpty()) {
fail(exceptions.get(0).toString());
}
}
use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.
the class MixinTest method testMultipleMixin.
/**
* Tests event filtering with multiple mixin type name.
*/
public void testMultipleMixin() throws RepositoryException {
testRootNode.addNode(nodeName1, testNodeType).addMixin(mixReferenceable);
testRootNode.addNode(nodeName2, testNodeType).addMixin(mixLockable);
testRootNode.addNode(nodeName3, testNodeType).addMixin(mixReferenceable);
testRootNode.save();
EventResult propertyAddedListener = new EventResult(log);
addEventListener(propertyAddedListener, new String[] { mixReferenceable, mixLockable }, Event.PROPERTY_ADDED);
try {
testRootNode.getNode(nodeName1).setProperty(propertyName1, "test");
testRootNode.getNode(nodeName2).setProperty(propertyName1, "test");
testRootNode.getNode(nodeName3).setProperty(propertyName1, "test");
testRootNode.save();
Event[] added = propertyAddedListener.getEvents(DEFAULT_WAIT_TIMEOUT);
checkPropertyAdded(added, new String[] { nodeName1 + "/" + propertyName1, nodeName2 + "/" + propertyName1, nodeName3 + "/" + propertyName1 });
} finally {
removeEventListener(propertyAddedListener);
}
}
use of org.apache.jackrabbit.test.api.observation.EventResult 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);
}
Aggregations