Search in sources :

Example 1 with EventResult

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

the class VersionEventsTest method testXACheckin.

/**
     * Test if checkin of a node in an XA transaction creates two add node
     * events: one for the version and one for the frozen node.
     */
public void testXACheckin() throws Exception {
    // create versionable node
    Node n1 = testRootNode.addNode(nodeName1);
    n1.addMixin(mixVersionable);
    testRootNode.save();
    EventResult listener = new EventResult(log);
    addEventListener(listener, Event.NODE_ADDED);
    // use a transaction
    UserTransaction utx = new UserTransactionImpl(superuser);
    // start transaction
    utx.begin();
    Version v = n1.checkin();
    // 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 added' event: " + v.getPath(), paths.contains(v.getPath()));
    String frozenPath = v.getPath() + "/" + jcrFrozenNode;
    assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
}
Also used : UserTransaction(javax.transaction.UserTransaction) 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) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Event(javax.jcr.observation.Event) HashSet(java.util.HashSet)

Example 2 with EventResult

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

the class JackrabbitObservationManagerTest method testDisjunctPaths.

public void testDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
    JackrabbitObservationManager oManager = (JackrabbitObservationManager) obsMgr;
    EventResult listener = new EventResult(log);
    JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths('/' + testPath + "/a", '/' + testPath + "/x").setEventTypes(NODE_ADDED);
    oManager.addEventListener(listener, filter);
    try {
        Node b = testRootNode.addNode("a").addNode("b");
        b.addNode("c");
        Node y = testRootNode.addNode("x").addNode("y");
        y.addNode("z");
        testRootNode.getSession().save();
        Event[] added = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
        checkNodeAdded(added, new String[] { "a/b", "x/y" }, null);
    } finally {
        oManager.removeEventListener(listener);
    }
}
Also used : JackrabbitObservationManager(org.apache.jackrabbit.api.observation.JackrabbitObservationManager) EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter)

Example 3 with EventResult

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

the class MixinTest method testSingleMixin.

/**
     * Tests event filtering with a single mixin type name.
     */
public void testSingleMixin() throws RepositoryException {
    testRootNode.addNode(nodeName1, testNodeType).addMixin(mixReferenceable);
    testRootNode.addNode(nodeName2, testNodeType);
    testRootNode.addNode(nodeName3, testNodeType).addMixin(mixReferenceable);
    testRootNode.save();
    EventResult propertyAddedListener = new EventResult(log);
    addEventListener(propertyAddedListener, new String[] { mixReferenceable }, 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, nodeName3 + "/" + propertyName1 });
    } finally {
        removeEventListener(propertyAddedListener);
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Event(javax.jcr.observation.Event)

Example 4 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 5 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)

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