jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r159487 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/observation/EventStateCollection.java test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
Date Wed, 30 Mar 2005 15:40:54 GMT
Author: mreutegg
Date: Wed Mar 30 07:40:52 2005
New Revision: 159487

URL: http://svn.apache.org/viewcvs?view=rev&rev=159487
Log:
JCR-69: removing source parent node after session move throws on save
- fixed bug in observation and added test case

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?view=diff&r1=159486&r2=159487
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Wed Mar 30 07:40:52 2005
@@ -123,7 +123,15 @@
                     // node moved
                     // generate node removed & node added event
                     String oldParentUUID = (String) n.getRemovedParentUUIDs().get(0);
-                    NodeState oldParent = (NodeState) changes.get(new NodeId(oldParentUUID));
+                    NodeState oldParent;
+                    try {
+                        oldParent = (NodeState) changes.get(new NodeId(oldParentUUID));
+                    } catch (NoSuchItemStateException e) {
+                        // old parent has been deleted, retrieve from
+                        // shared item state manager
+                        oldParent = (NodeState) provider.getItemState(new NodeId(oldParentUUID));
+                    }
+
                     NodeTypeImpl oldParentNodeType = getNodeType(oldParent, session);
                     Path newPath = getPath(n.getId(), hmgr);
                     Path[] allPaths = getAllPaths(n.getId(), hmgr);
@@ -179,7 +187,7 @@
                             NodeTypeImpl nodeType = getNodeType(parent, session);
                             Path newPath = getPath(state.getId(), hmgr);
                             Path parentPath = getParent(newPath);
-                            Path oldPath = null;
+                            Path oldPath;
                             try {
                                 if (moved.getIndex() == 0) {
                                     oldPath = Path.create(parentPath, moved.getName(), false);
@@ -262,7 +270,7 @@
                 // node created
                 NodeState n = (NodeState) state;
                 NodeId parentId = new NodeId(n.getParentUUID());
-                NodeState parent = null;
+                NodeState parent;
                 // unknown if parent node is also new
                 if (provider.hasItemState(parentId)) {
                     parent = (NodeState) provider.getItemState(parentId);

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java?view=diff&r1=159486&r2=159487
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/observation/NodeMovedTest.java
Wed Mar 30 07:40:52 2005
@@ -105,4 +105,42 @@
         checkNodeAdded(added, new String[]{nodeName2});
         checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2});
     }
+
+    /**
+     * Tests if a node moved triggers the correct events when the former parent
+     * node is removed at the same time.
+     */
+    public void testMoveWithRemove() throws RepositoryException {
+        /**
+         * Initial tree:
+         *  + testroot
+         *      + nodename1
+         *          + nodename2
+         *      + nodename3
+         *
+         * After move and remove:
+         *  + testroot
+         *      + nodename3
+         *          + nodename2
+         */
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        Node n2 = n1.addNode(nodeName2, testNodeType);
+        Node n3 = 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);
+        // move n2
+        superuser.move(n2.getPath(), n3.getPath() + "/" + nodeName2);
+        // remove n1
+        n1.remove();
+        testRootNode.save();
+        removeEventListener(addNodeListener);
+        removeEventListener(removeNodeListener);
+        Event[] added = addNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        Event[] removed = removeNodeListener.getEvents(DEFAULT_WAIT_TIMEOUT);
+        checkNodeAdded(added, new String[]{nodeName3 + "/" + nodeName2});
+        checkNodeRemoved(removed, new String[]{nodeName1 + "/" + nodeName2, nodeName1});
+    }
 }



Mime
View raw message