Search in sources :

Example 11 with EventResult

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));
}
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 12 with EventResult

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));
}
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 13 with EventResult

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());
    }
}
Also used : EventResult(org.apache.jackrabbit.test.api.observation.EventResult) Tail(org.apache.jackrabbit.core.Tail) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) EventIterator(javax.jcr.observation.EventIterator) File(java.io.File) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 14 with EventResult

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

Example 15 with EventResult

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