You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2005/05/04 11:58:19 UTC
svn commit: r168107 - in
/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api:
PropertyReadMethodsTest.java SetValueValueFormatExceptionTest.java
SetValueVersionExceptionTest.java TestAll.java
lock/SetValueLockExceptionTest.java lock/TestAll.java
Author: dpfister
Date: Wed May 4 02:58:17 2005
New Revision: 168107
URL: http://svn.apache.org/viewcvs?rev=168107&view=rev
Log:
Added and enhanced tests
Added:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java (with props)
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java (with props)
Modified:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/TestAll.java
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java?rev=168107&r1=168106&r2=168107&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java Wed May 4 02:58:17 2005
@@ -278,4 +278,56 @@
}
}
-}
\ No newline at end of file
+ /**
+ * Tests if <code>Property.getNodes()</code> returns an array that is a copy
+ * of the stored values, so changes to it are not reflected in internal storage.
+ */
+ public void testGetValueCopyStoredValues()
+ throws NotExecutableException, RepositoryException {
+
+ Property prop = PropertyUtil.searchMultivalProp(testRootNode, PropertyType.STRING);
+ if (prop == null) {
+ throw new NotExecutableException("No testable propery found.");
+ }
+
+ // acquire the values of the property and change the zeroth value
+ Value[] values = prop.getValues();
+ if (values.length == 0) {
+ throw new NotExecutableException("No testable propery found.");
+ }
+ values[0] = session.getValueFactory().createValue(values[0].getString() + "abc");
+ prop.getParent().save();
+
+ // re-acquire the values and compare the zeroth values
+ Value[] values2 = prop.getValues();
+ String s1 = values[0].getString();
+ String s2 = values2[0].getString();
+ assertFalse("Changes on the array returned by Property.getNodes() must " +
+ "not be reflected in the internal storage.",
+ s1.equals(s2));
+ }
+
+ /**
+ * Tests that a ValueFormatExcdption is thrown in case Property.getNode is called
+ * on a multivalued exception.
+ * @throws RepositoryException
+ * @throws NotExecutableException
+ */
+ public void testGetNode() throws RepositoryException, NotExecutableException {
+ Property prop = PropertyUtil.searchMultivalProp(testRootNode);
+ if (prop == null) {
+ throw new NotExecutableException("Test Property.getNode is throwing a "
+ + "ValueFormaException not executable in case of a multivalued property.");
+ }
+ else {
+ try {
+ prop.getNode();
+ fail("Property.getNode should throw a ValueFormatException in case of "
+ + "a multivalued porerty.");
+ } catch (ValueFormatException vfe) {
+ // ok
+ }
+ }
+ }
+
+}
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java?rev=168107&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java Wed May 4 02:58:17 2005
@@ -0,0 +1,370 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.nodetype.NodeTypeUtil;
+
+import javax.jcr.Session;
+import javax.jcr.PropertyType;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.NodeType;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.util.Calendar;
+
+/**
+ * <code>SetValueValueFormatExceptionTest</code> tests if Property.setValue() throws
+ * a ValueFormatException if a best-effort conversion fails.
+ * The ValueFormatException has to be thrown immediately (not on save).
+ *
+ * @test
+ * @sources SetValueValueFormatExceptionTest.java
+ * @executeClass org.apache.jackrabbit.test.api.SetValueValueFormatExceptionTest
+ * @keywords level2
+ */
+public class SetValueValueFormatExceptionTest extends AbstractJCRTest {
+ /**
+ * The session we use for the tests
+ */
+ private Session session;
+
+ private Property booleanProperty;
+ private Property dateProperty;
+
+ /**
+ * Sets up the fixture for the test cases.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ session = helper.getReadOnlySession();
+
+ // create a node with a boolean property
+ PropertyDefinition booleanPropDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, false, false, false, false);
+ if (booleanPropDef != null) {
+ NodeType nodeType = booleanPropDef.getDeclaringNodeType();
+
+ Node n = testRootNode.addNode(nodeName1, nodeType.getName());
+
+ Value initValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
+ booleanProperty = n.setProperty(booleanPropDef.getName(), initValue);
+ }
+
+ // create a node with a date property
+ PropertyDefinition datePropDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, false, false, false, false);
+ if (datePropDef != null) {
+ NodeType nodeType = datePropDef.getDeclaringNodeType();
+
+ Node n = testRootNode.addNode(nodeName2, nodeType.getName());
+
+ Value initValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
+ dateProperty = n.setProperty(datePropDef.getName(), initValue);
+ }
+ }
+
+ /**
+ * Releases the session aquired in {@link #setUp()}.
+ */
+ protected void tearDown() throws Exception {
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Tests if setValue(Value) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testValue()
+ throws NotExecutableException, RepositoryException {
+
+ if (booleanProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
+ booleanProperty.setValue(dateValue);
+ fail("Property.setValue(Value) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Value[]) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testValueArray()
+ throws NotExecutableException, RepositoryException {
+
+ // create a node with a multiple boolean property
+ PropertyDefinition propDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, true, false, false, false);
+ if (propDef == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ NodeType nodeType = propDef.getDeclaringNodeType();
+
+ Node n = testRootNode.addNode(nodeName3, nodeType.getName());
+
+ Value initValues[] = new Value[] {NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN)};
+ Property property = n.setProperty(propDef.getName(), initValues);
+
+ try {
+ Value dateValues[] =
+ new Value[] {NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE)};
+ property.setValue(dateValues);
+ fail("Property.setValue(Value[]) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(String) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testString()
+ throws NotExecutableException, RepositoryException {
+
+ if (dateProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ dateProperty.setValue("abc");
+ fail("Property.setValue(String) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(String[]) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testStringArray()
+ throws NotExecutableException, RepositoryException {
+
+ // create a node with a multiple date property
+ PropertyDefinition propDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.DATE, true, false, false, false);
+ if (propDef == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ NodeType nodeType = propDef.getDeclaringNodeType();
+
+ Node n = testRootNode.addNode(nodeName3, nodeType.getName());
+
+ Value initValues[] = new Value[] {NodeTypeUtil.getValueOfType(session, PropertyType.DATE)};
+ Property property = n.setProperty(propDef.getName(), initValues);
+
+ try {
+ String values[] = new String[] {"abc"};
+ property.setValue(values);
+ fail("Property.setValue(String[]) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(InputStream) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testInputStream()
+ throws NotExecutableException, RepositoryException {
+
+ if (dateProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ byte[] bytes = {123};
+ InputStream value = new ByteArrayInputStream(bytes);
+ dateProperty.setValue(value);
+ fail("Property.setValue(InputStream) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(long) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testLong()
+ throws NotExecutableException, RepositoryException {
+
+ if (booleanProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ booleanProperty.setValue(123);
+ fail("Property.setValue(long) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(double) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testDouble()
+ throws NotExecutableException, RepositoryException {
+
+ if (booleanProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ booleanProperty.setValue(1.23);
+ fail("Property.setValue(double) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Calendar) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testCalendar()
+ throws NotExecutableException, RepositoryException {
+
+ if (booleanProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ booleanProperty.setValue(Calendar.getInstance());
+ fail("Property.setValue(Calendar) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(boolean) throws a ValueFormatException immediately (not
+ * on save) if a conversion fails.
+ */
+ public void testBoolean()
+ throws NotExecutableException, RepositoryException {
+
+ if (dateProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ dateProperty.setValue(true);
+ fail("Property.setValue(boolean) must throw a ValueFormatException " +
+ "immediately if a conversion fails.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Node) throws a ValueFormatException immediately (not
+ * on save) if the property is not of type REFERENCE.
+ */
+ public void testNode()
+ throws NotExecutableException, RepositoryException {
+
+ if (booleanProperty == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+
+ try {
+ Node referenceableNode = testRootNode.addNode(nodeName3);
+ referenceableNode.addMixin(mixReferenceable);
+
+ booleanProperty.setValue(referenceableNode);
+ fail("Property.setValue(Node) must throw a ValueFormatException " +
+ "immediately if the property is not of type REFERENCE.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Node) throws a ValueFormatException immediately (not
+ * on save) if the specified node is not referencable.
+ */
+ public void testNodeNotReferenceable()
+ throws NotExecutableException, RepositoryException {
+
+ // create a node with a reference property
+ PropertyDefinition propDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.REFERENCE, false, false, false, false);
+ if (propDef == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+ NodeType nodeType = propDef.getDeclaringNodeType();
+ Node n = testRootNode.addNode(nodeName3, nodeType.getName());
+
+ // create a referenceable node (to init property)
+ Node referenceableNode = testRootNode.addNode(nodeName4 + "Ref");
+ referenceableNode.addMixin(mixReferenceable);
+
+ // create a not referenceable node (to throw the exception)
+ Node notReferenceableNode = testRootNode.addNode(nodeName4 + "NotRef");
+
+ Property property = n.setProperty(propDef.getName(), referenceableNode);
+
+ try {
+ property.setValue(notReferenceableNode);
+ fail("Property.setValue(Node) must throw a ValueFormatException " +
+ "immediately if the specified node is not referenceable.");
+ }
+ catch (ValueFormatException e) {
+ // success
+ }
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueValueFormatExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java?rev=168107&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java Wed May 4 02:58:17 2005
@@ -0,0 +1,309 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.nodetype.NodeTypeUtil;
+
+import javax.jcr.Session;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.Node;
+import javax.jcr.Value;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionException;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.NodeType;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.util.Calendar;
+
+/**
+ * <code>SetValueVersionExceptionTest</code>...
+ *
+ * @test
+ * @sources SetValueVersionExceptionTest.java
+ * @executeClass org.apache.jackrabbit.test.api.SetValueVersionExceptionTest
+ * @keywords level2 versionable
+ */
+public class SetValueVersionExceptionTest extends AbstractJCRTest {
+
+ /**
+ * The session we use for the tests
+ */
+ private Session session;
+
+ private Node node;
+
+ private Property property;
+ private Property multiProperty;
+
+ private Value value;
+ private Value values[];
+
+ /**
+ * Sets up the fixture for the test cases.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ session = helper.getReadOnlySession();
+
+ value = session.getValueFactory().createValue("abc");
+ values = new Value[] {value};
+
+ if (session.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) == null) {
+ throw new NotExecutableException("Versioning is not supported.");
+ }
+
+ // create a node that is versionable
+ node = testRootNode.addNode(nodeName1, testNodeType);
+ // or try to make it versionable if it is not
+ if (!node.isNodeType(mixVersionable)) {
+ if (node.canAddMixin(mixVersionable)) {
+ node.addMixin(mixVersionable);
+ } else {
+ throw new NotExecutableException("Failed to set up required test items");
+ }
+ }
+
+ property = node.setProperty(propertyName1, value);
+ multiProperty = node.setProperty(propertyName2, values);
+
+ testRootNode.save();
+
+ node.checkin();
+ }
+
+ /**
+ * Releases the session aquired in {@link #setUp()}.
+ */
+ protected void tearDown() throws Exception {
+ node.checkout();
+
+ if (session != null) {
+ session.logout();
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Tests if setValue(Value) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testValue() throws RepositoryException {
+ try {
+ property.setValue(value);
+ node.save();
+ fail("Property.setValue(Value) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Value[]) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testValueArray() throws RepositoryException {
+ try {
+ multiProperty.setValue(values);
+ node.save();
+ fail("Property.setValue(Value[]) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(String) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testString() throws RepositoryException {
+ try {
+ property.setValue("abc");
+ node.save();
+ fail("Property.setValue(String) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(String[]) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testStringArray() throws RepositoryException {
+ try {
+ String values[] = new String[] {"abc"};
+ multiProperty.setValue(values);
+ node.save();
+ fail("Property.setValue(String[]) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(InputStream) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testInputStream() throws RepositoryException {
+ try {
+ byte[] bytes = {123};
+ InputStream value = new ByteArrayInputStream(bytes);
+ property.setValue(value);
+ node.save();
+ fail("Property.setValue(InputStream) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(long) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testLong() throws RepositoryException {
+ try {
+ property.setValue(123);
+ node.save();
+ fail("Property.setValue(long) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(double) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testDouble() throws RepositoryException {
+ try {
+ property.setValue(1.23);
+ node.save();
+ fail("Property.setValue(double) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Calendar) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testCalendar() throws RepositoryException {
+ try {
+ property.setValue(Calendar.getInstance());
+ node.save();
+ fail("Property.setValue(Calendar) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(boolean) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testBoolean() throws RepositoryException {
+ try {
+ property.setValue(true);
+ node.save();
+ fail("Property.setValue(boolean) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+ }
+
+ /**
+ * Tests if setValue(Node) throws a VersionException immediately
+ * or on save if the parent node of this property is checked-in.
+ */
+ public void testNode()
+ throws NotExecutableException, RepositoryException {
+
+ // create a referenceable node
+ Node referenceableNode = testRootNode.addNode(nodeName3);
+ referenceableNode.addMixin(mixReferenceable);
+
+ // create a node with a reference property
+ PropertyDefinition propDef =
+ NodeTypeUtil.locatePropertyDef(session, PropertyType.REFERENCE, false, false, false, false);
+ if (propDef == null) {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+ NodeType nodeType = propDef.getDeclaringNodeType();
+ Node node = testRootNode.addNode(nodeName4, nodeType.getName());
+
+ // try to make it versionable if it is not
+ if (!node.isNodeType(mixVersionable)) {
+ if (node.canAddMixin(mixVersionable)) {
+ node.addMixin(mixVersionable);
+ } else {
+ throw new NotExecutableException("Failed to set up required test items.");
+ }
+ }
+
+ Property property = node.setProperty(propDef.getName(), referenceableNode);
+
+ testRootNode.save();
+
+ node.checkin();
+
+ try {
+ property.setValue(referenceableNode);
+ node.save();
+ fail("Property.setValue(Node) must throw a VersionException " +
+ "immediately or on save if the parent node of this property " +
+ "is checked-in.");
+ }
+ catch (VersionException e) {
+ // success
+ }
+
+ node.checkout();
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetValueVersionExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?rev=168107&r1=168106&r2=168107&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Wed May 4 02:58:17 2005
@@ -86,6 +86,8 @@
suite.addTestSuite(SetValueReferenceTest.class);
suite.addTestSuite(SetValueStringTest.class);
suite.addTestSuite(SetValueConstraintViolationExceptionTest.class);
+ suite.addTestSuite(SetValueValueFormatExceptionTest.class);
+ suite.addTestSuite(SetValueVersionExceptionTest.class);
suite.addTestSuite(SetPropertyBooleanTest.class);
suite.addTestSuite(SetPropertyCalendarTest.class);
@@ -130,6 +132,8 @@
suite.addTestSuite(DocumentViewImportTest.class);
suite.addTestSuite(SerializationTest.class);
+
+ suite.addTestSuite(ValueFactoryTest.class);
return suite;
}
Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java?rev=168107&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java Wed May 4 02:58:17 2005
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api.lock;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.lock.LockException;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+import javax.jcr.PathNotFoundException;
+import java.util.Calendar;
+import java.io.ByteArrayInputStream;
+
+
+/**
+ * <code>SetValueLockExceptionTest</code> Tests throwing of a LockException for the
+ * Property.setValue() methods in case the parentNode of the given property is locked.
+ *
+ * @test
+ * @sources SetValueLockExceptionTest.java
+ * @executeClass org.apache.jackrabbit.test.api.lock.SetValueyLockExceptionTest
+ * @keywords level2
+ */
+public class SetValueLockExceptionTest extends AbstractJCRTest {
+
+ private Session lockingSession;
+ private Session session;
+
+ private Node testNode;
+
+ private static final String binaryProp = "binaryProp";
+ private static final String booleanProp = "booleanProp";
+ private static final String dateProp = "dateProp";
+ private static final String doubleProp = "doubleProp";
+ private static final String longProp = "longProp";
+ private static final String referenceProp = "referenceProp";
+ private static final String stringProp = "stringProp";
+ private static final String multiStringProp ="multiStringProp";
+
+ private static final boolean booleanValue = false;
+ private Calendar dateValue = null;
+ private static final double doubleValue = 3.1414926;
+ private static final long longValue = Long.MAX_VALUE;
+ private Node referenceNode = null;
+ private static final String stringValue = "a string";
+ private byte[] binaryValue = null;
+ private String[] multiString = {"one", "two", "three"};
+
+ // types for the different method signatures of Property.setValue
+ private static final int TYPE_VALUE = 20;
+ private static final int TYPE_MULTIVAL = 21;
+ private static final int TYPE_MULTSTRING = 22;
+ private static int[] types = {PropertyType.DATE, PropertyType.DOUBLE, PropertyType.LONG,
+ PropertyType.REFERENCE, PropertyType.STRING,
+ PropertyType.BINARY, PropertyType.BOOLEAN, TYPE_VALUE,
+ TYPE_MULTIVAL, TYPE_MULTSTRING};
+
+
+ /**
+ * Check if Locking is supported and if yes setup a lockable node with properties
+ * each one for the possible values passed to Property.setValue .
+ * and
+ * @throws Exception
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ Repository repo = helper.getRepository();
+ if (repo.getDescriptor(Repository.OPTION_LOCKING_SUPPORTED) == null) {
+ throw new NotExecutableException("SetValueLockExceptionTest "
+ + "not executable: Locking not supported");
+ }
+ else {
+ lockingSession = superuser;
+
+ // add a lockable node
+ testNode = testRootNode.addNode(nodeName1, testNodeType);
+ testNode.addMixin(mixLockable);
+
+ // add properties
+ dateValue = Calendar.getInstance();
+ referenceNode = createReferenceableNode(nodeName2);
+ binaryValue = createRandomString(10).getBytes();
+
+ ByteArrayInputStream in = new ByteArrayInputStream(binaryValue);
+ testNode.setProperty(binaryProp, in);
+ testNode.setProperty(booleanProp, booleanValue);
+ testNode.setProperty(dateProp, dateValue);
+ testNode.setProperty(doubleProp, doubleValue);
+ testNode.setProperty(longProp, longValue);
+ if (referenceNode != null) {
+ testNode.setProperty(referenceProp, referenceNode);
+ }
+ testNode.setProperty(stringProp, stringValue);
+ testNode.setProperty(multiStringProp, multiString);
+ testRootNode.save();
+ }
+ }
+
+ public void tearDown() throws Exception {
+ if (testNode.holdsLock()) {
+ testNode.unlock();
+ }
+ lockingSession.save();
+ super.tearDown();
+ }
+
+ /**
+ * Tests if a LockException is thrown if a value is added to a property of a locked node.
+ *
+ * @param type The possible argument types.
+ * @throws RepositoryException
+ */
+ public void doTestSetValueLockException(int type)
+ throws RepositoryException {
+
+ // lock if not yet locked
+ if (!testNode.holdsLock()) {
+ testNode.lock(false, false);
+ lockingSession.save();
+ }
+
+ // another session
+ session = helper.getReadWriteSession();
+
+ try {
+ Node node = (Node) session.getItem(testNode.getPath());
+ Property prop = null;
+ switch (type) {
+ case PropertyType.BINARY:
+ ByteArrayInputStream in = new ByteArrayInputStream(binaryValue);
+ prop = node.getProperty(binaryProp);
+ prop.setValue(in);
+ break;
+
+ case PropertyType.BOOLEAN:
+ prop = node.getProperty(booleanProp);
+ prop.setValue(booleanValue);
+ break;
+
+ case PropertyType.DATE:
+ prop = node.getProperty(dateProp);
+ prop.setValue(dateValue);
+ break;
+
+ case PropertyType.DOUBLE:
+ prop = node.getProperty(doubleProp);
+ prop.setValue(doubleValue);
+ break;
+
+ case PropertyType.LONG:
+ prop = node.getProperty(longProp);
+ prop.setValue(longValue);
+ break;
+
+ case PropertyType.REFERENCE:
+ prop = node.getProperty(referenceProp);
+ if (referenceNode != null) {
+ prop.setValue(referenceNode);
+ }
+ break;
+
+ case PropertyType.STRING:
+ prop = node.getProperty(stringProp);
+ prop.setValue(stringValue);
+ break;
+
+ case TYPE_VALUE:
+ prop = node.getProperty(stringProp);
+ Value value = session.getValueFactory().createValue(stringValue);
+ prop.setValue(value);
+ break;
+
+ case TYPE_MULTIVAL:
+ prop = node.getProperty(multiStringProp);
+ Value[] values = { session.getValueFactory().createValue(stringValue),
+ session.getValueFactory().createValue(stringValue),
+ session.getValueFactory().createValue(stringValue) };
+ prop.setValue(values);
+ break;
+
+ case TYPE_MULTSTRING:
+ prop = node.getProperty(multiStringProp);
+ String[] strVals = {stringValue, stringValue, stringValue};
+ prop.setValue(strVals);
+ break;
+ }
+ session.save();
+ fail("Property.setValue should throw a LockException "
+ + "if the parent node holds a Lock.");
+ } catch (LockException le) {
+ // ok
+ }
+ }
+
+ /**
+ * Performs the test for all argument types.
+ * @throws RepositoryException
+ */
+ public void testSetValueLockException() throws RepositoryException {
+ for (int i = 0; i < types.length; i++) {
+ doTestSetValueLockException(types[i]);
+ }
+ }
+
+ /**
+ * Create a referenceable node under the testRootNode
+ * or null if it is not possible to create one.
+ * @param name
+ * @return
+ * @throws RepositoryException
+ */
+ public Node createReferenceableNode(String name) throws RepositoryException {
+ // remove a yet existing node at the target
+ try {
+ Node node = testRootNode.getNode(name);
+ node.remove();
+ lockingSession.save();
+ } catch (PathNotFoundException pnfe) {
+ // ok
+ }
+ // a referenceable node
+ Node n1 = testRootNode.addNode(name);
+ if (n1.canAddMixin(mixReferenceable)) {
+ n1.addMixin(mixReferenceable);
+ // make sure jcr:uuid is available
+ lockingSession.save();
+ return n1;
+ }
+ else {
+ return null;
+ }
+ }
+}
Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/SetValueLockExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/TestAll.java?rev=168107&r1=168106&r2=168107&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/TestAll.java Wed May 4 02:58:17 2005
@@ -37,6 +37,7 @@
TestSuite suite = new TestSuite("javax.jcr.lock tests");
suite.addTestSuite(LockTest.class);
+ suite.addTestSuite(SetValueLockExceptionTest.class);
return suite;
}