jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r155927 [2/2] - in incubator/jackrabbit/trunk: applications/test/ applications/test/repository/nodetypes/ src/java/org/apache/jackrabbit/core/util/ src/test/org/apache/jackrabbit/test/ src/test/org/apache/jackrabbit/test/api/
Date Wed, 02 Mar 2005 16:32:30 GMT
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java?view=auto&rev=155927
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java Wed
Mar  2 08:32:25 2005
@@ -0,0 +1,610 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.ItemExistsException;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Session;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Value;
+
+/**
+ * <code>SessionTest</code> contains all test cases for the
+ * <code>javax.jcr.Session</code> class that are level 2 (modifing repository
+ * content).
+ *
+ * @test
+ * @sources SessionTest.java
+ * @executeClass org.apache.jackrabbit.test.api.session.SessionTest
+ * @keywords level2
+ */
+public class SessionTest extends AbstractJCRTest {
+
+    /**
+     * Tries to move a node using <code>{@link javax.jcr.Session#move(String src, String
dest)}
+     * </code> to a location where a node already exists with
+     * same name.<br/> <br/> Prerequisites:
+     * <ul>
+     * <li><code>javax.jcr.tck.SessionTest.testMoveItemExistsException.nodetype2</code>
+     * must contain name of a nodetype that does not allow same name sibling
+     * child nodes.</li>
+     * <li><code>javax.jcr.tck.SessionTest.testMoveItemExistsException.nodetype3</code>
+     * must contain name of a valid nodetype that can be added as a child of
+     * <code>nodetype2</code></li>
+     * </ul> This should throw an <code>{@link javax.jcr.ItemExistsException}</code>.
+     */
+    public void testMoveItemExistsException() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to move
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // create a second node that will serve as new parent, must use a nodetype that does
not allow
+        // same name siblings
+        Node destParentNode = defaultRootNode.addNode(nodeName3, getProperty("nodetype2"));
+        // add a valid child
+        Node destNode = destParentNode.addNode(nodeName2, getProperty("nodetype3"));
+
+        // save the new nodes
+        superuser.save();
+
+        try {
+            // move the node
+            superuser.move(moveNode.getPath(), destNode.getPath());
+            fail("Moving a node using Session.move() to a location where a node with same
name already exists must throw ItemExistsException");
+        } catch (ItemExistsException e) {
+            // ok, works as expected
+        }
+    }
+
+    /**
+     * Calls <code>{@link javax.jcr.Session#move(String src, String dest)}</code>
+     * with invalid destination path.<br/> <br/> Should throw
+     * <code{@link javax.jcr.PathNotFoundException}</code>.
+     */
+    public void testMovePathNotFoundExceptionDestInvalid() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to move
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // move the node
+        try {
+            superuser.move(moveNode.getPath(), defaultRootNode.getPath() + "/" + nodeName2
+ "/" + nodeName1);
+            fail("Invalid destination path during Session.move() must throw PathNotFoundException");
+        } catch (PathNotFoundException e) {
+            // ok, works as expected
+        }
+    }
+
+    /**
+     * Calls <code>{@link javax.jcr.Session#move(String src, String dest)} with
+     * invalid source path.<br/> <br/> Should throw an <code>{@link
+     * javax.jcr.PathNotFoundException}.
+     */
+    public void testMovePathNotFoundExceptionSrcInvalid() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node that will serve as new parent
+        Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // move the node
+        try {
+            superuser.move(defaultRootNode.getPath() + "/" + nodeName1, destParentNode.getPath()
+ "/" + nodeName2);
+            fail("Invalid source path during Session.move() must throw PathNotFoundException");
+        } catch (PathNotFoundException e) {
+            // ok. works as expected
+        }
+    }
+
+    /**
+     * Calls <code>{@link javax.jcr.Session#move(String src, String dest)}
+     * </code> with a destination path that has an index postfixed.<br/>
+     * <br/> This should throw an <code>{@link javax.jcr.RepositoryException}</code>.
+     */
+    public void testMoveRepositoryException() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to be moved
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // create a node that will serve as new parent
+        Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // move the node
+        try {
+            superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2
+ "[1]");
+            fail("If destination path of Session.move() contains an index as postfix it must
throw RepositoryException");
+        } catch (RepositoryException e) {
+            // ok works as expected
+        }
+    }
+
+    /**
+     * Moves a node using <code>{@link javax.jcr.Session#move(String src, String dest)}
+     * </code>, afterwards it tries to only save the old parent node.<br>
+     * <br> This should throw <code>{@link javax.jcr.nodetype.ConstraintViolationException}</code>.
+     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
+     * must accept children of same nodetype</li> </ul>
+     */
+    public void testMoveConstraintViolationExceptionSrc() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to be moved
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // create a node that will serve as new parent
+        Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // move the node
+        superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
+
+        // save only old parent node
+        try {
+            srcParentNode.save();
+            fail("Saving only the source parent node after a Session.move() operation must
throw ContstraintViolationException");
+        } catch (ConstraintViolationException e) {
+            // ok both work as expected
+        }
+    }
+
+    /**
+     * Moves a node using <code>{@link javax.jcr.Session#move(String src, String dest)}
+     * </code>, afterwards it tries to only save the destination parent
+     * node.<br> <br> This should throw <code>{@link javax.jcr.nodetype.ConstraintViolationException}</code>.
+     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
+     * must accept children of same nodetype</li> </ul>
+     */
+    public void testMoveConstraintViolationExceptionDest() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to be moved
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // create a node that will serve as new parent
+        Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // move the node
+        superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
+
+        // save only moved node
+        try {
+            destParentNode.save();
+            fail("Saving only moved node after a Session.move() operation should throw ContstraintViolationException");
+        } catch (ConstraintViolationException e) {
+            // ok try to save the source
+        }
+    }
+
+    /**
+     * Checks if <code>{@link javax.jcr.Session#move(String src, String dest)}
+     * </code> works properly. To verify if node has been moved properly
+     * it uses a second session to retrieve the moved node.
+     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
+     * must accept children of same nodetype</li> </ul>
+     */
+    public void testMoveNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create parent node
+        Node srcParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create node to be moved
+        Node moveNode = srcParentNode.addNode(nodeName2, testNodeType);
+
+        // create a node that will serve as new parent
+        Node destParentNode = defaultRootNode.addNode(nodeName3, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        //move the nodes
+        superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
+
+        superuser.save();
+
+        // get moved tree root node with session 2
+        Session testSession = helper.getReadWriteSession();
+        testSession.getItem(destParentNode.getPath() + "/" + nodeName2);
+        // node found
+        testSession.logout();
+    }
+
+    /**
+     * Checks if a newly created node gets properly saved using <code{@link
+     * javax.jcr.Session#save()}</code>.<br/> <br/> It creates a new node,
saves
+     * it using <code>session.save()</code> then uses a different session to
+     * verify if the node has been properly saved.
+     */
+    public void testSaveNewNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node newNode = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // save changes
+        superuser.save();
+
+        // use a different session to verify if the node is there
+        helper.getReadOnlySession().getItem(newNode.getPath());
+
+        // throws PathNotFoundException if item was not saved
+    }
+
+    /**
+     * Checks if a modified node gets properly saved using <code{@link
+     * javax.jcr.Session#save()}</code>.<br/> <br/> It creates a new node,
saves
+     * it using <code>session.save()</code>, modifies the node by adding a child
+     * node, saves again and finally verifies with a different session if
+     * changes have been stored properly.<br/> <br/> Prerequisites: <ul>
+     * <li><code>javax.jcr.tck.nodetype</code> must accept children of
same
+     * nodetype</li> </ul>
+     */
+    public void testSaveModifiedNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node newNode = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // save new node
+        superuser.save();
+
+        // and add a child node
+        newNode.addNode(nodeName2, testNodeType);
+
+        // save the changes
+        superuser.save();
+
+        // check if the child node was created properly
+
+        // get a reference with a second session to the modified node
+        Node newNodeSession2 = (Node) helper.getReadOnlySession().getItem(newNode.getPath());
+        // check if child is there
+        assertTrue("Modifications on  a node are not save after Session.save()", newNodeSession2.hasNode(nodeName2));
+    }
+
+    /**
+     * Tries to create and save a node using {@link javax.jcr.Session#save()}
+     * with an mandatory property that is not set on saving time.<br/> <br/>
+     * Prerequisites: <ul> <li><code>javax.jcr.tck.SessionTest.testSaveContstraintViolationException.nodetype2</code>
+     * must reference a nodetype that has one at least one property that is
+     * mandatory but not autocreated</li> </ul>
+     */
+    public void testSaveContstraintViolationException() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node with at least one mandatory, not autocreated property
+        defaultRootNode.addNode(nodeName1, getProperty("nodetype2"));
+
+        // save changes
+        try {
+            superuser.save();
+            fail("Trying to use Session.save() with a node that has a mandatory property
not set, should throw ConstraintViolationException");
+        } catch (ConstraintViolationException e) {
+            // ok
+        }
+    }
+
+    /**
+     * Tries to save a node using {@link javax.jcr.Session#save()} that was
+     * already deleted by an other session.<br/> <br/> Procedure: <ul>
+     * <li>Creates a new node with session 1, saves it, adds a child node.</li>
+     * <li>Access new node with session 2,deletes the node, saves it.</li>
+     * <li>session 1 tries to save modifications .</li> </ul> This should
throw
+     * an {@link javax.jcr.InvalidItemStateException}. <br/><br/>Prerequisites:
+     * <ul> <li><code>javax.jcr.tck.nodetype</code> must accept children
of same
+     * nodetype</li> </ul>
+     */
+    public void testSaveInvalidStateException() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node nodeSession1 = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // save new node
+        superuser.save();
+
+        // make a modification
+        nodeSession1.addNode(nodeName2, testNodeType);
+
+        // get the new node with a different session
+        Session testSession = helper.getReadWriteSession();
+        Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());
+
+        // delete the node with the new session
+        nodeSession2.remove();
+
+        // make node removal persistent
+        testSession.save();
+
+        // save changes made wit superuser session
+        try {
+            superuser.save();
+            fail("Saving a modified Node using Session.save() already deleted by an other
session should throw InvalidItemStateException");
+        } catch (InvalidItemStateException e) {
+            // ok, works as expected
+        }
+    }
+
+    /**
+     * Moves an unreferencable node with one session and saves the same node
+     * using a different session at same time.<br/> <br/> Procedure: <ul>
+     * <li>Creates node 1 and node 2 with session 1</li> <li>Gets reference
to
+     * node 1 using session 2</li> <li>session 1 moves node 1 under node 2 ,
+     * saves using session1.save()</li> <li>session 2 modifies node 1 by adding
+     * a child node, saves using session2.save()</li> </ul> Should throw {@link
+     * javax.jcr.InvalidItemStateException} since saving an unreferencable node
+     * that has been moved by and other session is not possible.
+     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
+     * must accept children of same nodetype and it must not be
+     * referencable</li> </ul>
+     */
+    public void testSaveMovedNotRefNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create non referenciable node to be moved with session 1
+        Node testNodeSession1 = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // create a second node with session 1 that will serve as new parent
+        Node newParentNodeSession1 = defaultRootNode.addNode(nodeName2, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // get the moving node with session 2
+        Session testSession = helper.getReadWriteSession();
+        Node testNodeSession2 = (Node) testSession.getItem(testNodeSession1.getPath());
+
+        //move the node with session 1
+        superuser.move(testNodeSession1.getPath(), newParentNodeSession1.getPath() + "/"
+ nodeName1);
+
+        // make the move persistent with session 1
+        superuser.save();
+
+        // add a child to the node with session
+        testNodeSession2.addNode(nodeName3, testNodeType);
+
+        // save it
+        try {
+            testSession.save();
+            fail("Saving a unreferencedable Node that has been moved by other session should
throw InvalidItemStateException");
+        } catch (InvalidItemStateException e) {
+            // ok, works as expected
+        }
+    }
+
+    /**
+     * Checks if {@link javax.jcr.Session#refresh(boolean refresh)} works
+     * properly with <code>refresh</code> set to <code>false</code>.<br/>
<br/>
+     * Procedure: <ul> <li>Creates two nodes with session 1</li> <li>Modifies
+     * node 1 with session 1 by adding a child node</li> <li>Get node 2 with
+     * session 2</li> <li>Modifies node 2 with session 2 by adding a child
+     * node</li> <li>saves session 2 changes using {@link
+     * javax.jcr.Session#save()}</li> <li>calls <code>Session.refresh(false)</code>
+     * on session 1</li> </ul> Session 1 changes should be cleared and session
2
+     * changes should now be visible to session 1. <br/><br/>Prerequisites: <ul>
+     * <li><code>javax.jcr.tck.nodetype</code> must accept children of
same
+     * nodetype</li> </ul>
+     */
+    public void testRefreshBooleanFalse() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node testNode1Session1 = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create a second node
+        Node testNode2Session1 = defaultRootNode.addNode(nodeName2, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // add child node to test node 1 using session 1
+        testNode1Session1.addNode(nodeName2, testNodeType);
+
+        // get session 2
+        Session session2 = helper.getReadWriteSession();
+
+        // get the second node
+        Node testNode2Session2 = (Node) session2.getItem(testNode2Session1.getPath());
+
+        // adds a child node
+        testNode2Session2.addNode(nodeName3, testNodeType);
+
+        // save the changes
+        session2.save();
+
+        // call refresh on session 1
+        superuser.refresh(false);
+
+        // check if session 1 flag has been cleared
+        assertFalse("Session should have no pending changes recorded after Session.refresh(false)!",
superuser.hasPendingChanges());
+
+        // check if added child node for node 1 by session 1 has been removed
+        assertFalse("Node Modifications have not been flushed after session.refresh(false)",
testNode1Session1.hasNodes());
+
+        // check if added child node for node 2 by session 2 has become visible in session
1
+        assertTrue("Node modified by a different session has not been updated after Session.refresh(false)",
testNode2Session1.hasNodes());
+    }
+
+    /**
+     * Checks if {@link javax.jcr.Session#refresh(boolean refresh)} works
+     * properly with <code>refresh</code> set to <code>true</code>.<br/>
<br/>
+     * Procedure: <ul> <li>Creates two nodes with session 1</li> <li>Modifies
+     * node 1 with session 1 by adding a child node</li> <li>Get node 2 with
+     * session 2</li> <li>Modifies node 2 with session 2 by adding a child
+     * node</li> <li>saves session 2 changes using {@link
+     * javax.jcr.Session#save()}</li> <li>calls <code>Session.refresh(true)</code>
+     * on session 1</li> </ul> Session 1 changes and session 2 changes now be
+     * visible to session 1. <br/><br/>Prerequisites: <ul>
+     * <li><code>javax.jcr.tck.nodetype</code> must accept children of
same
+     * nodetype</li> </ul>
+     */
+    public void testRefreshBooleanTrue() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node testNode1Session1 = defaultRootNode.addNode(nodeName1, testNodeType);
+        // create a second node
+        Node testNode2Session1 = defaultRootNode.addNode(nodeName2, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // add child node to test node 1 using session 1
+        testNode1Session1.addNode(nodeName2, testNodeType);
+
+        // get session 2
+        Session session2 = helper.getReadWriteSession();
+
+        // get the second node
+        Node testNode2Session2 = (Node) session2.getItem(testNode2Session1.getPath());
+
+        // adds a child node
+        testNode2Session2.addNode(nodeName3, testNodeType);
+
+        // save the changes
+        session2.save();
+
+        // call refresh on session 1
+        superuser.refresh(true);
+
+        // check if session 1 flag has been cleared
+        assertTrue("Session should still have pending changes recorded after Session.refresh(true)!",
superuser.hasPendingChanges());
+
+        // check if added child node for node 1 by session 1 is still there
+        assertTrue("Node Modifications are lost after session.refresh(true)", testNode1Session1.hasNodes());
+
+        // check if added child node for node 2 by session 2 has become visible in session
1
+        assertTrue("Node modified by a different session has not been updated after Session.refresh(true)",
testNode2Session1.hasNodes());
+    }
+
+    /**
+     * Checks if {@link javax.jcr.Session#hasPendingChanges()}  works
+     * properly.<br/> <br/> Procedure:<br/> <ul> <li>Gets a
session, checks
+     * inital flag setting</li> <li>Adds a node, checks flag</li> <li>Saves
on
+     * session, checks flag</li> <li>Adds a property, checks flag</li>
<li>Saves
+     * on session, checks flag</li> <li>Adds a child node, checks flag</li>
+     * <li>Saves on session, checks flag</li> <li>Removes child node, checks
+     * flag</li> <li>Saves on session, checks flag</li> <li>Removes
property,
+     * checks flag</li> <li>Saves on session, checks flag</li> </ul>
+     * Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>
must accept
+     * children of same nodetype</li> <li><code>javax.jcr.tck.propertyname1</code>
+     * must be the name of a String property that can be added to a node of type
+     * set in <code>javax.jcr.tck.nodetype</code> </ul>
+     */
+    public void testHasPendingChanges() throws RepositoryException {
+
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // initial check if flag is set correctly
+        assertFalse("Session should have no pending changes recorded!", superuser.hasPendingChanges());
+
+        // test with adding a node
+        Node testNode1 = defaultRootNode.addNode(nodeName1, testNodeType);
+        assertTrue("Session should have pending changes recorded after new node was added!",
superuser.hasPendingChanges());
+
+        // save the node
+        superuser.save();
+        // pending changes should have been cleared
+        assertFalse("Session should have no pending changes recorded after new node was added
and saved!", superuser.hasPendingChanges());
+
+        // adds a property
+        testNode1.setProperty(propertyName1, "test");
+        assertTrue("Session should have pending changes recorded after a property was added!",
superuser.hasPendingChanges());
+
+        // save the new prop
+        superuser.save();
+        // pending changes should have been cleared
+        assertFalse("Session should have no pending changes recorded after added property
hase been saved!", superuser.hasPendingChanges());
+
+        // add child node
+        Node testChildNode = testNode1.addNode(nodeName1, testNodeType);
+
+        assertTrue("Session should have pending changes recorded after child node has been
added!", superuser.hasPendingChanges());
+
+        // save the new child nodes
+        superuser.save();
+
+        // pending changes should have been cleared
+        assertFalse("Session should have no pending changes recorded after new child node
has been added and saved!", superuser.hasPendingChanges());
+
+
+        // remove the child node
+        testChildNode.remove();
+        assertTrue("Session should have pending changes recorded after child node has been
removed", superuser.hasPendingChanges());
+
+        // save the change
+        superuser.save();
+
+        // pending changes should have been cleared
+        assertFalse("Session should have no pending changes recorded after child node has
been removed and saved!", superuser.hasPendingChanges());
+
+        // remove the property
+        testNode1.setProperty(propertyName1, (Value) null);
+        assertTrue("Session should have pending changes recorded after property has been
removed", superuser.hasPendingChanges());
+
+        // save the change
+        superuser.save();
+
+        // pending changes should have been cleared
+        assertFalse("Session should have no pending changes recorded after property has been
removed and saved!", superuser.hasPendingChanges());
+
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionUUIDTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionUUIDTest.java?view=auto&rev=155927
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionUUIDTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionUUIDTest.java
Wed Mar  2 08:32:25 2005
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.Session;
+import javax.jcr.InvalidItemStateException;
+
+/**
+ * <code>SessionUUIDTest</code> contains all tests for the {@link javax.jcr.Session}
+ * class that require a UUID (and therefore are optional).
+ *
+ * @test
+ * @sources SessionUUIDTest.java
+ * @executeClass org.apache.jackrabbit.test.api.session.SessionUUIDTest
+ * @keywords uuid
+ */
+public class SessionUUIDTest extends AbstractJCRTest {
+
+    /**
+     * Tries to remove a node that is a reference target using {@link Session#save()}.<br>
+     * <br>Procedure:
+     * <ul>
+     * <li>Creates two nodes with same session</li>
+     * <li>One has a referencing property pointing to the other node</li>
+     * <li>Target node gets removed.</code></li>
+     * </ul>
+     * This should generate a {@link javax.jcr.ReferentialIntegrityException} upon save.
+     * <br><br>Prerequisites:
+     * <ul>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.nodetype</code> must allow
a property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.propertyname1</code> name
of the property of type {@link javax.jcr.PropertyType#REFERENCE}</li>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.nodetype2</code> must have
the mixin type <code>mix:referenceable</code> assigned.</li>
+     * </ul>
+     */
+    public void testSaveReferentialIntegrityException() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node with a property of type PropertyType.REFERENCE
+        Node referencingNode = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // create a node with a jcr:uuid property to serve as target
+        Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
+
+        // set the reference
+        referencingNode.setProperty(propertyName1, refTargetNode);
+
+        // save the new nodes
+        superuser.save();
+
+        // remove the referenced node
+        refTargetNode.remove();
+
+        // try to save
+        try {
+            superuser.save();
+            fail("Saving a deleted node using Session.save() that is a reference target should
throw ReferentialIntegrityException");
+        } catch (ReferentialIntegrityException e) {
+            // ok, works as expected
+        }
+    }
+
+    /**
+     * Moves a referencable node using {@link javax.jcr.Session#move(String, String)} with
one session and
+     * saves afterward changes made with a second session to the moved node using {@link
Session#save()}.<br/>
+     * <br/>
+     * Procedure:
+     * <ul>
+     * <li>Creates node 1 and node 2 with session 1</li>
+     * <li>Gets reference to node 1 using session 2</li>
+     * <li>Session 1 moves node 1 under node 2, saves changes</li>
+     * <li>Session 2 modifes node 1, saves</li>
+     * </ul>
+     * This should work since the modified node is identified by its UUID, not by position
in repository.
+     * <br><br>Prerequisites:
+     * <ul>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.nodetype2</code> must have
the mixin type <code>mix:referenceable</code> assigned.</li>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.testSaveMovedRefNode.propertyname1</code>
+     * name of a property that can be modified in <code>nodetype2</code> for
testing</li>
+     * </ul>
+     */
+    public void testSaveMovedRefNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node newParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // create a referenceable node
+        Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
+
+        // save the new nodes
+        superuser.save();
+
+        // get the moving node with session 2
+        Session testSession = helper.getReadWriteSession();
+
+        Node refTargetNodeSession2 = (Node) testSession.getItem(refTargetNode.getPath());
+
+        // move the node with session 1
+        superuser.move(refTargetNode.getPath(), newParentNode.getPath() + "/" + nodeName2);
+
+        // make the move persistent with session 1
+        superuser.save();
+
+        // modify some prop of the moved node with session 2
+        refTargetNodeSession2.setProperty(propertyName1, "test");
+
+        // save it
+        testSession.save();
+
+        // ok, works as expected
+    }
+
+    /**
+     * Moves a node using {@link javax.jcr.Session#move(String, String)} and places a new
<b>referenceable</b> node
+     * at the source position with same name. A second session tries to save changes made
to the moved node using
+     * {@link Session#save()}.
+     * <br/>
+     * Procedure:
+     * <ul>
+     * <li>Create node 1 and node 2 with session 1</li>
+     * <li>Session 2 gets a reference to node 1</li>
+     * <li>Session 1 moves node 1 under node 2 , saves</li>
+     * <li>session 1 adds new referencable node previous position of node 1</li>
+     * <li>session 2 modifes node, saves</li>
+     * </ul>
+     * This should fail since the node that replaces the moved node is referencable. Should
+     * throw {@link javax.jcr.InvalidItemStateException}.
+     * <br><br>Prerequisites:
+     * <ul>
+     * <li><code>javax.jcr.tck.nodetype</code> must allow children of itself.</li>
+     * <li><code>javax.jcr.tck.propertyname1</code>
+     * name of a property that can be modified in <code>javax.jcr.tck.nodetype</code>
for testing</li>
+     * <li><code>javax.jcr.tck.SessionUUIDTest.nodetype2</code> must have
the mixin type <code>mix:referenceable</code> assigned.</li>
+     * </ul>
+     */
+    public void testSaveReplacedNotRefNodeByRefNode() throws RepositoryException {
+        // get default workspace test root node using superuser session
+        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
+
+        // create a node
+        Node parentNode = defaultRootNode.addNode(nodeName1, testNodeType);
+
+        // create a moving node
+        Node movingNode = defaultRootNode.addNode(nodeName2, testNodeType);
+
+        // save the new nodes
+        superuser.save();
+
+        // get the moving node with session 2
+        Session testSession = helper.getReadWriteSession();
+        Node movingNodeSession2 = (Node) testSession.getItem(movingNode.getPath());
+
+        //move the node with session 1
+        superuser.move(movingNode.getPath(), parentNode.getPath() + "/" + nodeName2);
+
+        // repace it it with a referenciable node
+        parentNode.addNode(nodeName3, getProperty("nodetype2"));
+
+        // make the move and adding of new node persistent with session 1
+        superuser.save();
+
+        // modify some prop of the moved node
+        movingNodeSession2.setProperty(propertyName1, "test");
+
+        // save it
+        try {
+            testSession.save();
+            fail("Saving a unreferenceable Node using Session.save() that has been moved
and replaced by a referenceable node in the meantime should" +
+                    " throw InvalidItemStateException");
+        } catch (InvalidItemStateException e) {
+            // ok, what's expected
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SessionUUIDTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?view=diff&r1=155926&r2=155927
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Wed Mar
 2 08:32:25 2005
@@ -37,10 +37,9 @@
         TestSuite suite = new TestSuite("javax.jcr tests");
 
         // ADD TEST CLASSES HERE:
-        suite.addTestSuite(AddNodeTest.class);
+
+        // level 1 tests
         suite.addTestSuite(RootNodeTest.class);
-        suite.addTestSuite(NamespaceRegistryTest.class);
-        suite.addTestSuite(ReferencesTest.class);
         suite.addTestSuite(NodeReadMethodsTest.class);
         suite.addTestSuite(PropertyTypeTest.class);
         suite.addTestSuite(NodeDiscoveringNodeTypesTest.class);
@@ -63,6 +62,16 @@
         suite.addTestSuite(RepositoryDescriptorTest.class);
         suite.addTestSuite(SessionReadMethodsTest.class);
         suite.addTestSuite(WorkspaceReadMethodsTest.class);
+
+        // level 2 tests
+        suite.addTestSuite(AddNodeTest.class);
+        suite.addTestSuite(NamespaceRegistryTest.class);
+        suite.addTestSuite(ReferencesTest.class);
+        suite.addTestSuite(SessionTest.class);
+        suite.addTestSuite(SessionUUIDTest.class);
+        suite.addTestSuite(NodeTest.class);
+        suite.addTestSuite(NodeUUIDTest.class);
+        suite.addTestSuite(NodeOrderableChildNodesTest.class);
 
         return suite;
     }



Mime
View raw message