Search in sources :

Example 16 with EventResult

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);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event)

Example 17 with EventResult

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();
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) HashSet(java.util.HashSet) Set(java.util.Set) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session) HashSet(java.util.HashSet)

Example 18 with EventResult

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));
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) HashSet(java.util.HashSet) Set(java.util.Set) Version(javax.jcr.version.Version) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) HashSet(java.util.HashSet)

Example 19 with EventResult

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);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Test(org.junit.Test)

Example 20 with EventResult

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);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Event(javax.jcr.observation.Event) ObservationManager(javax.jcr.observation.ObservationManager) Privilege(javax.jcr.security.Privilege) 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