Search in sources :

Example 6 with EventResult

use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.

the class MixinTest method testDerivedMixin.

/**
     * Checks if an event listener registered for a mixin type T also gets
     * notifications for an event on a node with a mixin type which is derived
     * from T.
     */
public void testDerivedMixin() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, testNodeType);
    node1.addMixin(mixVersionable);
    testRootNode.save();
    EventResult propertyAddedListener = new EventResult(log);
    // mix:versionable is derived from mix:referenceable
    addEventListener(propertyAddedListener, new String[] { mixReferenceable }, Event.PROPERTY_ADDED);
    try {
        node1.setProperty(propertyName1, "test");
        testRootNode.save();
        Event[] added = propertyAddedListener.getEvents(DEFAULT_WAIT_TIMEOUT);
        checkPropertyAdded(added, new String[] { nodeName1 + "/" + propertyName1 });
    } finally {
        removeEventListener(propertyAddedListener);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

Example 7 with EventResult

use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.

the class MixinTest method testMultipleMixinOnNode.

/**
     * Tests event filtering on nodes with multiple mixins applied.
     */
public void testMultipleMixinOnNode() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, testNodeType);
    node1.addMixin(mixReferenceable);
    node1.addMixin(mixLockable);
    Node node2 = testRootNode.addNode(nodeName2, testNodeType);
    Node node3 = testRootNode.addNode(nodeName3, testNodeType);
    node3.addMixin(mixLockable);
    node3.addMixin(mixReferenceable);
    testRootNode.save();
    EventResult propertyAddedListener = new EventResult(log);
    addEventListener(propertyAddedListener, new String[] { mixReferenceable }, Event.PROPERTY_ADDED);
    try {
        node1.setProperty(propertyName1, "test");
        node2.setProperty(propertyName1, "test");
        node3.setProperty(propertyName1, "test");
        testRootNode.save();
        Event[] added = propertyAddedListener.getEvents(DEFAULT_WAIT_TIMEOUT);
        checkPropertyAdded(added, new String[] { nodeName1 + "/" + propertyName1, nodeName3 + "/" + propertyName1 });
    } finally {
        removeEventListener(propertyAddedListener);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

Example 8 with EventResult

use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.

the class ShareableNodesTest method testRemoveShare.

public void testRemoveShare() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    Node s = n1.addNode(nodeName3);
    s.addMixin(mixShareable);
    testRootNode.save();
    Workspace wsp = superuser.getWorkspace();
    wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
    EventResult result = new EventResult(log);
    addEventListener(result);
    removeFromSharedSet(n2.getNode(nodeName3));
    testRootNode.save();
    checkNodeRemoved(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 9 with EventResult

use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.

the class ShareableNodesTest method testAddShare.

public void testAddShare() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    Node n2 = testRootNode.addNode(nodeName2);
    Node s = n1.addNode(nodeName3);
    s.addMixin(mixShareable);
    testRootNode.save();
    EventResult result = new EventResult(log);
    addEventListener(result);
    Workspace wsp = superuser.getWorkspace();
    wsp.clone(wsp.getName(), s.getPath(), n2.getPath() + "/" + s.getName(), false);
    checkNodeAdded(result.getEvents(DEFAULT_WAIT_TIMEOUT), new String[] { nodeName2 + "/" + nodeName3 }, new String[0]);
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Workspace(javax.jcr.Workspace)

Example 10 with EventResult

use of org.apache.jackrabbit.test.api.observation.EventResult in project jackrabbit by apache.

the class JackrabbitNodeTest method testRenameEventHandling.

public void testRenameEventHandling() throws RepositoryException {
    Session s = getHelper().getSuperuserSession();
    ObservationManager mgr = s.getWorkspace().getObservationManager();
    EventResult result = new EventResult(log);
    try {
        mgr.addEventListener(result, Event.PERSIST | Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_REMOVED, testRootNode.getPath(), true, null, null, false);
        NodeIterator it = testRootNode.getNodes();
        Node n = it.nextNode();
        String name = n.getName();
        JackrabbitNode node = (JackrabbitNode) n;
        node.rename(name.toUpperCase());
        superuser.save();
        boolean foundMove = false;
        for (Event event : result.getEvents(5000)) {
            if (Event.NODE_MOVED == event.getType()) {
                foundMove = true;
                break;
            }
        }
        if (!foundMove) {
            fail("Expected NODE_MOVED event upon renaming a node.");
        }
    } finally {
        mgr.removeEventListener(result);
        s.logout();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session)

Aggregations

EventResult (org.apache.jackrabbit.test.api.observation.EventResult)20 Event (javax.jcr.observation.Event)17 Node (javax.jcr.Node)13 ObservationManager (javax.jcr.observation.ObservationManager)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 Version (javax.jcr.version.Version)5 Session (javax.jcr.Session)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Workspace (javax.jcr.Workspace)2 UserTransaction (javax.transaction.UserTransaction)2 UserTransactionImpl (org.apache.jackrabbit.core.UserTransactionImpl)2 File (java.io.File)1 NodeIterator (javax.jcr.NodeIterator)1 RepositoryException (javax.jcr.RepositoryException)1 EventIterator (javax.jcr.observation.EventIterator)1 Privilege (javax.jcr.security.Privilege)1 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)1 JackrabbitObservationManager (org.apache.jackrabbit.api.observation.JackrabbitObservationManager)1