jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r585552 - in /jackrabbit/trunk: jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/
Date Wed, 17 Oct 2007 16:16:06 GMT
Author: reschke
Date: Wed Oct 17 09:16:04 2007
New Revision: 585552

URL: http://svn.apache.org/viewvc?rev=585552&view=rev
Log:
JCR-1164: extend observation tests so that they can also check for optional events; update
test cases to pass in the optional events (may not be complete yet).

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ReorderTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AbstractObservationTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AddEventListenerTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeAddedTest.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/NodeRemovedTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeReorderTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/WorkspaceOperationTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ReorderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ReorderTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ReorderTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/ReorderTest.java
Wed Oct 17 09:16:04 2007
@@ -87,7 +87,7 @@
         // 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]"});
-        checkNodeRemoved(removed, new String[]{nodeName1 + "[2]", nodeName3});
+        checkNodeAdded(added, new String[]{nodeName1 + "[4]"}, null);
+        checkNodeRemoved(removed, new String[]{nodeName1 + "[2]", nodeName3}, null);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AbstractObservationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AbstractObservationTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AbstractObservationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AbstractObservationTest.java
Wed Oct 17 09:16:04 2007
@@ -25,7 +25,9 @@
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.ObservationManager;
 import javax.jcr.observation.EventListenerIterator;
+
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 import java.util.List;
 import java.util.ArrayList;
@@ -125,14 +127,16 @@
      * relative to {@link #testRoot}.
      *
      * @param events   the <code>Event</code>s.
-     * @param relPaths paths to child nodes added relative to {@link
-     *                 #testRoot}.
+     * @param requiredRelPaths paths to child nodes added relative to {@link
+     *                 #testRoot} (required events).
+     * @param optionalRelPaths paths to child nodes added relative to {@link
+     *                 #testRoot} (optional events).
      * @throws RepositoryException if an error occurs while retrieving the nodes
      *                             from event instances.
      */
-    protected void checkNodeAdded(Event[] events, String[] relPaths)
+    protected void checkNodeAdded(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths)
             throws RepositoryException {
-        checkNodes(events, relPaths, Event.NODE_ADDED);
+        checkNodes(events, requiredRelPaths, optionalRelPaths, Event.NODE_ADDED);
     }
 
     /**
@@ -140,14 +144,16 @@
      * relative to {@link #testRoot}.
      *
      * @param events   the <code>Event</code>s.
-     * @param relPaths paths to child nodes added relative to {@link
-     *                 #testRoot}.
+     * @param requiredRelPaths paths to child nodes added relative to {@link
+     *                 #testRoot} (required events).
+     * @param optionalRelPaths paths to child nodes added relative to {@link
+     *                 #testRoot} (optional events).
      * @throws RepositoryException if an error occurs while retrieving the nodes
      *                             from event instances.
      */
-    protected void checkNodeRemoved(Event[] events, String[] relPaths)
+    protected void checkNodeRemoved(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths)
             throws RepositoryException {
-        checkNodes(events, relPaths, Event.NODE_REMOVED);
+        checkNodes(events, requiredRelPaths, optionalRelPaths, Event.NODE_REMOVED);
     }
 
     /**
@@ -162,7 +168,7 @@
      */
     protected void checkPropertyAdded(Event[] events, String[] relPaths)
             throws RepositoryException {
-        checkNodes(events, relPaths, Event.PROPERTY_ADDED);
+        checkNodes(events, relPaths, null, Event.PROPERTY_ADDED);
     }
 
     /**
@@ -177,7 +183,7 @@
      */
     protected void checkPropertyChanged(Event[] events, String[] relPaths)
             throws RepositoryException {
-        checkNodes(events, relPaths, Event.PROPERTY_CHANGED);
+        checkNodes(events, relPaths, null, Event.PROPERTY_CHANGED);
     }
 
     /**
@@ -192,7 +198,7 @@
      */
     protected void checkPropertyRemoved(Event[] events, String[] relPaths)
             throws RepositoryException {
-        checkNodes(events, relPaths, Event.PROPERTY_REMOVED);
+        checkNodes(events, relPaths, null, Event.PROPERTY_REMOVED);
     }
 
     /**
@@ -200,24 +206,38 @@
      * relative to {@link #testRoot}.
      *
      * @param events    the <code>Event</code>s.
-     * @param relPaths  paths to item events relative to {@link #testRoot}.
+     * @param requiredRelPaths  paths to required item events relative to {@link #testRoot}.
+     * @param optionalRelPaths  paths to optional item events relative to {@link #testRoot}.
      * @param eventType the type of event to check.
      * @throws RepositoryException if an error occurs while retrieving the nodes
      *                             from event instances.
      */
-    private void checkNodes(Event[] events, String[] relPaths, long eventType)
+    private void checkNodes(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths,
long eventType)
             throws RepositoryException {
-        assertEquals("Number of events wrong", relPaths.length, events.length);
         Set paths = new HashSet();
         for (int i = 0; i < events.length; i++) {
             assertEquals("Wrong event type", eventType, events[i].getType());
             String path = events[i].getPath();
             paths.add(path);
         }
-        for (int i = 0; i < relPaths.length; i++) {
-            String expected = testRoot + "/" + relPaths[i];
+        // check all required paths are there
+        for (int i = 0; i < requiredRelPaths.length; i++) {
+            String expected = testRoot + "/" + requiredRelPaths[i];
             assertTrue("Path " + expected + " not found in events.",
                     paths.contains(expected));
+            paths.remove(expected);
+        }
+        // check what remains in the set is indeed optional
+        Set optional = new HashSet();
+        if (optionalRelPaths != null) {
+            for (int i = 0; i < optionalRelPaths.length; i++) {
+                optional.add(testRoot + "/" + optionalRelPaths[i]);
+            }
+        }
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            String path = (String)it.next();
+            assertTrue("Path " + path + " not expected in events.",
+                    optional.contains(path));
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AddEventListenerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AddEventListenerTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AddEventListenerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/AddEventListenerTest.java
Wed Oct 17 09:16:04 2007
@@ -55,7 +55,7 @@
         testRootNode.save();
         Event[] events = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
         obsMgr.removeEventListener(listener);
-        checkNodeAdded(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2});
+        checkNodeAdded(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2}, null);
     }
 
     /**
@@ -70,7 +70,7 @@
         testRootNode.save();
         Event[] events = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
         obsMgr.removeEventListener(listener);
-        checkNodeAdded(events, new String[]{nodeName1});
+        checkNodeAdded(events, new String[]{nodeName1}, null);
     }
 
     /**
@@ -170,7 +170,7 @@
         }
         Event[] events = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
         obsMgr.removeEventListener(listener);
-        checkNodeAdded(events, new String[]{nodeName1 + "/" + nodeName3});
+        checkNodeAdded(events, new String[]{nodeName1 + "/" + nodeName3}, null);
     }
 
     //-------------------------< internal >-------------------------------------

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeAddedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeAddedTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeAddedTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeAddedTest.java
Wed Oct 17 09:16:04 2007
@@ -47,7 +47,7 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeAdded(events, new String[]{nodeName1});
+        checkNodeAdded(events, new String[]{nodeName1}, null);
     }
 
     /**
@@ -62,7 +62,7 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeAdded(events, new String[]{nodeName1, nodeName2});
+        checkNodeAdded(events, new String[]{nodeName1, nodeName2}, null);
     }
 
     /**
@@ -77,7 +77,7 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeAdded(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2});
+        checkNodeAdded(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2}, null);
     }
 
     /**
@@ -92,6 +92,6 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeAdded(events, new String[]{nodeName1});
+        checkNodeAdded(events, new String[]{nodeName1}, null);
     }
 }

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=585552&r1=585551&r2=585552&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
Wed Oct 17 09:16:04 2007
@@ -68,8 +68,8 @@
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
-        checkNodeAdded(added, new String[]{nodeName3});
-        checkNodeRemoved(removed, new String[]{nodeName1});
+        checkNodeAdded(added, new String[]{nodeName3}, new String[]{nodeName3 + "/" + nodeName2});
+        checkNodeRemoved(removed, new String[]{nodeName1}, new String[]{nodeName1 + "/" +
nodeName2});
     }
 
     /**
@@ -102,8 +102,8 @@
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
-        checkNodeAdded(added, new String[]{nodeName2});
-        checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2});
+        checkNodeAdded(added, new String[]{nodeName2}, null);
+        checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2}, null);
     }
 
     /**
@@ -140,7 +140,7 @@
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
-        checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName2});
-        checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2, nodeName1});
+        checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName2}, null);
+        checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2, nodeName1}, null);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeRemovedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeRemovedTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeRemovedTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/NodeRemovedTest.java
Wed Oct 17 09:16:04 2007
@@ -49,7 +49,7 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeRemoved(events, new String[]{nodeName1});
+        checkNodeRemoved(events, new String[]{nodeName1}, null);
     }
 
     /**
@@ -66,7 +66,7 @@
         testRootNode.save();
         Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(result);
-        checkNodeRemoved(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2});
+        checkNodeRemoved(events, new String[]{nodeName1, nodeName1 + "/" + nodeName2}, null);
     }
 
 }

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=585552&r1=585551&r2=585552&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
Wed Oct 17 09:16:04 2007
@@ -97,11 +97,11 @@
             }
         }
         if (reorderEnd) {
-            checkNodeAdded(added, new String[]{nodeName2});
-            checkNodeRemoved(removed, new String[]{nodeName2});
+            checkNodeAdded(added, new String[]{nodeName2}, null);
+            checkNodeRemoved(removed, new String[]{nodeName2}, null);
         } else {
-            checkNodeAdded(added, new String[]{nodeName3});
-            checkNodeRemoved(removed, new String[]{nodeName3});
+            checkNodeAdded(added, new String[]{nodeName3}, null);
+            checkNodeRemoved(removed, new String[]{nodeName3}, null);
         }
     }
 
@@ -164,11 +164,11 @@
             }
         }
         if (reorderEnd) {
-            checkNodeAdded(added, new String[]{nodeName1 + "[3]"});
-            checkNodeRemoved(removed, new String[]{nodeName1 + "[2]"});
+            checkNodeAdded(added, new String[]{nodeName1 + "[3]"}, null);
+            checkNodeRemoved(removed, new String[]{nodeName1 + "[2]"}, null);
         } else {
-            checkNodeAdded(added, new String[]{nodeName1 + "[2]"});
-            checkNodeRemoved(removed, new String[]{nodeName1 + "[3]"});
+            checkNodeAdded(added, new String[]{nodeName1 + "[2]"}, null);
+            checkNodeRemoved(removed, new String[]{nodeName1 + "[3]"}, null);
         }
     }
 
@@ -238,11 +238,11 @@
             }
         }
         if (reorderEnd) {
-            checkNodeAdded(added, new String[]{nodeName1 + "[3]"});
-            checkNodeRemoved(removed, new String[]{nodeName1 + "[2]", nodeName3});
+            checkNodeAdded(added, new String[]{nodeName1 + "[3]"}, null);
+            checkNodeRemoved(removed, new String[]{nodeName1 + "[2]", nodeName3}, null);
         } else {
-            checkNodeAdded(added, new String[]{nodeName1 + "[2]"});
-            checkNodeRemoved(removed, new String[]{nodeName1 + "[3]", nodeName3});
+            checkNodeAdded(added, new String[]{nodeName1 + "[2]"}, null);
+            checkNodeRemoved(removed, new String[]{nodeName1 + "[3]", nodeName3}, null);
         }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/WorkspaceOperationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/WorkspaceOperationTest.java?rev=585552&r1=585551&r2=585552&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/WorkspaceOperationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/observation/WorkspaceOperationTest.java
Wed Oct 17 09:16:04 2007
@@ -51,7 +51,7 @@
         superuser.getWorkspace().copy(testRoot + "/" + nodeName1, testRoot + "/" + nodeName3);
         Event[] events = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(listener);
-        checkNodeAdded(events, new String[]{nodeName3, nodeName3 + "/" + nodeName2});
+        checkNodeAdded(events, new String[]{nodeName3, nodeName3 + "/" + nodeName2}, null);
     }
 
     /**
@@ -72,8 +72,8 @@
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
-        checkNodeAdded(added, new String[]{nodeName3});
-        checkNodeRemoved(removed, new String[]{nodeName1});
+        checkNodeAdded(added, new String[]{nodeName3}, new String[]{nodeName3 + "/" + nodeName2});
+        checkNodeRemoved(removed, new String[]{nodeName1}, new String[]{nodeName1 + "/" +
nodeName2});
     }
 
     /**
@@ -95,8 +95,8 @@
         Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
         removeEventListener(addNodeListener);
         removeEventListener(removeNodeListener);
-        checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName4});
-        checkNodeRemoved(removed, new String[]{nodeName1});
+        checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName4}, new String[]{nodeName3
+ "/" + nodeName4 + "/" + nodeName2});
+        checkNodeRemoved(removed, new String[]{nodeName1}, new String[]{nodeName1 + "/" +
nodeName2});
     }
 
 }



Mime
View raw message