jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r771698 - in /jackrabbit/trunk: jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/
Date Tue, 05 May 2009 12:38:46 GMT
Author: reschke
Date: Tue May  5 12:38:32 2009
New Revision: 771698

URL: http://svn.apache.org/viewvc?rev=771698&view=rev
Log:
JCR-2085: move integrate new tests from NodeMovedtest and NodeReorderTest into jackrabbit-jcr-tests

Removed:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/NodeMovedTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/NodeReorderTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/TestAll.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/TestAll.java?rev=771698&r1=771697&r2=771698&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/observation/TestAll.java
Tue May  5 12:38:32 2009
@@ -30,8 +30,6 @@
         TestSuite suite = new TestSuite("javax.jcr.observation tests");
 
         suite.addTestSuite(EventJournalTest.class);
-        suite.addTestSuite(NodeMovedTest.class);
-        suite.addTestSuite(NodeReorderTest.class);
 
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java?rev=771698&r1=771697&r2=771698&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
Tue May  5 12:38:32 2009
@@ -16,10 +16,15 @@
  */
 package org.apache.jackrabbit.test.api.observation;
 
+import java.util.Map;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
 import javax.jcr.observation.Event;
 
+import org.apache.jackrabbit.test.api.observation.AbstractObservationTest;
+import org.apache.jackrabbit.test.api.observation.EventResult;
+
 /**
  * Tests if {@link javax.jcr.Session#move} operations trigger the appropriate
  * observation events.
@@ -39,6 +44,16 @@
 public class NodeMovedTest extends AbstractObservationTest {
 
     /**
+     * The key <code>srcAbsPath</code> in the info map.
+     */
+    private static final String SRC_ABS_PATH = "srcAbsPath";
+
+    /**
+     * The key <code>destAbsPath</code> in the info map.
+     */
+    private static final String DEST_ABS_PATH = "destAbsPath";
+
+    /**
      * Tests if node removed and node added event is triggered when a tree
      * is moved.
      */
@@ -60,16 +75,21 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         superuser.move(n1.getPath(), testRoot + "/" + nodeName3);
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         checkNodeAdded(added, new String[]{nodeName3}, new String[]{nodeName3 + "/" + nodeName2});
         checkNodeRemoved(removed, new String[]{nodeName1}, new String[]{nodeName1 + "/" +
nodeName2});
+        checkNodeMoved(moved, nodeName1, nodeName3);
     }
 
     /**
@@ -94,16 +114,21 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         superuser.move(n2.getPath(), testRoot + "/" + nodeName2);
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         checkNodeAdded(added, new String[]{nodeName2}, null);
         checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2}, null);
+        checkNodeMoved(moved, nodeName1 + "/" + nodeName2, nodeName2);
     }
 
     /**
@@ -129,8 +154,10 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         // move n2
         superuser.move(n2.getPath(), n3.getPath() + "/" + nodeName2);
         // remove n1
@@ -138,9 +165,47 @@
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName2}, null);
         checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2, nodeName1}, null);
+        checkNodeMoved(moved, nodeName1 + "/" + nodeName2, nodeName3 + "/" + nodeName2);
+    }
+
+    /**
+     * TODO: move to base class once JSR 283 is final
+     * Checks <code>Events</code> for paths. All <code>relPaths</code>
are
+     * relative to {@link #testRoot}.
+     *
+     * @param events the <code>Event</code>s.
+     * @param from   the source path where the node was moved from.
+     * @param to     the destination path where the node was moved to.
+     * @throws RepositoryException if an error occurs while retrieving the nodes
+     *                             from event instances.
+     */
+    protected void checkNodeMoved(Event[] events, String from, String to)
+            throws RepositoryException {
+        checkNodes(events, new String[]{to}, null, Event.NODE_MOVED);
+        assertEquals("Wrong number of events", 1, events.length);
+        Map info = events[0].getInfo();
+        checkInfoEntry(info, SRC_ABS_PATH, testRoot + "/" + from);
+        checkInfoEntry(info, DEST_ABS_PATH, testRoot + "/" + to);
+    }
+
+    /**
+     * TODO: move to base class once JSR 283 is final
+     * Checks if the info map contains the given <code>key</code> with the
+     * <code>expected</code> value.
+     *
+     * @param info the event info map.
+     * @param key the name of the key.
+     * @param expected the expected value.
+     */
+    protected void checkInfoEntry(Map info, String key, String expected) {
+        String value = (String) info.get(key);
+        assertNotNull("Missing event info key: " + key, value);
+        assertEquals("Wrong event info value for: " + key, expected, value);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java?rev=771698&r1=771697&r2=771698&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java
Tue May  5 12:38:32 2009
@@ -16,7 +16,11 @@
  */
 package org.apache.jackrabbit.test.api.observation;
 
+import java.util.Map;
+
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.observation.AbstractObservationTest;
+import org.apache.jackrabbit.test.api.observation.EventResult;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Node;
@@ -43,6 +47,16 @@
 public class NodeReorderTest extends AbstractObservationTest {
 
     /**
+     * The key <code>srcChildRelPath</code> in the info map.
+     */
+    private static final String SRC_CHILD_REL_PATH = "srcChildRelPath";
+
+    /**
+     * The key <code>destChildRelPath</code> in the info map.
+     */
+    private static final String DEST_CHILD_REL_PATH = "destChildRelPath";
+
+    /**
      * Tests if reordering a child node triggers a {@link Event#NODE_REMOVED}
      * and a {@link Event#NODE_ADDED} event.
      */
@@ -71,14 +85,18 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         testRootNode.orderBefore(nodeName3, nodeName2);
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         // either
         // 1) nodename2 has been reordered to the end
         // or:
@@ -99,9 +117,11 @@
         if (reorderEnd) {
             checkNodeAdded(added, new String[]{nodeName2}, null);
             checkNodeRemoved(removed, new String[]{nodeName2}, null);
+            checkNodeReordered(moved, nodeName2, nodeName2, null);
         } else {
             checkNodeAdded(added, new String[]{nodeName3}, null);
             checkNodeRemoved(removed, new String[]{nodeName3}, null);
+            checkNodeReordered(moved, nodeName3, nodeName3, nodeName2);
         }
     }
 
@@ -137,15 +157,19 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         testRootNode.orderBefore(nodeName1 + "[3]", nodeName1 + "[2]");
         //testRootNode.orderBefore(nodeName1 + "[2]", null);
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         // either
         // 1) nodename1[2] has been reordered to the end
         // or:
@@ -166,9 +190,11 @@
         if (reorderEnd) {
             checkNodeAdded(added, new String[]{nodeName1 + "[3]"}, null);
             checkNodeRemoved(removed, new String[]{nodeName1 + "[2]"}, null);
+            checkNodeReordered(moved, nodeName1 + "[2]", nodeName1 + "[3]", null);
         } else {
             checkNodeAdded(added, new String[]{nodeName1 + "[2]"}, null);
             checkNodeRemoved(removed, new String[]{nodeName1 + "[3]"}, null);
+            checkNodeReordered(moved, nodeName1 + "[3]", nodeName1 + "[2]", nodeName1 + "[2]");
         }
     }
 
@@ -210,15 +236,19 @@
         testRootNode.save();
         EventResult addNodeListener = new EventResult(log);
         EventResult removeNodeListener = new EventResult(log);
+        EventResult moveNodeListener = new EventResult(log);
         addEventListener(addNodeListener, Event.NODE_ADDED);
         addEventListener(removeNodeListener, Event.NODE_REMOVED);
+        addEventListener(moveNodeListener, Event.NODE_MOVED);
         testRootNode.orderBefore(nodeName1 + "[2]", null);
         testRootNode.getNode(nodeName3).remove();
         testRootNode.save();
         Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] moved = moveNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
+        removeEventListener(moveNodeListener);
         // either
         // 1) nodename1[2] has been reordered to the end
         // or:
@@ -240,9 +270,46 @@
         if (reorderEnd) {
             checkNodeAdded(added, new String[]{nodeName1 + "[3]"}, null);
             checkNodeRemoved(removed, new String[]{nodeName1 + "[2]", nodeName3}, null);
+            checkNodeReordered(moved, nodeName1 + "[2]", nodeName1 + "[3]", null);
         } else {
             checkNodeAdded(added, new String[]{nodeName1 + "[2]"}, null);
             checkNodeRemoved(removed, new String[]{nodeName1 + "[3]", nodeName3}, null);
+            checkNodeReordered(moved, nodeName1 + "[3]", nodeName1 + "[2]", nodeName1 + "[2]");
         }
     }
+
+    /**
+     * Checks <code>Events</code> for paths. All <code>relPaths</code>
are
+     * relative to {@link #testRoot}.
+     *
+     * @param events the <code>Event</code>s.
+     * @param src    the source child path where the node was reordered from.
+     * @param dest   the destination child path where the node was reordered to.
+     * @param before the destination child path where the node was reordered before.
+     * @throws RepositoryException if an error occurs while retrieving the nodes
+     *                             from event instances.
+     */
+    protected void checkNodeReordered(Event[] events, String src,
+                                      String dest, String before)
+            throws RepositoryException {
+        checkNodes(events, new String[]{dest}, null, Event.NODE_MOVED);
+        assertEquals("Wrong number of events", 1, events.length);
+        Map info = events[0].getInfo();
+        checkInfoEntry(info, SRC_CHILD_REL_PATH, src);
+        checkInfoEntry(info, DEST_CHILD_REL_PATH, before);
+    }
+
+    /**
+     * Checks if the info map contains the given <code>key</code> with the
+     * <code>expected</code> value.
+     *
+     * @param info the event info map.
+     * @param key the name of the key.
+     * @param expected the expected value.
+     */
+    protected void checkInfoEntry(Map info, String key, String expected) {
+        assertTrue("Missing event info key: " + key, info.containsKey(key));
+        assertEquals("Wrong event info value for: " + key,
+                expected, (String) info.get(key));
+    }
 }



Mime
View raw message