Author: angela Date: Thu Mar 1 02:39:43 2007 New Revision: 513267 URL: http://svn.apache.org/viewvc?view=rev&rev=513267 Log: tests Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMixedTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMoveTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewAndSavedTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewSNSTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderReferenceableSNSTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderSNSTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java (with props) jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/version/ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/version/LabelTest.java Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveSNSTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/DeepLockTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/OpenScopedLockTest.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestGeneralWrite.java jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/test/TestPropertyRead.java Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.AbstractJCRTest; + +import javax.jcr.Node; +import javax.jcr.ItemExistsException; +import javax.jcr.RepositoryException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.lock.LockException; + +/** + * AbstractMoveTest... + */ +abstract class AbstractMoveTest extends AbstractJCRTest { + + private static Logger log = LoggerFactory.getLogger(AbstractMoveTest.class); + + protected Node srcParentNode; + protected Node destParentNode; + protected Node moveNode; + + protected String destinationPath; + + protected void setUp() throws Exception { + super.setUp(); + + // create parent node + srcParentNode = testRootNode.addNode(nodeName1, testNodeType); + // create node to be moved + moveNode = srcParentNode.addNode(nodeName2, testNodeType); + // create a node that will serve as new parent + destParentNode = testRootNode.addNode(nodeName3, testNodeType); + // save the new nodes + testRootNode.save(); + + destinationPath = destParentNode.getPath() + "/" + nodeName2; + } + + protected abstract boolean isSessionMove(); + + protected void doMove(String srcPath, String destPath) + throws RepositoryException, LockException, ConstraintViolationException, ItemExistsException, VersionException { + if (isSessionMove()) { + superuser.move(srcPath, destPath); + } else { + superuser.getWorkspace().move(srcPath, destPath); + } + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.lock.LockException; + +/** + * AbstractMoveTreeTest... + */ +abstract class AbstractMoveTreeTest extends AbstractJCRTest { + + private static Logger log = LoggerFactory.getLogger(AbstractMoveTreeTest.class); + + protected Node childNode; + protected Node grandChildNode; + protected Property childProperty; + + protected Node srcParentNode; + protected Node destParentNode; + + protected String srcPath; + protected String destinationPath; + + protected void setUp() throws Exception { + super.setUp(); + + srcParentNode = testRootNode.addNode(nodeName1, testNodeType); + Node moveNode = srcParentNode.addNode(nodeName2, testNodeType); + destParentNode = testRootNode.addNode(nodeName3, testNodeType); + + srcPath = moveNode.getPath(); + destinationPath = destParentNode.getPath() + "/" + nodeName4; + + childProperty = moveNode.setProperty(propertyName2, "anyString"); + childNode = moveNode.addNode(nodeName2, testNodeType); + grandChildNode = childNode.addNode(nodeName3, testNodeType); + + doMove(moveNode.getPath(), destinationPath); + } + + protected abstract boolean saveBeforeMove(); + + protected abstract boolean isSessionMove(); + + protected void doMove(String srcPath, String destPath) throws RepositoryException, LockException, ConstraintViolationException, ItemExistsException, VersionException { + if (saveBeforeMove()) { + testRootNode.save(); + } + if (isSessionMove()) { + superuser.move(srcPath, destPath); + } else { + superuser.getWorkspace().move(srcPath, destPath); + } + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractMoveTreeTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.util.Text; + +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.ItemExistsException; +import javax.jcr.RepositoryException; +import javax.jcr.Property; +import javax.jcr.Node; +import javax.jcr.InvalidItemStateException; +import javax.jcr.AccessDeniedException; +import javax.jcr.Session; +import javax.jcr.lock.LockException; +import javax.jcr.version.VersionException; + +/** + * MoveMultipleTest... + */ +public class MoveMultipleTest extends AbstractMoveTest { + + private static Logger log = LoggerFactory.getLogger(MoveMultipleTest.class); + + private String originalPath; + + protected void setUp() throws Exception { + super.setUp(); + originalPath = moveNode.getPath(); + } + + protected boolean isSessionMove() { + return true; + } + + /** + * Transiently move a persisted node multiple times and check results + * after each move as well as after saving. + */ + public void testMultipleMove() throws RepositoryException, ConstraintViolationException, ItemExistsException, VersionException { + // 1. move + doMove(moveNode.getPath(), destinationPath); + + // 2. move + String destPath2 = srcParentNode.getPath()+"/"+nodeName1; + doMove(destinationPath, destPath2); + assertTrue(moveNode.getParent().isSame(srcParentNode)); + assertEquals(moveNode.getName(), Text.getName(destPath2)); + assertEquals(moveNode.getPath(), destPath2); + assertFalse(destParentNode.hasNode(Text.getName(destinationPath))); + + // 3. move + String destPath3 = destParentNode.getPath()+"/"+nodeName4; + doMove(destPath2, destPath3); + assertTrue(moveNode.getParent().isSame(destParentNode)); + assertEquals(moveNode.getName(), Text.getName(destPath3)); + assertEquals(moveNode.getPath(), destPath3); + assertFalse(srcParentNode.hasNode(Text.getName(destPath2))); + + testRootNode.save(); + + assertTrue(moveNode.getParent().isSame(destParentNode)); + assertEquals(moveNode.getName(), Text.getName(destPath3)); + assertEquals(moveNode.getPath(), destPath3); + assertFalse(srcParentNode.hasNode(Text.getName(destPath2))); + } + + /** + * Test revert of persisted node after multiple transient moves + */ + public void testRevertingMultipleMove() throws RepositoryException { + doMove(moveNode.getPath(), destinationPath); + String destPath2 = srcParentNode.getPath()+"/"+nodeName1; + doMove(destinationPath, destPath2); + String destPath3 = destParentNode.getPath()+"/"+nodeName4; + doMove(destPath2, destPath3); + + superuser.refresh(false); + + assertEquals(moveNode.getPath(), originalPath); + assertTrue(srcParentNode.hasNode(Text.getName(originalPath))); + assertFalse(srcParentNode.hasNode(Text.getName(destPath2))); + assertFalse(destParentNode.hasNodes()); + } + + /** + * Move a new node multiple times and check the hierarchy after saving. + */ + public void testMultipleMoveNewNode() throws RepositoryException, LockException, ConstraintViolationException, VersionException { + // add additional nodes + Node moveNode2 = moveNode.addNode(nodeName3, testNodeType); + + doMove(moveNode2.getPath(), destinationPath); + String destPath2 = destParentNode.getPath()+"/"+nodeName4; + doMove(moveNode2.getPath(), destPath2); + String destPath3 = srcParentNode.getPath()+"/"+nodeName4; + doMove(moveNode2.getPath(), destPath3); + doMove(moveNode2.getPath(), destinationPath); + + testRootNode.save(); + + assertTrue(moveNode2.getParent().isSame(destParentNode)); + assertEquals(moveNode2.getName(), Text.getName(destinationPath)); + assertEquals(moveNode2.getPath(), destinationPath); + assertFalse(moveNode2.hasNodes()); + + superuser.save(); + } + + /** + * Move destination after moving the target node. + */ + public void testMoveDestination() throws RepositoryException { + doMove(moveNode.getPath(), destinationPath); + doMove(destParentNode.getPath(), srcParentNode.getPath() + "/" + destParentNode.getName()); + + superuser.save(); + assertTrue(destParentNode.getParent().isSame(srcParentNode)); + assertTrue(moveNode.getParent().isSame(destParentNode)); + } + + /** + * Separately move the persisted 'moveNode' and its transiently added + * child node. + */ + public void testMoveParentAndChild() throws RepositoryException, LockException, ConstraintViolationException, VersionException { + // add additional nodes + Node moveNode2 = moveNode.addNode(nodeName3, testNodeType); + Property childProperty = moveNode2.setProperty(propertyName2, "anyString"); + Node childNode = moveNode2.addNode(nodeName4, testNodeType); + + doMove(moveNode.getPath(), destinationPath); + doMove(moveNode2.getPath(), srcParentNode.getPath() + "/" + moveNode2.getName()); + + assertFalse(moveNode.hasNode(moveNode2.getName())); + assertFalse(moveNode.hasNodes()); + assertTrue(srcParentNode.getNode(moveNode2.getName()).isSame(moveNode2)); + + doMove(moveNode.getPath(), originalPath); + + assertEquals(moveNode.getPath(), originalPath); + assertFalse(destParentNode.hasNode(Text.getName(destinationPath))); + + assertFalse(moveNode.hasNode(moveNode2.getName())); + assertFalse(moveNode.hasNodes()); + assertTrue(srcParentNode.getNode(moveNode2.getName()).isSame(moveNode2)); + + superuser.save(); + + assertFalse(moveNode.hasNodes()); + assertTrue(moveNode2.hasNode(childNode.getName())); + assertTrue(moveNode2.hasProperty(childProperty.getName())); + + assertTrue(srcParentNode.getNode(moveNode.getName()).isSame(moveNode)); + assertTrue(srcParentNode.getNode(moveNode2.getName()).isSame(moveNode2)); + } + + /** + * Move a node that has a child node and finally revert the 'move' operations. + */ + public void testRevertingMoveParentAndChild() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + Node moveNode2 = moveNode.addNode(nodeName3, testNodeType); + // moveNode2 must be persisted in order not to have it removed upon + // refresh(false). + moveNode.save(); + + doMove(moveNode.getPath(), destinationPath); + doMove(moveNode2.getPath(), srcParentNode.getPath() + "/" + moveNode2.getName()); + doMove(moveNode.getPath(), originalPath); + + testRootNode.refresh(false); + + // now all 3 move ops must be reverted + assertTrue(moveNode2.getParent().isSame(moveNode)); + assertTrue(moveNode.getParent().isSame(srcParentNode)); + assertFalse(destParentNode.hasNodes()); + assertFalse(srcParentNode.hasNode(moveNode2.getName())); + } + + /** + * Separately move the new 'moveNode' and its child node. Save 'add' and + * 'move' ops in one step. + */ + public void testMoveNewParentAndNewChild() throws RepositoryException, LockException, ConstraintViolationException, VersionException { + Node moveNode2 = moveNode.addNode("moveNode2", testNodeType); + Property childProperty = moveNode2.setProperty(propertyName2, "anyString"); + Node childNode = moveNode2.addNode("childNode", testNodeType); + + doMove(moveNode2.getPath(), destinationPath); + doMove(childNode.getPath(), srcParentNode.getPath() + "/" + childNode.getName()); + doMove(moveNode2.getPath(), srcParentNode.getPath() + "/" + nodeName4); + + superuser.save(); + + assertTrue(moveNode2.getName().equals(nodeName4)); + assertFalse(moveNode2.hasNodes()); + assertTrue(moveNode2.hasProperty(childProperty.getName())); + + assertTrue(moveNode2.getParent().isSame(srcParentNode)); + assertTrue(childNode.getParent().isSame(srcParentNode)); + } + + /** + * Separately move the persisted 'moveNode' and its 'new' child node. + * Check if reverting the changes removes the 'new' child and moves + * the persisted moveNode back. + */ + public void testRevertingMoveParentAndNewChild() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + Node moveNode2 = moveNode.addNode(nodeName3, testNodeType); + + doMove(moveNode.getPath(), destinationPath); + doMove(moveNode2.getPath(), srcParentNode.getPath() + "/" + moveNode2.getName()); + doMove(moveNode.getPath(), originalPath); + + testRootNode.refresh(false); + + // moveNode2 which has never been saved, must be removed + try { + moveNode2.getParent(); + fail("Reverting the move of a 'new' node must remove the new node as well."); + } catch (InvalidItemStateException e) { + // ok + } + // the persistent 'moveNode' must be moved back to its original position. + assertTrue(moveNode.getParent().isSame(srcParentNode)); + assertFalse(destParentNode.hasNodes()); + } + + /** + * Move a node with child items without having loaded the children before. + * Test if children can be accessed afterwards. + */ + public void testAccessChildrenAfterMove() throws RepositoryException, ConstraintViolationException, InvalidItemStateException, AccessDeniedException, NoSuchNodeTypeException, ItemExistsException, VersionException { + Property childProperty = moveNode.setProperty(propertyName2, "anyString"); + Node childNode = moveNode.addNode(nodeName2, testNodeType); + testRootNode.save(); + + Session otherSession = helper.getReadWriteSession(); + otherSession.move(originalPath, destinationPath); + + Node mv = (Node) otherSession.getItem(destinationPath); + + assertTrue(childNode.isSame(mv.getNode(nodeName2))); + assertTrue(childProperty.isSame(mv.getProperty(propertyName2))); + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveMultipleTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,109 @@ +/* + * $Id$ + * + * Copyright 1997-2005 Day Management AG + * Barfuesserplatz 6, 4001 Basel, Switzerland + * All Rights Reserved. + * + * This software is the confidential and proprietary information of + * Day Management AG, ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Day. + */ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.Item; +import javax.jcr.PathNotFoundException; + +/** + * MoveTreeTest... + */ +public class MoveNewTreeTest extends AbstractMoveTreeTest { + + private static Logger log = LoggerFactory.getLogger(MoveNewTreeTest.class); + + protected boolean saveBeforeMove() { + return false; + } + + protected boolean isSessionMove() { + return true; + } + + public void testTreeAncestors() throws RepositoryException { + int degree = destParentNode.getDepth(); + Item ancestor = childNode.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + ancestor = childProperty.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + ancestor = grandChildNode.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + + } + + public void testTreeEntries() throws RepositoryException { + Item item = superuser.getItem(destinationPath + "/" + nodeName2); + assertTrue("Moving a node must move all child items as well.", childNode.isSame(item)); + item = superuser.getItem(destinationPath + "/" + propertyName2); + assertTrue("Moving a node must move all child items as well.", childProperty.isSame(item)); + item = superuser.getItem(destinationPath + "/" + nodeName2 + "/" + nodeName3); + assertTrue("Moving a node must move all child items as well.", grandChildNode.isSame(item)); + } + + public void testOldPath() throws RepositoryException { + try { + superuser.getItem(srcPath + "/" + nodeName2 + "/" + nodeName3); + fail("Moving a node must move all child items as well."); + } catch (PathNotFoundException e) { + // ok + } + } + + /** + * Reverting the MOVE of a NEW-node must also remove the Node at its + * original position. + * + * @throws RepositoryException + */ + public void testRevertRemovedFromSrc() throws RepositoryException { + superuser.refresh(false); + assertFalse("Reverting move of a new node must remove the node from both positions.", superuser.itemExists(srcPath)); + } + + /** + * Reverting the MOVE of a NEW-node must remove the Node from the destination. + * + * @throws RepositoryException + */ + public void testRevertRemovedFromDestination() throws RepositoryException { + superuser.refresh(false); + assertFalse("Reverting move of a new node must remove the node from both positions.", superuser.itemExists(destinationPath)); + } + + public void testRevertInvalidatedMovedTree() throws RepositoryException { + superuser.refresh(false); + try { + childNode.getAncestor(0); + fail("Reverting move of a new node must remove the tree completely"); + } catch (RepositoryException e) { + // OK + } + try { + childProperty.getAncestor(0); + fail("Reverting move of a new node must remove the tree completely"); + } catch (RepositoryException e) { + // OK + } + try { + grandChildNode.getAncestor(0); + fail("Reverting move of a new node must remove the tree completely"); + } catch (RepositoryException e) { + // OK + } + } +} Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveNewTreeTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveReferenceableTest.java Thu Mar 1 02:39:43 2007 @@ -26,7 +26,7 @@ /** * MoveReferenceableTest... */ -public class MoveReferenceableTest extends MoveTest { +public class MoveReferenceableTest extends AbstractMoveTest { private static Logger log = LoggerFactory.getLogger(MoveReferenceableTest.class); @@ -41,6 +41,10 @@ moveNode.save(); } + protected boolean isSessionMove() { + return true; + } + /** * Test if a moved referenceable node still has the same uuid. */ @@ -48,7 +52,7 @@ String uuid = moveNode.getUUID(); //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); assertEquals("After successful moving a referenceable node node, the uuid must not have changed.", uuid, moveNode.getUUID()); } @@ -60,7 +64,7 @@ String uuid = moveNode.getUUID(); //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); superuser.save(); assertEquals("After successful moving a referenceable node node, the uuid must not have changed.", uuid, moveNode.getUUID()); } @@ -73,7 +77,7 @@ String uuid = moveNode.getUUID(); //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); Node n = superuser.getNodeByUUID(uuid); assertTrue("After successful moving a referenceable node node, accessing the node by uuid must return the same node.", n.isSame(moveNode)); @@ -89,7 +93,7 @@ String uuid = moveNode.getUUID(); //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); superuser.save(); Node n = superuser.getNodeByUUID(uuid); Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveSNSTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveSNSTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveSNSTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveSNSTest.java Thu Mar 1 02:39:43 2007 @@ -31,7 +31,7 @@ * expects orderable same-name-siblings to have a consistent and testable * order.) */ -public class MoveSNSTest extends MoveTest { +public class MoveSNSTest extends AbstractMoveTest { private static Logger log = LoggerFactory.getLogger(MoveSNSTest.class); @@ -56,6 +56,10 @@ testRootNode.save(); } + protected boolean isSessionMove() { + return true; + } + /** * Implementation specific: * Test if the path of a moved node, contains the index of the last sibling. @@ -63,7 +67,7 @@ public void testMovedNodeGetPath() throws RepositoryException, NotExecutableException { int index = destSibling.getIndex() + 1; //move the node - superuser.move(moveNode.getPath(),destinationPath); + doMove(moveNode.getPath(),destinationPath); assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath()); } @@ -75,7 +79,7 @@ public void testMovedNodeGetPath2() throws RepositoryException, NotExecutableException { int index = destSibling.getIndex() + 1; //move the node - superuser.move(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2); + doMove(moveNode.getPath(), destParentNode.getPath() + "/" + nodeName2); superuser.save(); assertEquals("After successful move the moved node must return the destination path.", destinationPath + "["+ index +"]", moveNode.getPath()); } @@ -87,7 +91,7 @@ public void testAccessMovedNodeByOldPath() throws RepositoryException, NotExecutableException { String oldPath = moveNode.getPath(); //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); try { Item item = superuser.getItem(oldPath); // Implementation specific: @@ -104,7 +108,7 @@ public void testAccessMovedNodeByOldPath2() throws RepositoryException, NotExecutableException { String oldPath = moveNode.getPath(); //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); superuser.save(); try { Item item = superuser.getItem(oldPath); @@ -124,7 +128,7 @@ */ public void testMovedNodeIsSame() throws RepositoryException, NotExecutableException { //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); int cnt = 0; for (NodeIterator it = destParentNode.getNodes(nodeName2); it.hasNext();) { @@ -148,7 +152,7 @@ */ public void testMovedNodeIsSame2() throws RepositoryException, NotExecutableException { //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); superuser.save(); int cnt = 0; Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTest.java Thu Mar 1 02:39:43 2007 @@ -18,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.jackrabbit.test.AbstractJCRTest; import org.apache.jackrabbit.test.NotExecutableException; import javax.jcr.RepositoryException; @@ -32,35 +31,18 @@ /** * MoveTest... */ -public class MoveTest extends AbstractJCRTest { +public class MoveTest extends AbstractMoveTest { private static Logger log = LoggerFactory.getLogger(MoveTest.class); - protected Node srcParentNode; - protected Node destParentNode; - protected Node moveNode; - - protected String destinationPath; - - protected void setUp() throws Exception { - super.setUp(); - - // create parent node - srcParentNode = testRootNode.addNode(nodeName1, testNodeType); - // create node to be moved - moveNode = srcParentNode.addNode(nodeName2, testNodeType); - // create a node that will serve as new parent - destParentNode = testRootNode.addNode(nodeName3, testNodeType); - // save the new nodes - testRootNode.save(); - - destinationPath = destParentNode.getPath() + "/" + nodeName2; + protected boolean isSessionMove() { + return true; } public void testMoveRoot() throws RepositoryException { Node root = superuser.getRootNode(); try { - superuser.move(root.getPath(), destinationPath); + doMove(root.getPath(), destinationPath); fail("Moving the root node must fail with RepositoryException."); } catch (RepositoryException e) { // OK @@ -69,7 +51,7 @@ public void testMoveBelowDescendant() throws RepositoryException { try { - superuser.move(srcParentNode.getPath(), moveNode.getPath() + "/" + nodeName2); + doMove(srcParentNode.getPath(), moveNode.getPath() + "/" + nodeName2); fail("Moving the ancestor node below descendant must fail with RepositoryException."); } catch (RepositoryException e) { // OK @@ -78,7 +60,7 @@ public void testMoveDestinationWithIndex() throws RepositoryException { try { - superuser.move(moveNode.getPath(), destinationPath + "[1]"); + doMove(moveNode.getPath(), destinationPath + "[1]"); fail("Moving to destination with index must fail with RepositoryException."); } catch (RepositoryException e) { // OK @@ -96,7 +78,7 @@ throw new NotExecutableException("Move destination already contains a child node with name " + nodeName2); } //move the node - superuser.move(oldPath,destinationPath); + doMove(oldPath, destinationPath); assertEquals("After successful move the moved node must return the destination path.", destinationPath, moveNode.getPath()); } @@ -111,7 +93,7 @@ throw new NotExecutableException("Move destination already contains a child node with name " + nodeName2); } //move the node - superuser.move(oldPath, destParentNode.getPath() + "/" + nodeName2); + doMove(oldPath, destParentNode.getPath() + "/" + nodeName2); superuser.save(); assertEquals("After successful move the moved node must return the destination path.", destinationPath, moveNode.getPath()); } @@ -133,7 +115,7 @@ String oldPath = moveNode.getPath(); //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); try { superuser.getItem(oldPath); fail("A moved node must not be accessible by its old path any more."); @@ -160,7 +142,7 @@ String oldPath = moveNode.getPath(); //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); superuser.save(); try { superuser.getItem(oldPath); @@ -186,7 +168,7 @@ String newPath = destParentNode.getPath() + "/" + nodeName2; //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); Item movedItem = superuser.getItem(newPath); assertTrue("Moved Node must be the same after the move.", movedItem.isSame(moveNode)); // NOTE: implementation specific test @@ -208,7 +190,7 @@ String oldPath = moveNode.getPath(); //move the node - superuser.move(oldPath, destinationPath); + doMove(oldPath, destinationPath); superuser.save(); Item movedItem = superuser.getItem(destinationPath); @@ -225,7 +207,7 @@ */ public void testMovedNodeParent() throws RepositoryException { //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); assertTrue("Parent of moved node must be the destination parent node.", moveNode.getParent().isSame(destParentNode)); // NOTE: implementation specific test assertTrue("After successful moving a referenceable node node, accessing the node by uuid be the identical node.", moveNode.getParent() == destParentNode); @@ -239,7 +221,7 @@ */ public void testMovedNodeParent2() throws RepositoryException { //move the node - superuser.move(moveNode.getPath(), destinationPath); + doMove(moveNode.getPath(), destinationPath); superuser.save(); assertTrue("Parent of moved node must be the destination parent node.", moveNode.getParent().isSame(destParentNode)); @@ -265,8 +247,8 @@ try { // move the node - superuser.move(moveNode.getPath(), destProperty.getPath()); - fail("Moving a node using Session.move() to a location where a property already exists must throw ItemExistsException"); + doMove(moveNode.getPath(), destProperty.getPath()); + fail("Moving a node to a location where a property exists must throw ItemExistsException"); } catch (ItemExistsException e) { // ok, works as expected } Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.*; + +/** + * MoveTreeTest... + */ +public class MoveTreeTest extends AbstractMoveTreeTest { + + private static Logger log = LoggerFactory.getLogger(MoveTreeTest.class); + + protected boolean saveBeforeMove() { + return true; + } + + protected boolean isSessionMove() { + return true; + } + + public void testTreeAncestors() throws RepositoryException { + int degree = destParentNode.getDepth(); + Item ancestor = childNode.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + ancestor = childProperty.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + ancestor = grandChildNode.getAncestor(degree); + assertTrue("Moving a node must move all child items as well.", ancestor.isSame(destParentNode)); + + } + + public void testTreeEntries() throws RepositoryException { + Item item = superuser.getItem(destinationPath + "/" + nodeName2); + assertTrue("Moving a node must move all child items as well.", childNode.isSame(item)); + item = superuser.getItem(destinationPath + "/" + propertyName2); + assertTrue("Moving a node must move all child items as well.", childProperty.isSame(item)); + item = superuser.getItem(destinationPath + "/" + nodeName2 + "/" + nodeName3); + assertTrue("Moving a node must move all child items as well.", grandChildNode.isSame(item)); + } + + public void testOldPath() throws RepositoryException { + try { + superuser.getItem(srcPath + "/" + nodeName2); + fail("Moving a node must move all child items as well."); + } catch (PathNotFoundException e) { + // ok + } + try { + superuser.getItem(srcPath + "/" + propertyName2); + fail("Moving a node must move all child items as well."); + } catch (PathNotFoundException e) { + // ok + } + try { + superuser.getItem(srcPath + "/" + nodeName2 + "/" + nodeName3); + fail("Moving a node must move all child items as well."); + } catch (PathNotFoundException e) { + // ok + } + } + + public void testAncestorAfterRevert() throws RepositoryException { + superuser.refresh(false); + Item ancestor = grandChildNode.getAncestor(srcParentNode.getDepth()); + assertTrue("Reverting a move-operation must move the tree back.", ancestor.isSame(srcParentNode)); + } + + public void testDestinationAfterRevert() throws RepositoryException { + superuser.refresh(false); + try { + superuser.getItem(destinationPath + "/" + propertyName2); + fail("Reverting a move-operation must move the tree back."); + } catch (PathNotFoundException e) { + // ok + } + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/MoveTreeTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RemoveNodeTest.java Thu Mar 1 02:39:43 2007 @@ -25,6 +25,7 @@ import javax.jcr.PathNotFoundException; import javax.jcr.InvalidItemStateException; import javax.jcr.Item; +import javax.jcr.Session; /** * RemoveNodeTest... @@ -53,7 +54,8 @@ // check if the node has been properly removed try { - testRootNode.getNode(nodeName1); + String relPath = removePath.substring(removePath.lastIndexOf('/') + 1); + testRootNode.getNode(relPath); fail("Transiently removed node should no longer be accessible from parent node."); } catch (PathNotFoundException e) { // ok , works as expected @@ -68,7 +70,8 @@ removeItem.remove(); testRootNode.save(); try { - testRootNode.getNode(nodeName1); + String relPath = removePath.substring(removePath.lastIndexOf('/') + 1); + testRootNode.getNode(relPath); fail("Persistently removed node should no longer be accessible from parent node."); } catch (PathNotFoundException e) { // ok , works as expected @@ -116,6 +119,32 @@ fail("Calling getProperty(String) on a removed node must throw InvalidItemStateException."); } catch (InvalidItemStateException e) { //ok + } + } + + public void testInvalidStateRemovedNode3() throws RepositoryException { + Node childNode = testRootNode.addNode(nodeName1, testNodeType); + superuser.save(); + + // get the node with session 2 + Session otherSession = helper.getReadWriteSession(); + try { + Node childNode2 = (Node) otherSession.getItem(childNode.getPath()); + + childNode.remove(); + superuser.save(); + + // try to remove already deleted node with session 2 + try { + childNode2.refresh(false); + childNode2.remove(); + otherSession.save(); + fail("Removing a node already deleted by other session should throw an InvalidItemStateException!"); + } catch (InvalidItemStateException e) { + //ok, works as expected + } + } finally { + otherSession.logout(); } } } Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; + +/** + * RenameTest... + */ +public class RenameTest extends AbstractMoveTest { + + private static Logger log = LoggerFactory.getLogger(RenameTest.class); + + private String renamedName; + private String renamePath; + + protected void setUp() throws Exception { + super.setUp(); + + renamedName = "renamed"; + renamePath = srcParentNode.getPath() + "/" + renamedName; + } + + protected boolean isSessionMove() { + return true; + } + + public void testRename() throws RepositoryException { + doMove(moveNode.getPath(), renamePath); + assertEquals(moveNode.getName(), renamedName); + superuser.save(); + assertEquals(moveNode.getName(), renamedName); + } + + public void testRevertRename() throws RepositoryException { + doMove(moveNode.getPath(), renamePath); + assertEquals(moveNode.getName(), renamedName); + + superuser.refresh(false); + assertEquals(moveNode.getName(), nodeName2); + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/RenameTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMixedTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMixedTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMixedTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMixedTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,28 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.lock.LockException; + +/** + * ReorderMixedTest... + */ +public class ReorderMixedTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderMixedTest.class); + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + child1 = testRootNode.addNode(nodeName2, testNodeType); + child2 = testRootNode.addNode(nodeName4, testNodeType); + child3 = testRootNode.addNode(nodeName2, testNodeType); + child4 = testRootNode.addNode(nodeName2, testNodeType); + + testRootNode.save(); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMoveTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMoveTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMoveTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderMoveTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,229 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; +import org.apache.jackrabbit.name.Path; +import org.apache.jackrabbit.util.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.NodeIterator; +import javax.jcr.ItemNotFoundException; + +/** + * ReorderMoveTest testing various combinations of move/rename + * and reorder with and without intermediate save, revert and other transient + * modifications. + */ +public class ReorderMoveTest extends AbstractJCRTest { + + private static Logger log = LoggerFactory.getLogger(ReorderMoveTest.class); + + private Node destParent; + private Node srcParent; + private String destPath; + + protected void setUp() throws Exception { + super.setUp(); + if (!testRootNode.getPrimaryNodeType().hasOrderableChildNodes()) { + throw new NotExecutableException("Test node does not have orderable children."); + } + + // create move-destination + destParent = testRootNode.addNode(nodeName4, testNodeType); + srcParent = testRootNode.addNode(nodeName2, testNodeType); + + destPath = destParent.getPath() + "/" + nodeName3; + testRootNode.save(); + } + + private Node[] createOrderableChildren(boolean sns, boolean doSave) throws RepositoryException { + String[] childNames; + if (sns) { + childNames = new String[] {nodeName2, nodeName2, nodeName2, nodeName2}; + } else { + childNames = new String[] {nodeName1, nodeName2, nodeName3, nodeName4}; + } + Node[] children = new Node[4]; + children[0] = srcParent.addNode(childNames[0], testNodeType); + children[1] = srcParent.addNode(childNames[1], testNodeType); + children[2] = srcParent.addNode(childNames[2], testNodeType); + children[3] = srcParent.addNode(childNames[3], testNodeType); + + if (doSave) { + testRootNode.save(); + } + return children; + } + + private static String getRelPath(Node child) throws RepositoryException { + if (child == null) { + return null; + } + String path = child.getPath(); + return path.substring(path.lastIndexOf('/')+1); + } + + private static void testOrder(Node parent, Node[] children) throws RepositoryException { + NodeIterator it = parent.getNodes(); + int i = 0; + while (it.hasNext()) { + Node child = it.nextNode(); + // TODO: check for sameNess must be replaced by 'isSame' for generic JCR impl + // assertTrue(child.isSame(children[i])); + assertSame(child, children[i]); + i++; + } + } + + /** + * Move a orderable child node and reorder the remaining nodes. + */ + public void testMoveAndReorder() throws RepositoryException { + Node[] children = createOrderableChildren(false, true); + String oldName = children[2].getName(); + // move + testRootNode.getSession().move(children[2].getPath(), destPath); + // reorder + srcParent.orderBefore(getRelPath(children[1]), null); + testOrder(srcParent, new Node[] {children[0], children[3], children[1]}); + + testRootNode.save(); + testOrder(srcParent, new Node[] {children[0], children[3], children[1]}); + assertFalse(srcParent.hasNode(oldName)); + } + + /** + * Move a orderable SNS-node and reorder the remaining nodes at source-parent. + */ + public void testMoveAndReorderSNS() throws RepositoryException { + Node[] children = createOrderableChildren(true, true); + String snsName = children[0].getName(); + + // move + testRootNode.getSession().move(children[2].getPath(), destPath); + testRootNode.getSession().move(children[1].getPath(), destPath); + + // reorder + srcParent.orderBefore(getRelPath(children[0]), null); + testOrder(srcParent, new Node[] {children[3], children[0]}); + assertFalse(srcParent.hasNode(snsName+"[4]")); + + testRootNode.save(); + testOrder(srcParent, new Node[] {children[3], children[0]}); + assertFalse(srcParent.hasNode(snsName+"[4]")); + + // check if move have been successfull + assertEquals(children[2].getPath(), destPath); + assertTrue(children[2].getIndex() == Path.INDEX_DEFAULT); + assertEquals(children[1].getPath(), destPath+"[2]"); + } + + /** + * Reorder nodes and move one of the reordered siblings + * away. Test the ordering of the remaining siblings. + */ + public void testReorderAndMove() throws RepositoryException { + Node[] children = createOrderableChildren(false, true); + + // reorder first + srcParent.orderBefore(getRelPath(children[0]), null); + srcParent.orderBefore(getRelPath(children[3]), getRelPath(children[1])); + // move + testRootNode.getSession().move(children[3].getPath(), destPath); + + testOrder(srcParent, new Node[] {children[1], children[2], children[0]}); + + testRootNode.save(); + testOrder(srcParent, new Node[] {children[1], children[2], children[0]}); + } + + /** + * Reorder same-name-sibling nodes and move one of the reordered siblings + * away. Test the ordering of the remaining siblings. + */ + public void testReorderAndMoveSNS() throws RepositoryException { + Node[] children = createOrderableChildren(true, true); + + // reorder first + srcParent.orderBefore(getRelPath(children[0]), null); + srcParent.orderBefore(getRelPath(children[3]), getRelPath(children[1])); + // move + testRootNode.getSession().move(children[3].getPath(), destPath); + + testOrder(srcParent, new Node[] {children[1], children[2], children[0]}); + + testRootNode.save(); + testOrder(srcParent, new Node[] {children[1], children[2], children[0]}); + } + + /** + * Any attempt reorder a moved node at its original position must fail. + */ + public void testReorderMovedNode() throws RepositoryException { + Node[] children = createOrderableChildren(false, true); + + String relPath = getRelPath(children[2]); + testRootNode.getSession().move(children[2].getPath(), destPath); + + try { + srcParent.orderBefore(relPath, null); + fail("Reordering a child node that has been moved away must fail."); + } catch (ItemNotFoundException e) { + // ok + } + } + + /** + * Move a SNS-node and reorder its original siblings afterwards. + * Test if reverting the changes results in the original ordering and + * hierarchy. + */ + public void testRevertMoveAndReorderSNS() throws RepositoryException { + Node[] children = createOrderableChildren(true, true); + // move then reorder + testRootNode.getSession().move(children[2].getPath(), destPath); + srcParent.orderBefore(getRelPath(children[1]), null); + srcParent.orderBefore(getRelPath(children[3]), getRelPath(children[0])); + + testRootNode.refresh(false); + testOrder(srcParent, new Node[] {children[0], children[1], children[2], children[3]}); + assertFalse(destParent.hasNode(Text.getName(destPath))); + } + + /** + * Move a SNS-node, that got its siblings reordered before. + * Test if reverting the changes results in the original ordering and + * hierarchy. + */ + public void testRevertReorderAndMoveSNS() throws RepositoryException { + Node[] children = createOrderableChildren(true, true); + // reorder then move + srcParent.orderBefore(getRelPath(children[1]), null); + srcParent.orderBefore(getRelPath(children[3]), getRelPath(children[2])); + srcParent.getSession().move(children[2].getPath(), destPath); + + testRootNode.refresh(false); + testOrder(srcParent, new Node[] {children[0], children[1], children[2], children[3]}); + assertFalse(destParent.hasNode(Text.getName(destPath))); + } + + /** + * Move a SNS-node, that has been reordered before. + * Test if reverting the changes results in the original ordering and + * hierarchy. + */ + public void testRevertMoveReorderedSNS() throws RepositoryException { + Node[] children = createOrderableChildren(true, true); + // reorder then move + srcParent.orderBefore(getRelPath(children[1]), null); + srcParent.orderBefore(getRelPath(children[3]), getRelPath(children[2])); + srcParent.getSession().move(children[1].getPath(), destPath); + + testRootNode.refresh(false); + testOrder(srcParent, new Node[] {children[0], children[1], children[2], children[3]}); + assertFalse(destParent.hasNode(Text.getName(destPath))); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewAndSavedTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewAndSavedTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewAndSavedTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewAndSavedTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,28 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.lock.LockException; + +/** + * ReorderNewAndSavedTest... + */ +public class ReorderNewAndSavedTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderNewAndSavedTest.class); + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + child1 = testRootNode.addNode(nodeName1, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + testRootNode.save(); + + child3 = testRootNode.addNode(nodeName3, testNodeType); + child4 = testRootNode.addNode(nodeName4, testNodeType); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewSNSTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewSNSTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewSNSTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewSNSTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,26 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.lock.LockException; + +/** + * ReorderNewSNSTest... + */ +public class ReorderNewSNSTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderNewSNSTest.class); + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + child1 = testRootNode.addNode(nodeName2, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + child3 = testRootNode.addNode(nodeName2, testNodeType); + child4 = testRootNode.addNode(nodeName2, testNodeType); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderNewTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,26 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.lock.LockException; + +/** + * ReorderNewTest... + */ +public class ReorderNewTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderNewTest.class); + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + child1 = testRootNode.addNode(nodeName1, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + child3 = testRootNode.addNode(nodeName3, testNodeType); + child4 = testRootNode.addNode(nodeName4, testNodeType); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderReferenceableSNSTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderReferenceableSNSTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderReferenceableSNSTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderReferenceableSNSTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,32 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.RepositoryException; +import javax.jcr.Node; + +/** + * ReorderSNSTest... + */ +public class ReorderReferenceableSNSTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderReferenceableSNSTest.class); + + protected void createOrderableChildren() throws RepositoryException, NotExecutableException { + child1 = testRootNode.addNode(nodeName2, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + child3 = testRootNode.addNode(nodeName2, testNodeType); + child4 = testRootNode.addNode(nodeName2, testNodeType); + Node[] children = new Node[] { child1, child2, child3, child4}; + for (int i = 0; i < children.length; i++) { + if (children[i].canAddMixin(mixReferenceable)) { + children[i].addMixin(mixReferenceable); + } else { + throw new NotExecutableException(); + } + } + testRootNode.save(); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderSNSTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderSNSTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderSNSTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderSNSTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,44 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.RepositoryException; +import javax.jcr.ItemExistsException; +import javax.jcr.Item; +import javax.jcr.Node; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.lock.LockException; + +/** + * ReorderSNSTest... + */ +public class ReorderSNSTest extends ReorderTest { + + private static Logger log = LoggerFactory.getLogger(ReorderSNSTest.class); + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException { + child1 = testRootNode.addNode(nodeName2, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + child3 = testRootNode.addNode(nodeName2, testNodeType); + child4 = testRootNode.addNode(nodeName2, testNodeType); + + testRootNode.save(); + } + + + public void testReorder3() throws RepositoryException { + String pathBefore = child3.getPath(); + + testRootNode.orderBefore(getRelPath(child3), getRelPath(child1)); + testRootNode.save(); + + Item itemIndex3 = testRootNode.getSession().getItem(pathBefore); + assertTrue(itemIndex3.isSame(child2)); + + Item item3 = testRootNode.getSession().getItem(child3.getPath()); + assertTrue(item3.isSame(child3)); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/ReorderTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,129 @@ +package org.apache.jackrabbit.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.RepositoryException; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.Session; +import javax.jcr.ItemExistsException; +import javax.jcr.lock.LockException; +import javax.jcr.version.VersionException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; + +/** + * ReorderTest... + */ +public class ReorderTest extends AbstractJCRTest { + + private static Logger log = LoggerFactory.getLogger(ReorderTest.class); + + protected Node child1; + protected Node child2; + protected Node child3; + protected Node child4; + + protected void setUp() throws Exception { + super.setUp(); + if (!testRootNode.getPrimaryNodeType().hasOrderableChildNodes()) { + throw new NotExecutableException("Test node does not have orderable children."); + } + createOrderableChildren(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + protected void createOrderableChildren() throws RepositoryException, LockException, ConstraintViolationException, NoSuchNodeTypeException, ItemExistsException, VersionException, NotExecutableException { + child1 = testRootNode.addNode(nodeName1, testNodeType); + child2 = testRootNode.addNode(nodeName2, testNodeType); + child3 = testRootNode.addNode(nodeName3, testNodeType); + child4 = testRootNode.addNode(nodeName4, testNodeType); + + testRootNode.save(); + } + + protected static String getRelPath(Node child) throws RepositoryException { + if (child == null) { + return null; + } + String path = child.getPath(); + return path.substring(path.lastIndexOf('/')+1); + } + + private static void testOrder(Node parent, Node[] children) throws RepositoryException { + NodeIterator it = parent.getNodes(); + int i = 0; + while (it.hasNext()) { + Node child = it.nextNode(); + assertTrue(child.isSame(children[i])); + i++; + } + } + + public void testReorder() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child1), getRelPath(child3)); + testOrder(testRootNode, new Node[] { child2, child1, child3, child4}); + + testRootNode.save(); + testOrder(testRootNode, new Node[] { child2, child1, child3, child4}); + } + + public void testReorderToEnd() throws RepositoryException, ConstraintViolationException, UnsupportedRepositoryOperationException, VersionException { + testRootNode.orderBefore(getRelPath(child2), null); + testOrder(testRootNode, new Node[] { child1, child3, child4, child2}); + + testRootNode.save(); + testOrder(testRootNode, new Node[] { child1, child3, child4, child2}); + } + + public void testRevertReorder() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child4), getRelPath(child2)); + testOrder(testRootNode, new Node[] { child1, child4, child2, child3}); + + testRootNode.refresh(false); + testOrder(testRootNode, new Node[] { child1, child2, child3, child4}); + } + + public void testRevertReorderToEnd() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child1), null); + testOrder(testRootNode, new Node[] { child2, child3, child4, child1}); + + testRootNode.refresh(false); + testOrder(testRootNode, new Node[] { child1, child2, child3, child4}); + } + + public void testReorder2() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child3), getRelPath(child1)); + testRootNode.save(); + + Session otherSession = helper.getReadOnlySession(); + testOrder((Node) otherSession.getItem(testRootNode.getPath()), new Node[] {child3, child1, child2, child4}); + } + + public void testReorderTwice() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child2), null); + testRootNode.orderBefore(getRelPath(child4), getRelPath(child1)); + + testOrder(testRootNode, new Node[] { child4, child1, child3, child2}); + testRootNode.save(); + testOrder(testRootNode, new Node[] { child4, child1, child3, child2}); + } + + public void testReorderFinallyOriginalOrder() throws RepositoryException { + testRootNode.orderBefore(getRelPath(child4), getRelPath(child1)); + testRootNode.orderBefore(getRelPath(child3), getRelPath(child4)); + testRootNode.orderBefore(getRelPath(child2), getRelPath(child3)); + testRootNode.orderBefore(getRelPath(child1), getRelPath(child2)); + + testOrder(testRootNode, new Node[] { child1, child2, child3, child4}); + testRootNode.save(); + testOrder(testRootNode, new Node[] { child1, child2, child3, child4}); + } +} Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java?view=auto&rev=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java (added) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java Thu Mar 1 02:39:43 2007 @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jcr2spi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.RepositoryException; +import javax.jcr.Property; +import javax.jcr.ItemExistsException; + +/** + * WorkspaceMoveTest... + */ +public class WorkspaceMoveTest extends MoveTest { + + private static Logger log = LoggerFactory.getLogger(WorkspaceMoveTest.class); + + protected void setUp() throws Exception { + super.setUp(); + } + + protected boolean isSessionMove() { + return false; + } + + + /** + * Tries to move a node using to a location where a property already exists + * with same name. + *

+ * This should throw an {@link javax.jcr.ItemExistsException}. + */ + public void testMovePropertyExistsException() throws RepositoryException, NotExecutableException { + // try to create a property with the name of the node to be moved + // to the destination parent + Property destProperty; + try { + destProperty = destParentNode.setProperty(nodeName2, "anyString"); + destParentNode.save(); + } catch (RepositoryException e) { + throw new NotExecutableException("Cannot create property with name '" +nodeName2+ "' and value 'anyString' at move destination."); + } + + try { + // move the node + doMove(moveNode.getPath(), destProperty.getPath()); + fail("Moving a node to a location where a property exists must throw ItemExistsException"); + } catch (ItemExistsException e) { + // ok, works as expected + } + } + + public void testMoveTransientPropertyExistsException() throws RepositoryException, NotExecutableException { + // try to create a property with the name of the node to be moved + // to the destination parent + Property destProperty; + try { + destProperty = destParentNode.setProperty(nodeName2, "anyString"); + } catch (RepositoryException e) { + throw new NotExecutableException("Cannot create property with name '" +nodeName2+ "' and value 'anyString' at move destination."); + } + + try { + // move the node + doMove(moveNode.getPath(), destProperty.getPath()); + fail("Moving a node to a location where a property exists must throw ItemExistsException"); + } catch (ItemExistsException e) { + // ok, works as expected + } + } +} \ No newline at end of file Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/WorkspaceMoveTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/AbstractLockTest.java Thu Mar 1 02:39:43 2007 @@ -53,8 +53,8 @@ } protected void tearDown() throws Exception { + // make sure all locks are removed try { - // make sure all locks are removed lockedNode.unlock(); } catch (RepositoryException e) { // ignore @@ -256,6 +256,52 @@ } finally { // mk sure all locks are release again lockedNode2.unlock(); + } + } + + /** + * A locked node must also be locked if accessed by some other session. + */ + public void testLockVisibility() throws RepositoryException { + Session otherSession = helper.getReadOnlySession(); + Node ln2 = (Node) otherSession.getItem(lockedNode.getPath()); + assertTrue("Locked node must also be locked for another session", ln2.isLocked()); + assertTrue("Locked node must also be locked for another session", ln2.holdsLock()); + } + + /** + * If a locked nodes is unlocked again, any Lock instance retrieved by + * another session must change the lock-status. Similarly, the previously + * locked node must not be marked locked any more. + */ + public void testUnlockByOtherSession() throws RepositoryException { + Session otherSession = helper.getReadOnlySession(); + Node ln2 = (Node) otherSession.getItem(lockedNode.getPath()); + Lock l2 = ln2.getLock(); + + lockedNode.unlock(); + + assertFalse("Lock must be informed if Node is unlocked.", l2.isLive()); + } + + /** + * If a locked nodes is unlocked again, any Lock instance retrieved by + * another session must change the lock-status. Similarly, the previously + * locked node must not be marked locked any more. + */ + public void testUnlockByOtherSession2() throws RepositoryException { + Session otherSession = helper.getReadOnlySession(); + Node ln2 = (Node) otherSession.getItem(lockedNode.getPath()); + + lockedNode.unlock(); + + assertFalse("Node is not locked any more", ln2.isLocked()); + assertFalse("Node is not locked any more", ln2.holdsLock()); + try { + ln2.getLock(); + fail("Node is not locked any more"); + } catch (LockException e) { + // OK } } } Modified: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/DeepLockTest.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/DeepLockTest.java?view=diff&rev=513267&r1=513266&r2=513267 ============================================================================== --- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/DeepLockTest.java (original) +++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/lock/DeepLockTest.java Thu Mar 1 02:39:43 2007 @@ -33,7 +33,7 @@ private static Logger log = LoggerFactory.getLogger(DeepLockTest.class); - private boolean isSessionScoped = true; + private boolean isSessionScoped = false; private boolean isDeep = true; private Node lockedNode; @@ -51,6 +51,15 @@ lock = lockedNode.lock(isDeep, isSessionScoped); } + protected void tearDown() throws Exception { + try { + lockedNode.unlock(); + } catch (RepositoryException e) { + log.warn(e.getMessage()); + } + super.tearDown(); + } + public void testLockHoldingNode() throws RepositoryException { assertTrue("Lock.getNode() must be lockholding node.", lock.getNode().isSame(lockedNode)); } @@ -59,21 +68,43 @@ assertTrue("Lock.isDeep() if lock has been created deeply.", lock.isDeep()); } + public void testNodeIsLocked() throws RepositoryException { + assertTrue("Creating a deep lock must create a lock on the lock-holding node", lockedNode.isLocked()); + assertTrue("Creating a deep lock must create a lock on the lock-holding node", lockedNode.holdsLock()); + } + public void testIsLockedChild() throws RepositoryException { assertTrue("Child node below deep lock must be locked", childNode.isLocked()); } + public void testIsLockedNewChild() throws RepositoryException { + Node newChild = lockedNode.addNode(nodeName3, testNodeType); + assertTrue("Child node below deep lock must be locked even if its is NEW", newChild.isLocked()); + } + public void testNotHoldsLockChild() throws RepositoryException { assertFalse("Child node below deep lock must not be lock holder", childNode.holdsLock()); } public void testGetLockOnChild() throws RepositoryException { // get lock must succeed even if child is not lockable. - Lock lock = childNode.getLock(); + childNode.getLock(); + } + + public void testGetLockOnNewChild() throws RepositoryException { + // get lock must succeed even if child is not lockable. + Node newChild = lockedNode.addNode(nodeName3, testNodeType); + newChild.getLock(); } public void testGetNodeOnLockObtainedFromChild() throws RepositoryException { Lock lock = childNode.getLock(); + assertTrue("Lock.getNode() must return the lock holding node even if lock is obtained from child node.", lock.getNode().isSame(lockedNode)); + } + + public void testGetNodeOnLockObtainedFromNewChild() throws RepositoryException { + Node newChild = lockedNode.addNode(nodeName3, testNodeType); + Lock lock = newChild.getLock(); assertTrue("Lock.getNode() must return the lock holding node even if lock is obtained from child node.", lock.getNode().isSame(lockedNode)); }