Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckoutTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckoutTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckoutTest.java (working copy) @@ -21,6 +21,7 @@ import javax.jcr.ItemNotFoundException; import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.Value; +import javax.jcr.version.VersionManager; /** * CheckoutTest covers tests related to {@link @@ -36,10 +37,15 @@ protected void setUp() throws Exception { super.setUp(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + if (!versionManager.isCheckedOut(path)) { + fail("A versionable node must be checked-out after persistent creation."); + } if (!versionableNode.isCheckedOut()) { fail("A versionable node must be checked-out after persistent creation."); } - versionableNode.checkin(); + versionManager.checkin(path); } /** @@ -52,6 +58,17 @@ } /** + * Test if VersionManager.isCheckedOut(P) returns true if P is the + * absolute path of a versionable node that has been checked out before. + */ + public void testIsCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); + assertTrue("After successfully calling VersionManager.checkout(P) with P denoting the absolute path of a versionable node, VersionManager.isCheckedOut(P) must return true.", versionManager.isCheckedOut(path)); + } + + /** * Test calling Node.isCheckedOut() on a non-versionable. */ public void testIsCheckedOutNonVersionableNode() throws RepositoryException { @@ -78,18 +95,63 @@ } /** + * Test calling VersionManager.isCheckedOut(P) with P denoting the + * absolute path of a non-versionable node. + */ + public void testIsCheckedOutNonVersionableNodeJcr2() throws RepositoryException { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + boolean isCheckedOut = versionManager.isCheckedOut(path); + Node vParent = null; + try { + vParent = nonVersionableNode.getParent(); + while (!vParent.isNodeType(mixVersionable)) { + vParent = vParent.getParent(); + } + } catch (ItemNotFoundException e) { + // root reached. + } + + if (vParent != null && vParent.isNodeType(mixVersionable)) { + String parentPath = vParent.getPath(); + if (versionManager.isCheckedOut(parentPath)) { + assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-out.", isCheckedOut); + } else { + assertFalse("VersionManager.isCheckedOut(P) must return false if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-in.", isCheckedOut); + } + } else { + assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node that has no versionable ancestor", isCheckedOut); + } + } + + /** * Test calling Node.checkout() on a non-versionable node. */ public void testCheckoutNonVersionableNode() throws RepositoryException { try { nonVersionableNode.checkout(); - fail("Node.checkout() on a non versionable node must throw UnsupportedRepositoryOperationException"); + fail("Node.checkout() on a non-versionable node must throw UnsupportedRepositoryOperationException"); } catch (UnsupportedRepositoryOperationException e) { //success } } /** + * Test calling VersionManager.checkout(P) with P denoting the absolute + * path of a non-versionable node. + */ + public void testCheckoutNonVersionableNodeJcr2() throws RepositoryException { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + try { + versionManager.checkout(path); + fail("VersionManager.checkout(P) with P denoting the absolute path of a non-versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** * Test if Node.checkout() doesn't throw any exception if the versionable * node has been checked out before. */ @@ -99,6 +161,18 @@ } /** + * Test if VersionManager.checkout(P) doesn't throw any exception if P + * denotes the absolute path of a versionable node that has been checked + * out before. + */ + public void testCheckoutTwiceDoesNotThrowJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); + versionManager.checkout(path); + } + + /** * Test if Node.checkout() copies the node's jcr:baseVersion to node's * jcr:predecessors property (no save required). */ @@ -121,4 +195,31 @@ fail("After calling Node.checkout() the current value of node's jcr:baseVersion must be copied to node's jcr:predecessors property"); } } + + /** + * Test if VersionManager.checkout(P), with P denoting the absolute path + * of a versionable node, copies the node's jcr:baseVersion to the node's + * jcr:predecessors property (no save required). + */ + public void testCheckoutCopiesBaseValueToPredecessorPropertyJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Value baseVersionValue = versionableNode.getProperty(jcrBaseVersion).getValue(); + versionManager.checkout(path); + Value[] predecessorsValues = versionableNode.getProperty(jcrPredecessors).getValues(); + + // loop over all values of jcr:predecessors property as it's not sure + // on which position jcr:baseVersion is copied. + boolean foundBaseVersionProp = false; + int i = 0; + while (i < predecessorsValues.length && !foundBaseVersionProp) { + if (predecessorsValues[i].equals(baseVersionValue)) { + foundBaseVersionProp = true; + } + i++; + } + if (!foundBaseVersionProp) { + fail("After calling Node.checkout() the current value of node's jcr:baseVersion must be copied to node's jcr:predecessors property"); + } + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/FrozenNodeTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/FrozenNodeTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/FrozenNodeTest.java (working copy) @@ -19,6 +19,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.version.Version; +import javax.jcr.version.VersionManager; /** * CheckinTest covers tests related to {@link javax.jcr.Node#checkin()}. @@ -33,18 +34,22 @@ protected void setUp() throws Exception { super.setUp(); - versionableNode.checkout(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); } /** * @throws RepositoryException */ public void testFrozenNodeUUUID() throws RepositoryException { - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrUUID).getValue().getString(); - String nuuid = n.getUUID(); - assertEquals("jcr:uuid needs to be equal to the getUUID() return value.", nuuid, puuid); + String nuuid = n.getIdentifier(); + assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); } /** @@ -52,23 +57,30 @@ */ public void testFrozenChildNodeUUUID() throws RepositoryException { versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode).getNode("child"); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrUUID).getValue().getString(); - String nuuid = n.getUUID(); - assertEquals("jcr:uuid needs to be equal to the getUUID() return value.", nuuid, puuid); + String nuuid = n.getIdentifier(); + assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); } /** * @throws RepositoryException */ public void testFrozenUUUID() throws RepositoryException { - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode); + // make versionable node referenceable + versionableNode.addMixin(mixReferenceable); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode(); String fuuid = n.getProperty(jcrFrozenUuid).getValue().getString(); - String ruuid = versionableNode.getUUID(); - assertEquals("jcr:frozenUuid needs to be equal to the getUUID() return value.", ruuid, fuuid); + String ruuid = versionableNode.getIdentifier(); + assertEquals("jcr:frozenUuid needs to be equal to the getIdentifier() return value.", ruuid, fuuid); } /** @@ -76,12 +88,15 @@ */ public void testFrozenChildUUUID() throws RepositoryException { Node n1 = versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode).getNode("child"); + n1.addMixin(mixReferenceable); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode().getNode("child"); String fuuid = n.getProperty(jcrFrozenUuid).getValue().getString(); - String ruuid = n1.getUUID(); - assertEquals("jcr:frozenUuid needs to be equal to the getUUID() return value.", ruuid, fuuid); + String ruuid = n1.getIdentifier(); + assertEquals("jcr:frozenUuid needs to be equal to the getIdentifier() return value.", ruuid, fuuid); } @@ -89,8 +104,10 @@ * @throws RepositoryException */ public void testFrozenNodeNodeType() throws RepositoryException { - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); @@ -101,9 +118,11 @@ */ public void testFrozenChildNodeNodeType() throws RepositoryException { versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode).getNode("child"); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid); @@ -113,8 +132,10 @@ * @throws RepositoryException */ public void testFrozenNodeType() throws RepositoryException { - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode(); String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString(); String ruuid = versionableNode.getPrimaryNodeType().getName(); assertEquals("jcr:frozenPrimaryType needs to be equal to the getPrimaryNodeType() return value.", ruuid, fuuid); @@ -125,9 +146,11 @@ */ public void testFrozenChildNodeType() throws RepositoryException { Node n1 = versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); - Node n = v.getNode(jcrFrozenNode).getNode("child"); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Node n = v.getFrozenNode().getNode("child"); String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString(); String ruuid = n1.getPrimaryNodeType().getName(); assertEquals("jcr:frozenPrimaryType needs to be equal to the getPrimaryNodeType() return value.", ruuid, fuuid); Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/RestoreTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/RestoreTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/RestoreTest.java (working copy) @@ -23,10 +23,7 @@ import javax.jcr.RepositoryException; import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.nodetype.NodeDefinition; -import javax.jcr.version.OnParentVersionAction; -import javax.jcr.version.Version; -import javax.jcr.version.VersionException; -import javax.jcr.version.VersionIterator; +import javax.jcr.version.*; import org.apache.jackrabbit.test.NotExecutableException; @@ -46,6 +43,8 @@ */ public class RestoreTest extends AbstractVersionTest { + VersionManager versionManager; + Version version; Version version2; Version rootVersion; @@ -57,17 +56,19 @@ protected void setUp() throws Exception { super.setUp(); + versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); propertyValue1 = getProperty("propertyValue1"); - propertyValue2 = getProperty("propertyValue1"); + propertyValue2 = getProperty("propertyValue2"); versionableNode.setProperty(propertyName1, propertyValue1); - versionableNode.save(); - version = versionableNode.checkin(); - versionableNode.checkout(); + versionableNode.getSession().save(); + version = versionManager.checkin(path); + versionManager.checkout(path); versionableNode.setProperty(propertyName1, propertyValue2); - versionableNode.save(); - version2 = versionableNode.checkin(); - versionableNode.checkout(); - rootVersion = versionableNode.getVersionHistory().getRootVersion(); + versionableNode.getSession().save(); + version2 = versionManager.checkin(path); + versionManager.checkout(path); + rootVersion = versionManager.getVersionHistory(path).getRootVersion(); // build a second versionable node below the testroot try { @@ -80,7 +81,7 @@ protected void tearDown() throws Exception { try { versionableNode2.remove(); - testRootNode.save(); + testRootNode.getSession().save(); } finally { version = null; version2 = null; @@ -105,6 +106,20 @@ } /** + * Test if restoring the root version fails. + * + * @throws RepositoryException + */ + public void testRestoreRootVersionFailJcr2() throws RepositoryException { + try { + versionManager.restore(rootVersion, true); + fail("Restore of jcr:rootVersion must throw VersionException."); + } catch (VersionException e) { + // success + } + } + + /** * Test if restoring a node works on checked-in node. * * @throws RepositoryException @@ -115,6 +130,46 @@ } /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_1() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(version, true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_2() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(versionableNode.getPath(), version, true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_3() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(versionableNode.getPath(), version.getName(), true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_4() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(new Version[] {version}, true); + } + + /** * Test if restoring a node works on checked-out node. * * @throws RepositoryException @@ -124,28 +179,147 @@ } /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2() throws RepositoryException { + versionManager.restore(version, true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + } + + /** * Restoring a node set the jcr:isCheckedOut property to false. * * @throws RepositoryException */ public void testRestoreSetsIsCheckedOutToFalse() throws RepositoryException { versionableNode.restore(version, true); - assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionableNode.isCheckedOut()); } /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2() throws RepositoryException { + versionManager.restore(version, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** * Test if restoring a node restores the correct property * * @throws RepositoryException */ - public void testRestoreCorrectVersion() throws RepositoryException { + public void testRestoreCorrectProperty() throws RepositoryException { versionableNode.restore(version, true); String value = versionableNode.getProperty(propertyName1).getString(); assertEquals("Restoring a node must set the correct property.", propertyValue1, value); } /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2() throws RepositoryException { + versionManager.restore(version, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** * Test if InvalidItemStateException is thrown if the node has pending changes. * * @throws RepositoryException @@ -163,6 +337,74 @@ } /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(version, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_2() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(versionableNode.getPath(), version, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_3() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(versionableNode.getPath(), version.getName(), true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_4() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(new Version[] {version}, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** * VersionException expected on Node.restore(Version, boolean) if the * specified version is not part of this node's version history. * @@ -180,6 +422,23 @@ } /** + * VersionException expected on restore if the + * specified version is not part of this node's version history. + * + * @throws RepositoryException + */ + public void testRestoreInvalidVersionJcr2() throws RepositoryException { + Version vNode2 = versionManager.checkin(versionableNode2.getPath()); + try { + versionManager.restore(versionableNode.getPath(), vNode2, true); + + fail("VersionException expected on Node.restore(Version, boolean) if the specified version is not part of this node's version history."); + } catch (VersionException e) { + // ok + } + } + + /** * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history. * * @throws RepositoryException @@ -206,6 +465,32 @@ } /** + * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history. + * + * @throws RepositoryException + */ + public void testRestoreInvalidVersion2Jcr2() throws RepositoryException { + String invalidName; + do { + invalidName = createRandomString(3); + for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext();) { + Version v = it.nextVersion(); + if (invalidName.equals(v.getName())) { + invalidName = null; + break; + } + } + } while (invalidName == null); + + try { + versionManager.restore(versionableNode.getPath(), invalidName, true); + fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history."); + } catch (VersionException e) { + // ok + } + } + + /** * Test calling Node.restore(String, boolean) on a non-versionable node. * * @throws RepositoryException @@ -221,6 +506,36 @@ } /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(String, boolean) + */ + public void testRestoreNonVersionableNodeJcr2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version, true); + fail("trying to restore on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(String, boolean) + */ + public void testRestoreNonVersionableNodeJcr2_2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), "foo", true); + fail("trying to restore on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** * Test calling Node.restore(Version, String, boolean) on a non-versionable node. * * @throws RepositoryException @@ -253,6 +568,36 @@ } /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(Version, boolean) + */ + public void testRestoreNonVersionableNode3Jcr2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version, true); + fail("Node.restore(Version, boolean) on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(Version, boolean) + */ + public void testRestoreNonVersionableNode3Jcr2_2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version.getName(), true); + fail("Node.restore(Version, boolean) on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** * Test if restoring a node with an invalid Version throws a VersionException * * @throws RepositoryException @@ -268,6 +613,21 @@ } /** + * Test if restoring a node with an invalid Version throws a VersionException + * + * @throws RepositoryException + */ + public void testRestoreWithInvalidVersionJcr2() throws RepositoryException { + Version invalidVersion = versionManager.checkin(versionableNode2.getPath()); + try { + versionManager.restore(versionableNode.getPath(), invalidVersion, true); + fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history."); + } catch (VersionException e) { + // success + } + } + + /** * Tests if restoring the Version of an existing node throws an * ItemExistsException if removeExisting is set to FALSE. */ @@ -292,9 +652,109 @@ } } + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(v, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_2() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(versionableNode.getPath(), v, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(versionableNode.getPath(), v.getName(), false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_4() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(new Version[] {v}, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + public void testRestoreChild1() throws RepositoryException { versionableNode.addNode("child1"); - versionableNode.save(); + versionableNode.getSession().save(); Version v1 = versionableNode.checkin(); versionableNode.checkout(); Version v2 = versionableNode.checkin(); @@ -312,6 +772,86 @@ } } + public void testRestoreChild1Jcr2() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(v1, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(version, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(v2, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_2() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(versionableNode.getPath(), v1, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(versionableNode.getPath(), version, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(versionableNode.getPath(), v2, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_3() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(versionableNode.getPath(), v1.getName(), true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(versionableNode.getPath(), version.getName(), true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(versionableNode.getPath(), v2.getName(), true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_4() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(new Version[] {v1}, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(new Version[] {version}, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(new Version[] {v2}, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + /** * Test the restore of a versionable node using a label. * @throws RepositoryException @@ -327,6 +867,20 @@ } /** + * Test the restore of a versionable node using a label. + * @throws RepositoryException + */ + public void testRestoreLabelJcr2() throws RepositoryException { + // mark V1 with label test1 + versionManager.getVersionHistory(versionableNode.getPath()).addVersionLabel(version.getName(), "test", true); + + // restore V1 via label. + versionManager.restoreByLabel(versionableNode.getPath(), "test", true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Node.restore('test') not correctly restored", propertyValue1, value); + } + + /** * Test the restore of the OPV=Version child nodes. * @throws RepositoryException */ @@ -336,7 +890,7 @@ if (!child1.isNodeType(mixVersionable)) { child1.addMixin(mixVersionable); } - versionableNode.save(); + versionableNode.getSession().save(); // create v1.0 of child Version v1Child = child1.checkin(); @@ -368,6 +922,47 @@ } /** + * Test the restore of the OPV=Version child nodes. + * @throws RepositoryException + */ + public void testRestoreNameJcr2() throws RepositoryException { + // V1.0 of versionableNode has no child + Node child1 = versionableNode.addNode(nodeName4); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + versionableNode.getSession().save(); + // create v1.0 of child + Version v1Child = child1.checkin(); + + // V1 of versionable node has child1 + String v1 = versionManager.checkin(versionableNode.getPath()).getName(); + + // create V1.1 of child + versionManager.checkout(child1.getPath()); + Version v11Child = versionManager.checkin(child1.getPath()); + + // V2 of versionable node has child1 + versionManager.checkout(versionableNode.getPath()); + String v2 = versionManager.checkin(versionableNode.getPath()).getName(); + + // restore 1.0 of versionable node --> no child + versionManager.restore(version, true); + assertFalse("restore must remove child node.", versionableNode.hasNode(nodeName4)); + + // restore V1 via name. since child was checkin first, 1.0 should be restored + versionManager.restore(versionableNode.getPath(), v1, true); + assertTrue("restore must restore child node.", versionableNode.hasNode(nodeName4)); + child1 = versionableNode.getNode(nodeName4); + assertEquals("restore must restore child node version 1.0.", v1Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName()); + + // restore V2 via name. child should be 1.1 + versionManager.restore(versionableNode.getPath(), v2, true); + child1 = versionableNode.getNode(nodeName4); + assertEquals("Node.restore('foo') must restore child node version 1.1.", v11Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName()); + } + + /** * Test the child ordering of restored nodes. * @throws RepositoryException */ @@ -375,7 +970,7 @@ // create a test-root that has orderable child nodes Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); testRoot.addMixin(mixVersionable); - versionableNode.save(); + versionableNode.getSession().save(); // create children of vNode and checkin Node child1 = testRoot.addNode(nodeName1); @@ -386,7 +981,7 @@ if (!child2.isNodeType(mixVersionable)) { child2.addMixin(mixVersionable); } - testRoot.save(); + testRoot.getSession().save(); child1.checkin(); child2.checkin(); Version v1 = testRoot.checkin(); @@ -394,7 +989,7 @@ // remove node 1 testRoot.checkout(); child1.remove(); - testRoot.save(); + testRoot.getSession().save(); testRoot.checkin(); // restore version 1.0 @@ -415,11 +1010,187 @@ * Test the child ordering of restored nodes. * @throws RepositoryException */ + public void testRestoreOrderJcr2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_3() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1.getName(), true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_4() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(new Version[] {v1}, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ public void testRestoreOrder2() throws RepositoryException { // create a test-root that has orderable child nodes Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); testRoot.addMixin(mixVersionable); - versionableNode.save(); + versionableNode.getSession().save(); // create children of vNode and checkin Node child1 = testRoot.addNode(nodeName1); @@ -430,7 +1201,7 @@ if (!child2.isNodeType(mixVersionable)) { child2.addMixin(mixVersionable); } - testRoot.save(); + testRoot.getSession().save(); child1.checkin(); child2.checkin(); Version v1 = testRoot.checkin(); @@ -438,7 +1209,7 @@ // reoder nodes testRoot.checkout(); testRoot.orderBefore(nodeName2, nodeName1); - testRoot.save(); + testRoot.getSession().save(); testRoot.checkin(); // restore version 1.0 @@ -456,6 +1227,182 @@ } /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_3() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_4() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(new Version[] {v1}, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** * Tests if restore on simple versioning creates a new version that is * in the correct linear order. */ @@ -480,4 +1427,108 @@ assertEquals("Node.restore() on simple versioning must create a new version.", expected.toString(), actual.toString()); } + + /** + * Tests if restore on simple versioning creates a new version that is + * in the correct linear order. + */ + public void testLinearVersionsJcr2() throws Exception { + // first get all linear versions + VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer expected = new StringBuffer(); + while (iter.hasNext()) { + expected.append(iter.nextVersion().getName()).append(","); + } + // restore version + versionManager.restore(version, true); + // append new base version + expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(","); + + // get the version names again + iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer actual = new StringBuffer(); + while (iter.hasNext()) { + actual.append(iter.nextVersion().getName()).append(","); + } + assertEquals("Node.restore() on simple versioning must create a new version.", + expected.toString(), actual.toString()); + } + + /** + * Tests if restore on simple versioning creates a new version that is + * in the correct linear order. + */ + public void testLinearVersionsJcr2_2() throws Exception { + // first get all linear versions + VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer expected = new StringBuffer(); + while (iter.hasNext()) { + expected.append(iter.nextVersion().getName()).append(","); + } + // restore version + versionManager.restore(versionableNode.getPath(), version, true); + // append new base version + expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(","); + + // get the version names again + iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer actual = new StringBuffer(); + while (iter.hasNext()) { + actual.append(iter.nextVersion().getName()).append(","); + } + assertEquals("Node.restore() on simple versioning must create a new version.", + expected.toString(), actual.toString()); + } + + /** + * Tests if restore on simple versioning creates a new version that is + * in the correct linear order. + */ + public void testLinearVersionsJcr2_3() throws Exception { + // first get all linear versions + VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer expected = new StringBuffer(); + while (iter.hasNext()) { + expected.append(iter.nextVersion().getName()).append(","); + } + // restore version + versionManager.restore(versionableNode.getPath(), version.getName(), true); + // append new base version + expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(","); + + // get the version names again + iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer actual = new StringBuffer(); + while (iter.hasNext()) { + actual.append(iter.nextVersion().getName()).append(","); + } + assertEquals("Node.restore() on simple versioning must create a new version.", + expected.toString(), actual.toString()); + } + + /** + * Tests if restore on simple versioning creates a new version that is + * in the correct linear order. + */ + public void testLinearVersionsJcr2_4() throws Exception { + // first get all linear versions + VersionIterator iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer expected = new StringBuffer(); + while (iter.hasNext()) { + expected.append(iter.nextVersion().getName()).append(","); + } + // restore version + versionManager.restore(new Version[] {version}, true); + // append new base version + expected.append(versionManager.getBaseVersion(versionableNode.getPath()).getName()).append(","); + + // get the version names again + iter = versionManager.getVersionHistory(versionableNode.getPath()).getAllLinearVersions(); + StringBuffer actual = new StringBuffer(); + while (iter.hasNext()) { + actual.append(iter.nextVersion().getName()).append(","); + } + assertEquals("Node.restore() on simple versioning must create a new version.", + expected.toString(), actual.toString()); + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckinTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckinTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckinTest.java (working copy) @@ -20,6 +20,7 @@ import javax.jcr.RepositoryException; import javax.jcr.UnsupportedRepositoryOperationException; import javax.jcr.version.Version; +import javax.jcr.version.VersionManager; /** * CheckinTest covers tests related to {@link javax.jcr.Node#checkin()} @@ -35,10 +36,35 @@ protected void setUp() throws Exception { super.setUp(); - versionableNode.checkout(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); } /** + * Test if Node.isCheckedOut() return false after calling Node.checkin() + * + * @throws javax.jcr.RepositoryException + */ + public void testIsCheckedOut() throws RepositoryException { + versionableNode.checkin(); + assertTrue("After calling Node.checkin() on a versionable node N, N.isCheckedOut() must return false", versionableNode.isCheckedOut() == false); + } + + /** + * Test if VersionManager.isCheckedOut(P) returns false if P is the + * absolute path of a checked-in versionable node. + * + * @throws javax.jcr.RepositoryException + */ + public void testIsCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + assertTrue("VersionManager.isCheckedOut(P) must return false if the path P resolves to a checked-in node.", versionManager.isCheckedOut(path) == false); + } + + /** * Test if Node.checkin() on a checked-in node has no effect. * * @throws RepositoryException @@ -56,6 +82,26 @@ } /** + * Test if VersionManager.checkin(P) has no effect if the path P resolves + * to a checked-in node. + * + * @throws RepositoryException + */ + public void testMultipleCheckinHasNoEffectJcr2() throws RepositoryException { + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + try { + Version v2 = versionManager.checkin(path); + + assertTrue("Calling VersionManager.checkin(P) must not have an if the path P resolves to a node that is already checked-in.", v.isSame(v2)); + } catch (RepositoryException e) { + fail("Calling VersionManager.checkin(P) must not throw an exception if the path P resolves to a node that is already checked-in."); + } + } + + /** * Test if Node.checkin() throws InvalidItemStateException if the node * has unsaved changes pending. * @@ -74,6 +120,26 @@ } /** + * Test if VersionManager.checkin(P) throws InvalidItemStateException if + * the path P resolves to a node that has unsaved changes pending. + * + * @throws RepositoryException + */ + public void testCheckinWithPendingChangesJcr2() throws RepositoryException { + try { + // modify node without calling save() + versionableNode.setProperty(propertyName1, propertyValue); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + + fail("InvalidItemStateException must be thrown on attempt to checkin a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** * Test if Node.isCheckedOut() returns false after Node.checkin(). * * @throws RepositoryException @@ -86,6 +152,20 @@ } /** + * Test if VersionManager.isCheckedOut(P) returns false after calling VersionManager.checkin(P). + * + * @throws RepositoryException + */ + public void testIsNotCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + boolean isCheckedOut = versionManager.isCheckedOut(path); + + assertFalse("VersionManager.isCheckedOut(P) must return false after VersionManager.checkin(P).", isCheckedOut); + } + + /** * Test if Node.checkin() adds another version to the VersionHistory * * @throws RepositoryException @@ -100,6 +180,22 @@ } /** + * Test if VersionManager.checkin(String) adds another version to the VersionHistory + * + * @throws RepositoryException + */ + public void testCheckinCreatesNewVersionJcr2() throws RepositoryException { + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + long initialNumberOfVersions = getNumberOfVersions(versionManager.getVersionHistory(path)); + versionManager.checkin(path); + long numberOfVersions = getNumberOfVersions(versionManager.getVersionHistory(path)); + + assertTrue("Checkin must create a new Version in the VersionHistory.", numberOfVersions == initialNumberOfVersions + 1); + } + + /** * Test calling Node.checkin() on a non-versionable node. * * @throws RepositoryException @@ -107,9 +203,26 @@ public void testCheckinNonVersionableNode() throws RepositoryException { try { nonVersionableNode.checkin(); - fail("Node.checkin() on a non versionable node must throw UnsupportedRepositoryOperationException"); + fail("Node.checkin() on a non-versionable node must throw UnsupportedRepositoryOperationException"); } catch (UnsupportedRepositoryOperationException e) { //success } } + + /** + * Test calling VersionManager.checkin(P) with the path P resolving to + * a non-versionable node. + * + * @throws RepositoryException + */ + public void testCheckinNonVersionableNodeJcr2() throws RepositoryException { + try { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + versionManager.checkin(path); + fail("VersionManager.checkin(P) must throw UnsupportedRepositoryOperationException if the path P resolves to a non-versionable node."); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckoutTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckoutTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CheckoutTest.java (working copy) @@ -20,6 +20,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.version.VersionManager; /** * SVCheckoutTest covers tests related to {@link @@ -34,68 +35,140 @@ public class CheckoutTest extends AbstractVersionTest { protected void setUp() throws Exception { - super.setUp(); + super.setUp(); - if (!versionableNode.isCheckedOut()) { - fail("A versionable node must be checked-out after persistent creation."); - } - versionableNode.checkin(); - } + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + if (!versionManager.isCheckedOut(path)) { + fail("A versionable node must be checked-out after persistent creation."); + } + if (!versionableNode.isCheckedOut()) { + fail("A versionable node must be checked-out after persistent creation."); + } + versionManager.checkin(path); + } - /** - * Test if Node.isCheckedOut() returns true, if the versionable node has - * been checked out before. - */ - public void testIsCheckedOut() throws RepositoryException { - versionableNode.checkout(); - assertTrue("After calling Node.checkout() a versionable node N, N.isCheckedOut() must return true.", versionableNode.isCheckedOut()); - } + /** + * Test if Node.isCheckedOut() returns true, if the versionable node has + * been checked out before. + */ + public void testIsCheckedOut() throws RepositoryException { + versionableNode.checkout(); + assertTrue("After calling Node.checkout() a versionable node N, N.isCheckedOut() must return true.", versionableNode.isCheckedOut()); + } - /** - * Test calling Node.isCheckedOut() on a non-versionable. - */ - public void testIsCheckedOutNonVersionableNode() throws RepositoryException { - boolean isCheckedOut = nonVersionableNode.isCheckedOut(); - Node vParent = null; - try { - vParent = nonVersionableNode.getParent(); - while (!vParent.isNodeType(mixVersionable)) { - vParent = vParent.getParent(); - } - } catch (ItemNotFoundException e) { - // root reached. - } + /** + * Test if VersionManager.isCheckedOut(P) returns true if P is the + * absolute path of a versionable node that has been checked out before. + */ + public void testIsCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); + assertTrue("After successfully calling VersionManager.checkout(P) with P denoting the absolute path of a versionable node, VersionManager.isCheckedOut(P) must return true.", versionManager.isCheckedOut(path)); + } - if (vParent != null && vParent.isNodeType(mixVersionable)) { - if (vParent.isCheckedOut()) { - assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and its nearest versionable ancestor is checked-out.", isCheckedOut); - } else { - assertFalse("Node.isCheckedOut() must return false if the node is non-versionable and its nearest versionable ancestor is checked-in.", isCheckedOut); - } - } else { - assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and has no versionable ancestor", isCheckedOut); - } - } + /** + * Test calling Node.isCheckedOut() on a non-versionable. + */ + public void testIsCheckedOutNonVersionableNode() throws RepositoryException { + boolean isCheckedOut = nonVersionableNode.isCheckedOut(); + Node vParent = null; + try { + vParent = nonVersionableNode.getParent(); + while (!vParent.isNodeType(mixVersionable)) { + vParent = vParent.getParent(); + } + } catch (ItemNotFoundException e) { + // root reached. + } - /** - * Test calling Node.checkout() on a non-versionable node. - */ - public void testCheckoutNonVersionableNode() throws RepositoryException { - try { - nonVersionableNode.checkout(); - fail("Node.checkout() on a non versionable node must throw UnsupportedRepositoryOperationException"); - } catch (UnsupportedRepositoryOperationException e) { - //success - } - } + if (vParent != null && vParent.isNodeType(mixVersionable)) { + if (vParent.isCheckedOut()) { + assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and its nearest versionable ancestor is checked-out.", isCheckedOut); + } else { + assertFalse("Node.isCheckedOut() must return false if the node is non-versionable and its nearest versionable ancestor is checked-in.", isCheckedOut); + } + } else { + assertTrue("Node.isCheckedOut() must return true if the node is non-versionable and has no versionable ancestor", isCheckedOut); + } + } - /** - * Test if Node.checkout() doesn't throw any exception if the versionable - * node has been checked out before. - */ - public void testCheckoutTwiceDoesNotThrow() throws RepositoryException { - versionableNode.checkout(); - versionableNode.checkout(); - } + /** + * Test calling VersionManager.isCheckedOut(P) with P denoting the + * absolute path of a non-versionable node. + */ + public void testIsCheckedOutNonVersionableNodeJcr2() throws RepositoryException { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + boolean isCheckedOut = versionManager.isCheckedOut(path); + Node vParent = null; + try { + vParent = nonVersionableNode.getParent(); + while (!vParent.isNodeType(mixVersionable)) { + vParent = vParent.getParent(); + } + } catch (ItemNotFoundException e) { + // root reached. + } + if (vParent != null && vParent.isNodeType(mixVersionable)) { + String parentPath = vParent.getPath(); + if (versionManager.isCheckedOut(parentPath)) { + assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-out.", isCheckedOut); + } else { + assertFalse("VersionManager.isCheckedOut(P) must return false if P denotes the absolute path of a non-versionable node whose nearest versionable ancestor is checked-in.", isCheckedOut); + } + } else { + assertTrue("VersionManager.isCheckedOut(P) must return true if P denotes the absolute path of a non-versionable node that has no versionable ancestor", isCheckedOut); + } + } + + /** + * Test calling Node.checkout() on a non-versionable node. + */ + public void testCheckoutNonVersionableNode() throws RepositoryException { + try { + nonVersionableNode.checkout(); + fail("Node.checkout() on a non-versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test calling VersionManager.checkout(P) with P denoting the absolute + * path of a non-versionable node. + */ + public void testCheckoutNonVersionableNodeJcr2() throws RepositoryException { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + try { + versionManager.checkout(path); + fail("VersionManager.checkout(P) with P denoting the absolute path of a non-versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test if Node.checkout() doesn't throw any exception if the versionable + * node has been checked out before. + */ + public void testCheckoutTwiceDoesNotThrow() throws RepositoryException { + versionableNode.checkout(); + versionableNode.checkout(); + } + + /** + * Test if VersionManager.checkout(P) doesn't throw any exception if P + * denotes the absolute path of a versionable node that has been checked + * out before. + */ + public void testCheckoutTwiceDoesNotThrowJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); + versionManager.checkout(path); + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/AbstractVersionTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/AbstractVersionTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/AbstractVersionTest.java (working copy) @@ -83,7 +83,7 @@ } try { nonVersionableNode = testRootNode.addNode(nodeName3, nonVersionableNodeType.getName()); - testRootNode.save(); + testRootNode.getSession().save(); } catch (RepositoryException e) { fail("Failed to create non-versionable test node." + e.getMessage()); } @@ -98,7 +98,7 @@ // remove versionable nodes try { versionableNode.remove(); - testRootNode.save(); + testRootNode.getSession().save(); } catch (Exception e) { log.println("Exception in tearDown: " + e.toString()); } finally { @@ -137,7 +137,7 @@ if (!nodetype.isNodeType(mixSimpleVersionable)) { versionableNode.addMixin(mixSimpleVersionable); } - parent.save(); + parent.getSession().save(); return versionableNode; } Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/FrozenNodeTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/FrozenNodeTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/FrozenNodeTest.java (working copy) @@ -19,6 +19,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.version.Version; +import javax.jcr.version.VersionManager; /** * SVFrozenNodeTest covers tests related to frozen nodes in @@ -34,18 +35,22 @@ protected void setUp() throws Exception { super.setUp(); - versionableNode.checkout(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); } /** * @throws RepositoryException */ public void testFrozenNodeUUUID() throws RepositoryException { - Version v = versionableNode.checkin(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrUUID).getValue().getString(); - String nuuid = n.getUUID(); - assertEquals("jcr:uuid needs to be equal to the getUUID() return value.", nuuid, puuid); + String nuuid = n.getIdentifier(); + assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); } /** @@ -53,12 +58,14 @@ */ public void testFrozenChildNodeUUUID() throws RepositoryException { versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrUUID).getValue().getString(); - String nuuid = n.getUUID(); - assertEquals("jcr:uuid needs to be equal to the getUUID() return value.", nuuid, puuid); + String nuuid = n.getIdentifier(); + assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid); } /** @@ -67,12 +74,14 @@ public void testFrozenUUUID() throws RepositoryException { // make versionable node referenceable versionableNode.addMixin(mixReferenceable); - versionableNode.save(); - Version v = versionableNode.checkin(); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String fuuid = n.getProperty(jcrFrozenUuid).getValue().getString(); - String ruuid = versionableNode.getUUID(); - assertEquals("jcr:frozenUuid needs to be equal to the getUUID() return value.", ruuid, fuuid); + String ruuid = versionableNode.getIdentifier(); + assertEquals("jcr:frozenUuid needs to be equal to the getIdentifier() return value.", ruuid, fuuid); } /** @@ -81,12 +90,14 @@ public void testFrozenChildUUUID() throws RepositoryException { Node n1 = versionableNode.addNode("child"); n1.addMixin(mixReferenceable); - versionableNode.save(); - Version v = versionableNode.checkin(); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String fuuid = n.getProperty(jcrFrozenUuid).getValue().getString(); - String ruuid = n1.getUUID(); - assertEquals("jcr:frozenUuid needs to be equal to the getUUID() return value.", ruuid, fuuid); + String ruuid = n1.getIdentifier(); + assertEquals("jcr:frozenUuid needs to be equal to the getIdentifier() return value.", ruuid, fuuid); } @@ -94,7 +105,9 @@ * @throws RepositoryException */ public void testFrozenNodeNodeType() throws RepositoryException { - Version v = versionableNode.checkin(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); @@ -106,8 +119,10 @@ */ public void testFrozenChildNodeNodeType() throws RepositoryException { versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String puuid = n.getProperty(jcrPrimaryType).getValue().getString(); String nuuid = n.getPrimaryNodeType().getName(); @@ -118,7 +133,9 @@ * @throws RepositoryException */ public void testFrozenNodeType() throws RepositoryException { - Version v = versionableNode.checkin(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode(); String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString(); String ruuid = versionableNode.getPrimaryNodeType().getName(); @@ -130,8 +147,10 @@ */ public void testFrozenChildNodeType() throws RepositoryException { Node n1 = versionableNode.addNode("child"); - versionableNode.save(); - Version v = versionableNode.checkin(); + versionableNode.getSession().save(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); Node n = v.getFrozenNode().getNode("child"); String fuuid = n.getProperty("jcr:frozenPrimaryType").getValue().getString(); String ruuid = n1.getPrimaryNodeType().getName(); Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CopyTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CopyTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/simple/CopyTest.java (working copy) @@ -49,7 +49,7 @@ try { String dstPath = getProperty("destination"); superuser.getNode(dstPath).remove(); - testRootNode.save(); + testRootNode.getSession().save(); } catch (Exception e) { log.println("Exception in tearDown: " + e.toString()); } finally { Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/RestoreTest.java (working copy) @@ -19,10 +19,7 @@ import org.apache.jackrabbit.test.NotExecutableException; import javax.jcr.nodetype.NodeDefinition; -import javax.jcr.version.Version; -import javax.jcr.version.VersionException; -import javax.jcr.version.OnParentVersionAction; -import javax.jcr.version.VersionIterator; +import javax.jcr.version.*; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.InvalidItemStateException; @@ -46,21 +43,33 @@ */ public class RestoreTest extends AbstractVersionTest { + VersionManager versionManager; + Version version; Version version2; Version rootVersion; Node versionableNode2; + String propertyValue1; + String propertyValue2; + protected void setUp() throws Exception { super.setUp(); + versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + propertyValue1 = getProperty("propertyValue1"); + propertyValue2 = getProperty("propertyValue2"); + versionableNode.setProperty(propertyName1, propertyValue1); + versionableNode.getSession().save(); + version = versionManager.checkin(path); + versionManager.checkout(path); + versionableNode.setProperty(propertyName1, propertyValue2); + versionableNode.getSession().save(); + version2 = versionManager.checkin(path); + versionManager.checkout(path); + rootVersion = versionManager.getVersionHistory(path).getRootVersion(); - version = versionableNode.checkin(); - versionableNode.checkout(); - version2 = versionableNode.checkin(); - versionableNode.checkout(); - rootVersion = versionableNode.getVersionHistory().getRootVersion(); - // build a second versionable node below the testroot try { versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType); @@ -72,7 +81,7 @@ protected void tearDown() throws Exception { try { versionableNode2.remove(); - testRootNode.save(); + testRootNode.getSession().save(); } finally { version = null; version2 = null; @@ -97,6 +106,20 @@ } /** + * Test if restoring the root version fails. + * + * @throws RepositoryException + */ + public void testRestoreRootVersionFailJcr2() throws RepositoryException { + try { + versionManager.restore(rootVersion, true); + fail("Restore of jcr:rootVersion must throw VersionException."); + } catch (VersionException e) { + // success + } + } + + /** * Test if restoring a node works on checked-in node. * * @throws RepositoryException @@ -107,6 +130,46 @@ } /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_1() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(version, true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_2() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(versionableNode.getPath(), version, true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_3() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(versionableNode.getPath(), version.getName(), true); + } + + /** + * Test if restoring a node works on checked-in node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedInNodeJcr2_4() throws RepositoryException { + versionManager.checkin(versionableNode.getPath()); + versionManager.restore(new Version[] {version}, true); + } + + /** * Test if restoring a node works on checked-out node. * * @throws RepositoryException @@ -116,17 +179,147 @@ } /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2() throws RepositoryException { + versionManager.restore(version, true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + } + + /** + * Test if restoring a node works on checked-out node. + * + * @throws RepositoryException + */ + public void testRestoreOnCheckedOutNodeJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + } + + /** * Restoring a node set the jcr:isCheckedOut property to false. * * @throws RepositoryException */ public void testRestoreSetsIsCheckedOutToFalse() throws RepositoryException { versionableNode.restore(version, true); - assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionableNode.isCheckedOut()); } /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2() throws RepositoryException { + versionManager.restore(version, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Restoring a node set the jcr:isCheckedOut property to false. + * + * @throws RepositoryException + */ + public void testRestoreSetsIsCheckedOutToFalseJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + assertFalse("Restoring a node sets the jcr:isCheckedOut property to false", versionManager.isCheckedOut(versionableNode.getPath())); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectProperty() throws RepositoryException { + versionableNode.restore(version, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2() throws RepositoryException { + versionManager.restore(version, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** + * Test if restoring a node restores the correct property + * + * @throws RepositoryException + */ + public void testRestoreCorrectPropertyJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Restoring a node must set the correct property.", propertyValue1, value); + } + + /** * Test if restoring a node sets the jcr:baseVersion property correctly. * * @throws javax.jcr.RepositoryException @@ -138,6 +331,50 @@ } /** + * Test if restoring a node sets the jcr:baseVersion property correctly. + * + * @throws javax.jcr.RepositoryException + */ + public void testRestoreSetsBaseVersionJcr2() throws RepositoryException { + versionManager.restore(version, true); + Version baseV = versionManager.getBaseVersion(versionableNode.getPath()); + assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV)); + } + + /** + * Test if restoring a node sets the jcr:baseVersion property correctly. + * + * @throws javax.jcr.RepositoryException + */ + public void testRestoreSetsBaseVersionJcr2_2() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version, true); + Version baseV = versionManager.getBaseVersion(versionableNode.getPath()); + assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV)); + } + + /** + * Test if restoring a node sets the jcr:baseVersion property correctly. + * + * @throws javax.jcr.RepositoryException + */ + public void testRestoreSetsBaseVersionJcr2_3() throws RepositoryException { + versionManager.restore(versionableNode.getPath(), version.getName(), true); + Version baseV = versionManager.getBaseVersion(versionableNode.getPath()); + assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV)); + } + + /** + * Test if restoring a node sets the jcr:baseVersion property correctly. + * + * @throws javax.jcr.RepositoryException + */ + public void testRestoreSetsBaseVersionJcr2_4() throws RepositoryException { + versionManager.restore(new Version[] {version}, true); + Version baseV = versionManager.getBaseVersion(versionableNode.getPath()); + assertTrue("Restoring a node must set node's base version in order to point to the restored version.", version.isSame(baseV)); + } + + /** * Test if InvalidItemStateException is thrown if the node has pending changes. * * @throws RepositoryException @@ -155,6 +392,74 @@ } /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(version, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_2() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(versionableNode.getPath(), version, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_3() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(versionableNode.getPath(), version.getName(), true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** + * Test if InvalidItemStateException is thrown if the node has pending changes. + * + * @throws RepositoryException + */ + public void testRestoreWithPendingChangesJcr2_4() throws RepositoryException { + // modify node without calling save() + try { + versionableNode.setProperty(propertyName1, propertyValue); + versionManager.restore(new Version[] {version}, true); + + fail("InvalidItemStateException must be thrown on attempt to restore a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** * VersionException expected on Node.restore(Version, boolean) if the * specified version is not part of this node's version history. * @@ -172,6 +477,23 @@ } /** + * VersionException expected on Node.restore(Version, boolean) if the + * specified version is not part of this node's version history. + * + * @throws RepositoryException + */ + public void testRestoreInvalidVersionJcr2() throws RepositoryException { + Version vNode2 = versionManager.checkin(versionableNode2.getPath()); + try { + versionManager.restore(versionableNode.getPath(), vNode2, true); + + fail("VersionException expected on Node.restore(Version, boolean) if the specified version is not part of this node's version history."); + } catch (VersionException e) { + // ok + } + } + + /** * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history. * * @throws RepositoryException @@ -198,9 +520,35 @@ } /** + * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history. + * + * @throws RepositoryException + */ + public void testRestoreInvalidVersion2Jcr2() throws RepositoryException { + String invalidName; + do { + invalidName = createRandomString(3); + for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext();) { + Version v = it.nextVersion(); + if (invalidName.equals(v.getName())) { + invalidName = null; + break; + } + } + } while (invalidName == null); + + try { + versionManager.restore(versionableNode.getPath(), invalidName, true); + fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history."); + } catch (VersionException e) { + // ok + } + } + + /** * Test calling Node.restore(String, boolean) on a non-versionable node. * - * @throws javax.jcr.RepositoryException + * @throws RepositoryException * @see Node#restore(String, boolean) */ public void testRestoreNonVersionableNode() throws RepositoryException { @@ -213,10 +561,40 @@ } /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(String, boolean) + */ + public void testRestoreNonVersionableNodeJcr2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version, true); + fail("trying to restore on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(String, boolean) + */ + public void testRestoreNonVersionableNodeJcr2_2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), "foo", true); + fail("trying to restore on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** * Test calling Node.restore(Version, String, boolean) on a non-versionable node. * - * @throws javax.jcr.RepositoryException - * @see Node#restore(javax.jcr.version.Version, String, boolean) + * @throws RepositoryException + * @see Node#restore(Version, String, boolean) */ public void testRestoreNonVersionableNode2() throws RepositoryException { // the 'version' will be restored at location 'foo'. @@ -232,7 +610,7 @@ /** * Test calling Node.restore(Version, boolean) on a non-versionable node. * - * @throws javax.jcr.RepositoryException + * @throws RepositoryException * @see Node#restore(Version, boolean) */ public void testRestoreNonVersionableNode3() throws RepositoryException { @@ -245,6 +623,36 @@ } /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(Version, boolean) + */ + public void testRestoreNonVersionableNode3Jcr2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version, true); + fail("Node.restore(Version, boolean) on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** + * Test restoring on a non-versionable node. + * + * @throws RepositoryException + * @see Node#restore(Version, boolean) + */ + public void testRestoreNonVersionableNode3Jcr2_2() throws RepositoryException { + try { + versionManager.restore(nonVersionableNode.getPath(), version.getName(), true); + fail("Node.restore(Version, boolean) on a non versionable node must throw UnsupportedRepositoryOperationException"); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } + + /** * Test if restoring a node with an invalid Version throws a VersionException * * @throws RepositoryException @@ -260,6 +668,21 @@ } /** + * Test if restoring a node with an invalid Version throws a VersionException + * + * @throws RepositoryException + */ + public void testRestoreWithInvalidVersionJcr2() throws RepositoryException { + Version invalidVersion = versionManager.checkin(versionableNode2.getPath()); + try { + versionManager.restore(versionableNode.getPath(), invalidVersion, true); + fail("Node.restore(Version, boolean): A VersionException must be thrown if the specified version does not exists in this node's version history."); + } catch (VersionException e) { + // success + } + } + + /** * Tests if restoring the Version of an existing node throws an * ItemExistsException if removeExisting is set to FALSE. */ @@ -284,9 +707,109 @@ } } + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(v, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_2() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(versionableNode.getPath(), v, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_3() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(versionableNode.getPath(), v.getName(), false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + + /** + * Tests if restoring the Version of an existing node throws an + * ItemExistsException if removeExisting is set to FALSE. + */ + public void testRestoreWithUUIDConflictJcr2_4() throws RepositoryException, NotExecutableException { + try { + Node naa = createVersionableNode(versionableNode, nodeName4, versionableNodeType); + // Verify that nodes used for the test have proper opv behaviour + NodeDefinition nd = naa.getDefinition(); + if (nd.getOnParentVersion() != OnParentVersionAction.COPY && nd.getOnParentVersion() != OnParentVersionAction.VERSION) { + throw new NotExecutableException("Child nodes must have OPV COPY or VERSION in order to be able to test Node.restore with uuid conflict."); + } + + Version v = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + superuser.move(naa.getPath(), versionableNode2.getPath() + "/" + naa.getName()); + superuser.save(); + versionManager.restore(new Version[] {v}, false); + + fail("Node.restore( Version, boolean ): An ItemExistsException must be thrown if the node to be restored already exsits and removeExisting was set to false."); + } catch (ItemExistsException e) { + // success + } + } + public void testRestoreChild1() throws RepositoryException { versionableNode.addNode("child1"); - versionableNode.save(); + versionableNode.getSession().save(); Version v1 = versionableNode.checkin(); versionableNode.checkout(); Version v2 = versionableNode.checkin(); @@ -304,29 +827,115 @@ } } + public void testRestoreChild1Jcr2() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(v1, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(version, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(v2, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_2() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(versionableNode.getPath(), v1, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(versionableNode.getPath(), version, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(versionableNode.getPath(), v2, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_3() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(versionableNode.getPath(), v1.getName(), true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(versionableNode.getPath(), version.getName(), true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(versionableNode.getPath(), v2.getName(), true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + + public void testRestoreChild1Jcr2_4() throws RepositoryException { + versionableNode.addNode("child1"); + versionableNode.getSession().save(); + Version v1 = versionManager.checkin(versionableNode.getPath()); + versionManager.checkout(versionableNode.getPath()); + Version v2 = versionManager.checkin(versionableNode.getPath()); + + versionManager.restore(new Version[] {v1}, true); + assertTrue("Node.restore('1.2') must not remove child node.", versionableNode.hasNode("child1")); + + versionManager.restore(new Version[] {version}, true); + assertFalse("Node.restore('1.0') must remove child node.", versionableNode.hasNode("child1")); + + try { + versionManager.restore(new Version[] {v2}, true); + } catch (RepositoryException e) { + fail("Node.restore('1.3') must fail."); + } + } + /** * Test the restore of a versionable node using a label. * @throws RepositoryException */ public void testRestoreLabel() throws RepositoryException { - // V1 of versionable node - Version v1 = versionableNode.checkin(); - String v1Name = v1.getName(); - // mark V1 with label test1 - versionableNode.getVersionHistory().addVersionLabel(v1Name, "test", true); + versionableNode.getVersionHistory().addVersionLabel(version.getName(), "test", true); - // create a new version - versionableNode.checkout(); - Version v2 = versionableNode.checkin(); - // restore V1 via label. versionableNode.restoreByLabel("test", true); - assertEquals("Node.restore('test') not correctly restored", - v1Name, versionableNode.getBaseVersion().getName()); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Node.restore('test') not correctly restored", propertyValue1, value); } /** + * Test the restore of a versionable node using a label. + * @throws RepositoryException + */ + public void testRestoreLabelJcr2() throws RepositoryException { + // mark V1 with label test1 + versionManager.getVersionHistory(versionableNode.getPath()).addVersionLabel(version.getName(), "test", true); + + // restore V1 via label. + versionManager.restoreByLabel(versionableNode.getPath(), "test", true); + String value = versionableNode.getProperty(propertyName1).getString(); + assertEquals("Node.restore('test') not correctly restored", propertyValue1, value); + } + + /** * Test the restore of the OPV=Version child nodes. * @throws RepositoryException */ @@ -336,7 +945,7 @@ if (!child1.isNodeType(mixVersionable)) { child1.addMixin(mixVersionable); } - versionableNode.save(); + versionableNode.getSession().save(); // create v1.0 of child Version v1Child = child1.checkin(); @@ -368,6 +977,47 @@ } /** + * Test the restore of the OPV=Version child nodes. + * @throws RepositoryException + */ + public void testRestoreNameJcr2() throws RepositoryException { + // V1.0 of versionableNode has no child + Node child1 = versionableNode.addNode(nodeName4); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + versionableNode.getSession().save(); + // create v1.0 of child + Version v1Child = child1.checkin(); + + // V1 of versionable node has child1 + String v1 = versionManager.checkin(versionableNode.getPath()).getName(); + + // create V1.1 of child + versionManager.checkout(child1.getPath()); + Version v11Child = versionManager.checkin(child1.getPath()); + + // V2 of versionable node has child1 + versionManager.checkout(versionableNode.getPath()); + String v2 = versionManager.checkin(versionableNode.getPath()).getName(); + + // restore 1.0 of versionable node --> no child + versionManager.restore(version, true); + assertFalse("restore must remove child node.", versionableNode.hasNode(nodeName4)); + + // restore V1 via name. since child was checkin first, 1.0 should be restored + versionManager.restore(versionableNode.getPath(), v1, true); + assertTrue("restore must restore child node.", versionableNode.hasNode(nodeName4)); + child1 = versionableNode.getNode(nodeName4); + assertEquals("restore must restore child node version 1.0.", v1Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName()); + + // restore V2 via name. child should be 1.1 + versionManager.restore(versionableNode.getPath(), v2, true); + child1 = versionableNode.getNode(nodeName4); + assertEquals("Node.restore('foo') must restore child node version 1.1.", v11Child.getName(), versionManager.getBaseVersion(child1.getPath()).getName()); + } + + /** * Test the child ordering of restored nodes. * @throws RepositoryException */ @@ -375,7 +1025,7 @@ // create a test-root that has orderable child nodes Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); testRoot.addMixin(mixVersionable); - versionableNode.save(); + versionableNode.getSession().save(); // create children of vNode and checkin Node child1 = testRoot.addNode(nodeName1); @@ -386,7 +1036,7 @@ if (!child2.isNodeType(mixVersionable)) { child2.addMixin(mixVersionable); } - testRoot.save(); + testRoot.getSession().save(); child1.checkin(); child2.checkin(); Version v1 = testRoot.checkin(); @@ -394,7 +1044,7 @@ // remove node 1 testRoot.checkout(); child1.remove(); - testRoot.save(); + testRoot.getSession().save(); testRoot.checkin(); // restore version 1.0 @@ -415,11 +1065,187 @@ * Test the child ordering of restored nodes. * @throws RepositoryException */ + public void testRestoreOrderJcr2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_3() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1.getName(), true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrderJcr2_4() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // remove node 1 + versionManager.checkout(testRoot.getPath()); + child1.remove(); + testRoot.getSession().save(); + versionManager.checkout(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(new Version[] {v1}, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ public void testRestoreOrder2() throws RepositoryException { // create a test-root that has orderable child nodes Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); testRoot.addMixin(mixVersionable); - versionableNode.save(); + versionableNode.getSession().save(); // create children of vNode and checkin Node child1 = testRoot.addNode(nodeName1); @@ -430,7 +1256,7 @@ if (!child2.isNodeType(mixVersionable)) { child2.addMixin(mixVersionable); } - testRoot.save(); + testRoot.getSession().save(); child1.checkin(); child2.checkin(); Version v1 = testRoot.checkin(); @@ -438,7 +1264,7 @@ // reoder nodes testRoot.checkout(); testRoot.orderBefore(nodeName2, nodeName1); - testRoot.save(); + testRoot.getSession().save(); testRoot.checkin(); // restore version 1.0 @@ -455,4 +1281,179 @@ assertEquals("Invalid child node ordering", orderOk, order); } + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_2() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_3() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(testRoot.getPath(), v1, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } + + /** + * Test the child ordering of restored nodes. + * @throws RepositoryException + */ + public void testRestoreOrder2Jcr2_4() throws RepositoryException { + // create a test-root that has orderable child nodes + Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured"); + testRoot.addMixin(mixVersionable); + versionableNode.getSession().save(); + + // create children of vNode and checkin + Node child1 = testRoot.addNode(nodeName1); + if (!child1.isNodeType(mixVersionable)) { + child1.addMixin(mixVersionable); + } + Node child2 = testRoot.addNode(nodeName2); + if (!child2.isNodeType(mixVersionable)) { + child2.addMixin(mixVersionable); + } + testRoot.getSession().save(); + versionManager.checkin(child1.getPath()); + versionManager.checkin(child2.getPath()); + Version v1 = versionManager.checkin(testRoot.getPath()); + + // reoder nodes + versionManager.checkout(testRoot.getPath()); + testRoot.orderBefore(nodeName2, nodeName1); + testRoot.getSession().save(); + versionManager.checkin(testRoot.getPath()); + + // restore version 1.0 + versionManager.restore(new Version[] {v1}, true); + + // check order + NodeIterator iter = testRoot.getNodes(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n1 = iter.nextNode(); + assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext()); + Node n2 = iter.nextNode(); + String orderOk = nodeName1 + ", " + nodeName2; + String order = n1.getName() + ", " + n2.getName(); + assertEquals("Invalid child node ordering", orderOk, order); + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckinTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckinTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/CheckinTest.java (working copy) @@ -17,6 +17,7 @@ package org.apache.jackrabbit.test.api.version; import javax.jcr.version.Version; +import javax.jcr.version.VersionManager; import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.InvalidItemStateException; @@ -36,7 +37,9 @@ protected void setUp() throws Exception { super.setUp(); - versionableNode.checkout(); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkout(path); } /** @@ -50,6 +53,19 @@ } /** + * Test if VersionManager.isCheckedOut(P) returns false if P is the + * absolute path of a checked-in versionable node. + * + * @throws javax.jcr.RepositoryException + */ + public void testIsCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + assertTrue("VersionManager.isCheckedOut(P) must return false if the path P resolves to a checked-in node.", versionManager.isCheckedOut(path) == false); + } + + /** * Test if the node's jcr:predecessors property contains an empty value array * after checkin. * @@ -64,6 +80,22 @@ } /** + * Test if the node's jcr:predecessors property contains an empty value array + * after checkin. + * + * @throws RepositoryException + */ + public void testCheckinRemovesPredecessorPropertyJcr2() throws RepositoryException { + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + Value[] predecessorsValue = versionableNode.getProperty(jcrPredecessors).getValues(); + + assertTrue("Checkin must set the node's jcr:predecessors property to the empty array", predecessorsValue.length == 0); + } + + /** * Test if the nodes jcr:predecessors property is copied to the new version * on Node.checkin(). * @@ -80,6 +112,24 @@ } /** + * Test if the nodes jcr:predecessors property is copied to the new version + * on checkin. + * + * @throws RepositoryException + */ + public void testPredecessorIsCopiedToNewVersionJcr2() throws RepositoryException { + + Value[] nPredecessorsValue = versionableNode.getProperty(jcrPredecessors).getValues(); + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Value[] vPredecessorsValue = v.getProperty(jcrPredecessors).getValues(); + + assertEquals("The versionable checked-out node's jcr:predecessors property is copied to the new version on checkin.", Arrays.asList(nPredecessorsValue), Arrays.asList(vPredecessorsValue)); + } + + /** * Test if Node.checkin() on a checked-in node has no effect. * * @throws RepositoryException @@ -97,6 +147,26 @@ } /** + * Test if VersionManager.checkin(P) has no effect if the path P resolves + * to a checked-in node. + * + * @throws RepositoryException + */ + public void testMultipleCheckinHasNoEffectJcr2() throws RepositoryException { + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + try { + Version v2 = versionManager.checkin(path); + + assertTrue("Calling VersionManager.checkin(P) must not have an if the path P resolves to a node that is already checked-in.", v.isSame(v2)); + } catch (RepositoryException e) { + fail("Calling VersionManager.checkin(P) must not throw an exception if the path P resolves to a node that is already checked-in."); + } + } + + /** * Test if versionable node N's jcr:baseVersion property is set to refer to * the new version after checkin. * @@ -110,6 +180,21 @@ } /** + * Test if versionable node N's jcr:baseVersion property is set to refer to + * the new version after checkin. + * + * @throws RepositoryException + */ + public void testBaseVersionAfterCheckinJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + Version v = versionManager.checkin(path); + Value baseVersionRef = versionableNode.getProperty(jcrBaseVersion).getValue(); + + assertEquals("Checked-in node's jcr:baseVersion property is set to refer to the version created on checkin.", superuser.getValueFactory().createValue(v), baseVersionRef); + } + + /** * Test if Node.checkin() throws InvalidItemStateException if the node * has unsaved changes pending. * @@ -128,6 +213,26 @@ } /** + * Test if VersionManager.checkin(P) throws InvalidItemStateException if + * the path P resolves to a node that has unsaved changes pending. + * + * @throws RepositoryException + */ + public void testCheckinWithPendingChangesJcr2() throws RepositoryException { + try { + // modify node without calling save() + versionableNode.setProperty(propertyName1, propertyValue); + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + + fail("InvalidItemStateException must be thrown on attempt to checkin a node having any unsaved changes pending."); + } catch (InvalidItemStateException e) { + // ok + } + } + + /** * Test if Node.isCheckedOut() returns false after Node.checkin(). * * @throws RepositoryException @@ -140,6 +245,20 @@ } /** + * Test if VersionManager.isCheckedOut(P) returns false after calling VersionManager.checkin(P). + * + * @throws RepositoryException + */ + public void testIsNotCheckedOutJcr2() throws RepositoryException { + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + versionManager.checkin(path); + boolean isCheckedOut = versionManager.isCheckedOut(path); + + assertFalse("VersionManager.isCheckedOut(P) must return false after VersionManager.checkin(P).", isCheckedOut); + } + + /** * Test if Node.checkin() adds another version to the VersionHistory * * @throws RepositoryException @@ -154,6 +273,22 @@ } /** + * Test if VersionManager.checkin(String) adds another version to the VersionHistory + * + * @throws RepositoryException + */ + public void testCheckinCreatesNewVersionJcr2() throws RepositoryException { + + VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager(); + String path = versionableNode.getPath(); + long initialNumberOfVersions = getNumberOfVersions(versionManager.getVersionHistory(path)); + versionManager.checkin(path); + long numberOfVersions = getNumberOfVersions(versionManager.getVersionHistory(path)); + + assertTrue("Checkin must create a new Version in the VersionHistory.", numberOfVersions == initialNumberOfVersions + 1); + } + + /** * Test calling Node.checkin() on a non-versionable node. * * @throws RepositoryException @@ -166,4 +301,21 @@ //success } } + + /** + * Test calling VersionManager.checkin(P) with the path P resolving to + * a non-versionable node. + * + * @throws RepositoryException + */ + public void testCheckinNonVersionableNodeJcr2() throws RepositoryException { + try { + VersionManager versionManager = nonVersionableNode.getSession().getWorkspace().getVersionManager(); + String path = nonVersionableNode.getPath(); + versionManager.checkin(path); + fail("VersionManager.checkin(P) must throw UnsupportedRepositoryOperationException if the path P resolves to a non-versionable node."); + } catch (UnsupportedRepositoryOperationException e) { + //success + } + } } \ No newline at end of file Index: jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java =================================================================== --- jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java (revision 775183) +++ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/version/AbstractVersionTest.java (working copy) @@ -83,7 +83,7 @@ } try { nonVersionableNode = testRootNode.addNode(nodeName3, nonVersionableNodeType.getName()); - testRootNode.save(); + testRootNode.getSession().save(); } catch (RepositoryException e) { fail("Failed to create non-versionable test node." + e.getMessage()); } @@ -98,7 +98,7 @@ // remove versionable nodes try { versionableNode.remove(); - testRootNode.save(); + testRootNode.getSession().save(); } catch (Exception e) { log.println("Exception in tearDown: " + e.toString()); } finally {