You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/02/15 16:37:32 UTC
svn commit: r153939 - in
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version:
CheckoutTest.java VersionLabelTest.java
Author: mreutegg
Date: Tue Feb 15 07:37:30 2005
New Revision: 153939
URL: http://svn.apache.org/viewcvs?view=rev&rev=153939
Log:
Added more versioning test cases.
Modified:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/CheckoutTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/VersionLabelTest.java
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/CheckoutTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/CheckoutTest.java?view=diff&r1=153938&r2=153939
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/CheckoutTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/CheckoutTest.java Tue Feb 15 07:37:30 2005
@@ -20,10 +20,13 @@
import javax.jcr.Node;
import javax.jcr.ItemNotFoundException;
import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Property;
/**
- * <code>CheckoutTest</code> covers tests related to {@link javax.jcr.Node#checkout()}
- * and {@link javax.jcr.Node#isCheckedOut()}.
+ * <code>CheckoutTest</code> covers tests related to {@link
+ * javax.jcr.Node#checkout()} and {@link javax.jcr.Node#isCheckedOut()}.
*
* @test
* @sources CheckoutTest.java
@@ -34,7 +37,7 @@
protected void setUp() throws Exception {
super.setUp();
-
+
if (!versionableNode.isCheckedOut()) {
fail("A versionable node must be checked-out after persistent creation.");
}
@@ -44,8 +47,6 @@
/**
* Test if Node.isCheckedOut() returns true, if the versionable node has
* been checked out before.
- *
- * @throws javax.jcr.RepositoryException
*/
public void testIsCheckedOut() throws RepositoryException {
versionableNode.checkout();
@@ -54,8 +55,6 @@
/**
* Test calling Node.isCheckedOut() on a non-versionable.
- *
- * @throws RepositoryException
*/
public void testIsCheckedOutNonVersionableNode() throws RepositoryException {
boolean isCheckedOut = nonVersionableNode.isCheckedOut();
@@ -71,9 +70,9 @@
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);
+ 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);
+ 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);
@@ -82,8 +81,6 @@
/**
* Test calling Node.checkout() on a non-versionable node.
- *
- * @throws RepositoryException
*/
public void testCheckoutNonVersionableNode() throws RepositoryException {
try {
@@ -91,6 +88,90 @@
fail("Node.checkout() on 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 Node.checkout() has no effect if the versionable node has been
+ * checked out before.
+ * <p/>
+ * As 'has no effect' means that the whole repository is in the exact same
+ * state as before and this isn't testable easily we test here only if the
+ * properties of the current node don't change (tested by a copy of the
+ * original node and compare the not autocreated properties (autocreated
+ * properties only because autocreated properties like UUID, creationdate
+ * etc will not be equal as expected)).
+ */
+ public void testCheckOutAlreadyCheckedOutNode() throws RepositoryException {
+ versionableNode.checkout();
+
+ // build a copy of versionableNode.
+ String copiedNodePath = testRoot + "/" + nodeName2;
+ superuser.getWorkspace().copy(versionableNode.getPath(), copiedNodePath);
+ Node copiedNode = (Node) superuser.getItem(copiedNodePath);
+
+ // perform 2nd checkout
+ versionableNode.checkout();
+
+ // check if the values of all not autocreated properties of
+ // the original node are equal to the ones of the copied node.
+ PropertyIterator propIt = versionableNode.getProperties();
+ while (propIt.hasNext()) {
+ Property origProp = propIt.nextProperty();
+ Property copyProp = copiedNode.getProperty(origProp.getName());
+ if (!origProp.getDefinition().isAutoCreate()) {
+ if (origProp.getDefinition().isMultiple()) {
+ Value[] origValues = origProp.getValues();
+ Value[] copyValues = copyProp.getValues();
+ int i = 0;
+ while (i < origValues.length) {
+ if (!origValues[i].equals(copyValues[i])) {
+ fail("After calling Node.checkout() on an already checket-out versionable node must not have changed property '" + origProp.getName() + "'.");
+ }
+ i++;
+ }
+ } else {
+ if (!origProp.getValue().equals(copyProp.getValue())) {
+ fail("After calling Node.checkout() on an already checket-out versionable node must not have changed property '" + origProp.getName() + "'.");
+ }
+ }
+ }
+ }
+
+ // success if passed: neither of the properties (exluding autocreated ones) changed
+ // between first and second checkout.
+ }
+
+ /**
+ * Test if Node.checkout() copies the node's jcr:baseVersion to node's
+ * jcr:predecessors property (no save required).
+ */
+ public void testCheckoutCopiesBaseValueToPredecessorProperty() throws RepositoryException {
+ Value baseVersionValue = versionableNode.getProperty(jcrBaseVersion).getValue();
+ versionableNode.checkout();
+ 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");
}
}
}
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/VersionLabelTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/VersionLabelTest.java?view=diff&r1=153938&r2=153939
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/VersionLabelTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/version/VersionLabelTest.java Tue Feb 15 07:37:30 2005
@@ -18,6 +18,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Node;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.Version;
import javax.jcr.version.VersionException;
@@ -310,5 +311,22 @@
} catch (UnsupportedRepositoryOperationException e) {
//success
}
+ }
+
+ /**
+ * Test if versionHistory.getVersionLabels(Version) throws a VersionException if the
+ * specified version is not in this version history.
+ */
+ public void testGetVersionLabelsForInvalidVersion() throws Exception {
+ // build a second versionable node below the testroot to get it's version.
+ Node versionableNode2 = createVersionableNode(testRootNode, nodeName2, versionableNodeType);
+ Version invalidV = versionableNode2.checkin();
+
+ try {
+ vHistory.getVersionLabels(invalidV);
+ fail("VersionHistory.getVersionLabels(Version) must throw a VersionException if the specified version is not in this version history");
+ } catch (VersionException ve) {
+ // success
+ }
}
}