jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r164563 - in /incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test: ./ api/ api/nodetype/
Date Mon, 25 Apr 2005 12:36:20 GMT
Author: mreutegg
Date: Mon Apr 25 05:36:19 2005
New Revision: 164563

URL: http://svn.apache.org/viewcvs?rev=164563&view=rev
Log:
Add test cases, contributed by Vinzenz Wyser.

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyStringTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyValueTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestResult.java Mon
Apr 25 05:36:19 2005
@@ -53,7 +53,7 @@
      */
     public synchronized void addError(Test test, Throwable throwable) {
         if (throwable instanceof NotExecutableException) {
-            log.println("Test case: " + test.toString() + " not executable");
+            log.println("Test case: " + test.toString() + " not executable: " + throwable.getMessage());
         } else {
             orig.addError(test, throwable);
         }

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java?rev=164563&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java
(added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java
Mon Apr 25 05:36:19 2005
@@ -0,0 +1,545 @@
+/*
+ * 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.nodetype.PropertyDefinition;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.Node;
+import javax.jcr.Value;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Property;
+import javax.jcr.PathValue;
+
+/**
+ * <code>SetPropertyAssumeTypeTest</code> tests if when setting a property
+ * of type <code>PropertyType.UNDEFINED</code> the type is assumed correctly.
+ * The signatures <code>Node.setProperty(String, Value, int)</code>,
+ * <code>Node.setProperty(String, String, int)</code>,
+ * <code>Node.setProperty(String, Value[], int)</code> and
+ * <code>Node.setProperty(String, Node)</code> are tested.
+ *
+ * @test
+ * @sources SetPropertyAssumeTypeTest.java
+ * @executeClass org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest
+ * @keywords level2
+ */
+public class SetPropertyAssumeTypeTest extends AbstractJCRTest {
+
+    private Node testNode;
+    private String testPropName;
+    private Value binaryValue;
+    private Value booleanValue;
+    private Value dateValue;
+    private Value doubleValue;
+    private Value longValue;
+    private Value nameValue;
+    private Value pathValue;
+    private Value stringValue;
+    private Value binaryValues[];
+    private Value booleanValues[];
+    private Value dateValues[];
+    private Value doubleValues[];
+    private Value longValues[];
+    private Value nameValues[];
+    private Value pathValues[];
+    private Value stringValues[];
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        binaryValue = NodeTypeUtil.getValueOfType(PropertyType.BINARY);
+        booleanValue = NodeTypeUtil.getValueOfType(PropertyType.BOOLEAN);
+        dateValue = NodeTypeUtil.getValueOfType(PropertyType.DATE);
+        doubleValue = NodeTypeUtil.getValueOfType(PropertyType.DOUBLE);
+        longValue = NodeTypeUtil.getValueOfType(PropertyType.LONG);
+        nameValue = NodeTypeUtil.getValueOfType(PropertyType.NAME);
+        pathValue = NodeTypeUtil.getValueOfType(PropertyType.PATH);
+        stringValue = NodeTypeUtil.getValueOfType(PropertyType.STRING);
+
+        binaryValues = new Value[] {binaryValue};
+        booleanValues = new Value[] {booleanValue};
+        dateValues = new Value[] {dateValue};
+        doubleValues = new Value[] {doubleValue};
+        longValues = new Value[] {longValue};
+        nameValues = new Value[] {nameValue};
+        pathValues = new Value[] {pathValue};
+        stringValues = new Value[] {stringValue};
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value, int)</code> if the node
+     * type of this node does not indicate a specific property type, then the
+     * type parameter is used.
+     */
+    public void testValue() throws NotExecutableException, RepositoryException {
+
+        setUpNodeWithUndefinedProperty(false);
+
+        Property prop;
+
+        // create an extra value for BINARY property to avoid IllegalStateException
+        Value stringValueForBinary = NodeTypeUtil.getValueOfType(PropertyType.STRING);
+        prop = testNode.setProperty(testPropName, stringValueForBinary, PropertyType.BINARY);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BINARY,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, stringValue, PropertyType.BOOLEAN);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BOOLEAN,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, doubleValue, PropertyType.DATE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DATE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValue, PropertyType.DOUBLE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DOUBLE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValue, PropertyType.LONG);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.LONG,
+                     prop.getType());
+
+        // create a PathValue that is convertible to the value of name property
+        Value valueConvertibleToName = PathValue.valueOf(nameValue.getString());
+        prop = testNode.setProperty(testPropName, valueConvertibleToName, PropertyType.NAME);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.NAME,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, nameValue, PropertyType.PATH);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.PATH,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValue, PropertyType.STRING);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.STRING,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value[], int)</code> if the node
+     * type of this node does not indicate a specific property type, then the
+     * type parameter is used.
+     */
+    public void testValues() throws NotExecutableException, RepositoryException {
+
+        setUpNodeWithUndefinedProperty(true);
+
+        Property prop;
+
+        // create an extra value for BINARY property to avoid IllegalStateException
+        Value stringValuesForBinary[] =
+            new Value[] {NodeTypeUtil.getValueOfType(PropertyType.STRING)};
+        prop = testNode.setProperty(testPropName, stringValuesForBinary, PropertyType.BINARY);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BINARY,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, stringValues, PropertyType.BOOLEAN);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BOOLEAN,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, doubleValues, PropertyType.DATE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DATE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValues, PropertyType.DOUBLE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DOUBLE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValues, PropertyType.LONG);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.LONG,
+                     prop.getType());
+
+        // create a PathValue that is convertible to the value of name property
+        Value valuesConvertibleToName[] =
+            new Value[] {PathValue.valueOf(nameValue.getString())};
+        prop = testNode.setProperty(testPropName, valuesConvertibleToName, PropertyType.NAME);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.NAME,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, nameValues, PropertyType.PATH);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.PATH,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValues, PropertyType.STRING);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.STRING,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, String, int)</code> if the node
+     * type of this node does not indicate a specific property type, then the
+     * type parameter is used.
+     */
+    public void testString() throws NotExecutableException, RepositoryException {
+
+        setUpNodeWithUndefinedProperty(false);
+
+        Property prop;
+
+        prop = testNode.setProperty(testPropName, binaryValue.getString(), PropertyType.BINARY);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BINARY,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, booleanValue.getString(), PropertyType.BOOLEAN);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.BOOLEAN,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValue.getString(), PropertyType.DATE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DATE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, doubleValue.getString(), PropertyType.DOUBLE);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.DOUBLE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, longValue.getString(), PropertyType.LONG);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.LONG,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, nameValue.getString(), PropertyType.NAME);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.NAME,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, pathValue.getString(), PropertyType.PATH);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.PATH,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, stringValue.getString(), PropertyType.STRING);
+        assertEquals("setProperty(String, Value, int) of a property of type undefined " +
+                     "must assume the property type of the type parameter.",
+                     PropertyType.STRING,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value)</code> if the node type
of
+     * this node does not indicate a specific property type, then the property
+     * type of the supplied Value object is used and if the property already
+     * exists (has previously been set) it assumes the new property type.
+     */
+    public void testValueAssumeTypeOfValue() throws NotExecutableException, RepositoryException
{
+
+        setUpNodeWithUndefinedProperty(false);
+
+        Property prop;
+
+        prop = testNode.setProperty(testPropName, binaryValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.BINARY,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, booleanValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.BOOLEAN,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.DATE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, doubleValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.DOUBLE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, longValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.LONG,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, nameValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.NAME,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, pathValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.PATH,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, stringValue);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.STRING,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Node)</code> if the node type
of
+     * this node does not indicate a specific property type, then the property
+     * type of the supplied Value object is used and if the property already
+     * exists (has previously been set) it assumes the new property type.
+     */
+    public void testNodeAssumeTypeOfValue()
+        throws NotExecutableException, RepositoryException {
+
+        setUpNodeWithUndefinedProperty(false);
+
+        Node referenceableNode = testRootNode.addNode(nodeName2);
+        referenceableNode.addMixin(mixReferenceable);
+
+        Property prop = testNode.setProperty(testPropName, referenceableNode);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.REFERENCE,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value[])</code> if the node type
of
+     * this node does not indicate a specific property type, then the property
+     * type of the supplied Value object is used and if the property already
+     * exists (has previously been set) it assumes the new property type.
+     */
+    public void testValuesAssumeTypeOfValue() throws NotExecutableException, RepositoryException
{
+
+        setUpNodeWithUndefinedProperty(true);
+
+        Property prop;
+
+        prop = testNode.setProperty(testPropName, binaryValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.BINARY,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, booleanValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.BOOLEAN,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, dateValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.DATE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, doubleValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.DOUBLE,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, longValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.LONG,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, nameValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.NAME,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, pathValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.PATH,
+                     prop.getType());
+
+        prop = testNode.setProperty(testPropName, stringValues);
+        assertEquals("setProperty(String, Value) of a property of type undefined " +
+                     "must assume the property type of the supplied value object.",
+                     PropertyType.STRING,
+                     prop.getType());
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value, int)</code> throws a
+     * ConstraintViolationException if the type parameter and the type of the
+     * property do not match. The exception has to be thrown either immediately
+     * (by this method) or on save.
+     */
+    public void testValueConstraintVioloationExceptionBecauseOfInvalidTypeParameter()
+        throws NotExecutableException, RepositoryException {
+
+        // locate a property definition of type string
+        PropertyDefinition propDef =
+                NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STRING, false, false,
false, false);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No testable property has been found.");
+        }
+
+        // create a node of type propDef.getDeclaringNodeType()
+        String nodeType = propDef.getDeclaringNodeType().getName();
+        Node testNode = testRootNode.addNode(nodeName1, nodeType);
+        String testPropName = propDef.getName();
+
+        try {
+            testNode.setProperty(testPropName, stringValue, PropertyType.DATE);
+            testRootNode.save();
+            fail("Node.setProperty(String, Value, int) must throw a " +
+                 "ConstraintViolationExcpetion if" );
+        }
+        catch (ConstraintViolationException e) {
+            // success
+        }
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, String, int)</code> throws a
+     * ConstraintViolationException if the type parameter and the type of the
+     * property do not match. The exception has to be thrown either immediately
+     * (by this method) or on save.
+     */
+    public void testStringConstraintVioloationExceptionBecauseOfInvalidTypeParameter()
+        throws NotExecutableException, RepositoryException {
+
+        // locate a property definition of type string
+        PropertyDefinition propDef =
+                NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STRING, false, false,
false, false);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No testable property has been found.");
+        }
+
+        // create a node of type propDef.getDeclaringNodeType()
+        String nodeType = propDef.getDeclaringNodeType().getName();
+        Node testNode = testRootNode.addNode(nodeName1, nodeType);
+        String testPropName = propDef.getName();
+
+        try {
+            testNode.setProperty(testPropName, "abc", PropertyType.DATE);
+            testRootNode.save();
+            fail("Node.setProperty(String, Value, int) must throw a " +
+                 "ConstraintViolationExcpetion if" );
+        }
+        catch (ConstraintViolationException e) {
+            // success
+        }
+    }
+
+    /**
+     * Tests if <code>Node.setProperty(String, Value[], int)</code> throws a
+     * ConstraintViolationException if the type parameter and the type of the
+     * property do not match. The exception has to be thrown either immediately
+     * (by this method) or on save.
+     */
+    public void testValuesConstraintVioloationExceptionBecauseOfInvalidTypeParameter()
+        throws NotExecutableException, RepositoryException {
+
+        // locate a property definition of type string
+        PropertyDefinition propDef =
+                NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STRING, true, false,
false, false);
+
+        if (propDef == null) {
+            throw new NotExecutableException("No testable property has been found.");
+        }
+
+        // create a node of type propDef.getDeclaringNodeType()
+        String nodeType = propDef.getDeclaringNodeType().getName();
+        Node testNode = testRootNode.addNode(nodeName1, nodeType);
+        String testPropName = propDef.getName();
+
+        try {
+            testNode.setProperty(testPropName, stringValues, PropertyType.DATE);
+            testRootNode.save();
+            fail("Node.setProperty(String, Value, int) must throw a " +
+                 "ConstraintViolationExcpetion if" );
+        }
+        catch (ConstraintViolationException e) {
+            // success
+        }
+    }
+
+    //--------------------------< internal >------------------------------------
+
+    private void setUpNodeWithUndefinedProperty(boolean multiple)
+        throws NotExecutableException {
+
+        try {
+            // locate a property definition of type undefined
+            PropertyDefinition propDef =
+                    NodeTypeUtil.locatePropertyDef(superuser, PropertyType.UNDEFINED, multiple,
false, false, false);
+
+            if (propDef == null) {
+                throw new NotExecutableException("No testable property of type " +
+                                                 "UNDEFINED has been found.");
+            }
+
+            // create a node of type propDef.getDeclaringNodeType()
+            String nodeType = propDef.getDeclaringNodeType().getName();
+            testNode = testRootNode.addNode(nodeName1, nodeType);
+            testPropName = propDef.getName();
+        }
+        catch (RepositoryException e) {
+            throw new NotExecutableException("Not able to set up test items.");
+        }
+    }
+
+}
\ No newline at end of file

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

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyStringTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyStringTest.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyStringTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyStringTest.java
Mon Apr 25 05:36:19 2005
@@ -76,6 +76,9 @@
         vArray2[2] = new StringValue("z");
     }
 
+
+    // String
+
     /**
      * Tests if adding a property with <code>Node.setProperty(String,
      * String)</code> works with <code>Session.save()</code>
@@ -156,6 +159,92 @@
                 testNode.hasProperty(propertyName1));
     }
 
+
+    // String with PropertyType
+
+    /**
+     * Tests if adding a property with <code>Node.setProperty(String,
+     * String, int)</code> works with <code>Session.save()</code>
+     */
+    public void testNewStringPropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        superuser.save();
+        assertEquals("Setting property with Node.setProperty(String, String, int) and Session.save()
not working",
+                s1,
+                testNode.getProperty(propertyName1).getString());
+    }
+
+    /**
+     * Tests if modifying a property with <code>Node.setProperty(String,
+     * String, int)</code> works with <code>Session.save()</code>
+     */
+    public void testModifyStringPropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        superuser.save();
+        testNode.setProperty(propertyName1, s2, PropertyType.STRING);
+        superuser.save();
+        assertEquals("Modifying property with Node.setProperty(String, String, int) and Session.save()
not working",
+                s2,
+                testNode.getProperty(propertyName1).getString());
+    }
+
+    /**
+     * Tests if adding a property with <code>Node.setProperty(String,
+     * String, int)</code> works with <code>parentNode.save()</code>
+     */
+    public void testNewStringPropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        testRootNode.save();
+        assertEquals("Setting property with Node.setProperty(String, String, int) and parentNode.save()
not working",
+                s1,
+                testNode.getProperty(propertyName1).getString());
+    }
+
+    /**
+     * Tests if modifying a property with <code>Node.setProperty(String,
+     * String, int)</code> works with <code>parentNode.save()</code>
+     */
+    public void testModifyStringPropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        testRootNode.save();
+        testNode.setProperty(propertyName1, s2, PropertyType.STRING);
+        testRootNode.save();
+        assertEquals("Modifying property with Node.setProperty(String, String, int) and parentNode.save()
not working",
+                s2,
+                testNode.getProperty(propertyName1).getString());
+    }
+
+    /**
+     * Tests if removing a <code>String</code> property with
+     * <code>Node.setProperty(String, null, int)</code> works with
+     * <code>Session.save()</code>
+     */
+    public void testRemoveStringPropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        superuser.save();
+        testNode.setProperty(propertyName1, (String) null, PropertyType.STRING);
+        superuser.save();
+        assertFalse("Removing property with Node.setProperty(String, (String)null, int) and
Session.save() not working",
+                testNode.hasProperty(propertyName1));
+    }
+
+    /**
+     * Tests if removing a <code>String</code> property with
+     * <code>Node.setProperty(String, null, int)</code> works with
+     * <code>parentNode.save()</code>
+     */
+    public void testRemoveStringPropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, s1, PropertyType.STRING);
+        testRootNode.save();
+        testNode.setProperty(propertyName1, (String) null, PropertyType.STRING);
+        testRootNode.save();
+        assertFalse("Removing property with Node.setProperty(String, (String)null, int) and
parentNode.save() not working",
+                testNode.hasProperty(propertyName1));
+    }
+
+
+    // String[]
+
     /**
      * Tests if adding properties with <code>Node.setProperty(String,
      * String[])</code> works with <code>Session.save()</code>
@@ -267,6 +356,9 @@
                 Arrays.asList(testNode.getProperty(propertyName2).getValues()));
     }
 
+
+    // String[] with PropertyType
+
     /**
      * Tests if adding properties with <code>Node.setProperty(String, String[],
      * int)</code> works with <code>Session.save()</code>
@@ -378,4 +470,4 @@
                 Arrays.asList(testNode.getProperty(propertyName2).getValues()));
     }
 
-}
\ No newline at end of file
+}

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyValueTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyValueTest.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyValueTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetPropertyValueTest.java
Mon Apr 25 05:36:19 2005
@@ -72,6 +72,11 @@
         vArrayWithNulls[3] = new StringValue("z");
     }
 
+
+    /**
+     * Value
+     */
+
     /**
      * Tests if adding a property with <code>Node.setProperty(String,
      * Value)</code> works with <code>Session.save()</code>
@@ -149,6 +154,90 @@
         testNode.setProperty(propertyName1, (Value) null);
         testRootNode.save();
         assertFalse("Removing property with Node.setProperty(String, (Value)null) and parentNode.save()
not working",
+                testNode.hasProperty(propertyName1));
+    }
+
+    /**
+     * Value with PropertyType
+     */
+
+    /**
+     * Tests if adding a property with <code>Node.setProperty(String,
+     * Value, int)</code> works with <code>Session.save()</code>
+     */
+    public void testNewValuePropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        superuser.save();
+        assertEquals("Setting property with Node.setProperty(String, Value, int) and Session.save()
not working",
+                v1,
+                testNode.getProperty(propertyName1).getValue());
+    }
+
+    /**
+     * Tests if modifying a property with <code>Node.setProperty(String,
+     * Value, int)</code> works with <code>Session.save()</code>
+     */
+    public void testModifyValuePropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        superuser.save();
+        testNode.setProperty(propertyName1, v2, PropertyType.STRING);
+        superuser.save();
+        assertEquals("Modifying property with Node.setProperty(String, Value, int) and Session.save()
not working",
+                v2,
+                testNode.getProperty(propertyName1).getValue());
+    }
+
+    /**
+     * Tests if adding a property with <code>Node.setProperty(String,
+     * Value, int)</code> works with <code>parentNode.save()</code>
+     */
+    public void testNewValuePropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        testRootNode.save();
+        assertEquals("Setting property with Node.setProperty(String, Value, int) and parentNode.save()
not working",
+                v1,
+                testNode.getProperty(propertyName1).getValue());
+    }
+
+    /**
+     * Tests if modifying a property with <code>Node.setProperty(String,
+     * Value, int)</code> works with <code>parentNode.save()</code>
+     */
+    public void testModifyValuePropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        testRootNode.save();
+        testNode.setProperty(propertyName1, v2, PropertyType.STRING);
+        testRootNode.save();
+        assertEquals("Modifying property with Node.setProperty(String, Value, int) and parentNode.save()
not working",
+                v2,
+                testNode.getProperty(propertyName1).getValue());
+    }
+
+    /**
+     * Tests if removing a <code>Value</code> property with
+     * <code>Node.setProperty(String, null, int)</code> works with
+     * <code>Session.save()</code>
+     */
+    public void testRemoveValuePropertySessionWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        superuser.save();
+        testNode.setProperty(propertyName1, (Value) null, PropertyType.STRING);
+        superuser.save();
+        assertFalse("Removing property with Node.setProperty(String, (Value)null, int) and
Session.save() not working",
+                testNode.hasProperty(propertyName1));
+    }
+
+    /**
+     * Tests if removing a <code>Value</code> property with
+     * <code>Node.setProperty(String, null, int)</code> works with
+     * <code>parentNode.save()</code>
+     */
+    public void testRemoveValuePropertyParentWithPropertyType() throws Exception {
+        testNode.setProperty(propertyName1, v1, PropertyType.STRING);
+        testRootNode.save();
+        testNode.setProperty(propertyName1, (Value) null, PropertyType.STRING);
+        testRootNode.save();
+        assertFalse("Removing property with Node.setProperty(String, (Value)null, int) and
parentNode.save() not working",
                 testNode.hasProperty(propertyName1));
     }
 

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=164563&r1=164562&r2=164563&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 Mon Apr
25 05:36:19 2005
@@ -96,6 +96,7 @@
         suite.addTestSuite(SetPropertyStringTest.class);
         suite.addTestSuite(SetPropertyValueTest.class);
         suite.addTestSuite(SetPropertyConstraintViolationExceptionTest.class);
+        suite.addTestSuite(SetPropertyAssumeTypeTest.class);
 
         suite.addTestSuite(NodeItemIsModifiedTest.class);
         suite.addTestSuite(NodeItemIsNewTest.class);

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java
Mon Apr 25 05:36:19 2005
@@ -32,7 +32,7 @@
 /**
  * Test of <code>NodeType.canSetProperty(String propertyName, Value
  * value)</code> and <code>NodeType.canSetProperty(String propertyName, Value[]
- * values)</code> where property is of type Double.
+ * values)</code> where property is of type Long.
  *
  * @test
  * @sources CanSetPropertyLongTest.java
@@ -74,7 +74,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.DOUBLE, false, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG, false, false,
false, false);
 
         if (propDef == null) {
             throw new NotExecutableException("No long property def that meets the " +
@@ -149,7 +149,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.DOUBLE, true, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG, true, false, false,
false);
 
         if (propDef == null) {
             throw new NotExecutableException("No multiple long property def that meets the
" +

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java
Mon Apr 25 05:36:19 2005
@@ -23,7 +23,6 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
-import javax.jcr.PropertyType;
 import javax.jcr.Value;
 
 /**
@@ -71,7 +70,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, true, true,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true,
true, false, false);
 
         // will never happen since at least jcr:mixinTypes of nt:base accomplish the request
         if (propDef == null) {
@@ -96,7 +95,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, false, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, false,
false, false, false);
 
         if (propDef == null) {
             throw new NotExecutableException("No not multiple, not protected property def
found");
@@ -119,7 +118,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, true, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true,
false, false, false);
 
         if (propDef == null) {
             throw new NotExecutableException("No not protected, multiple property def found");

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java
Mon Apr 25 05:36:19 2005
@@ -23,7 +23,6 @@
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
-import javax.jcr.PropertyType;
 import javax.jcr.Value;
 
 /**
@@ -70,7 +69,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, false, true,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, false,
true, false, false);
 
         // will never happen since at least jcr:primaryType of nt:base accomplish the request
         if (propDef == null) {
@@ -94,7 +93,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, true, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, true,
false, false, false);
 
         if (propDef == null) {
             throw new NotExecutableException("No multiple, not protected property def found.");
@@ -116,7 +115,7 @@
             throws NotExecutableException, RepositoryException {
 
         PropertyDefinition propDef =
-                NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEFINED, false, false,
false, false);
+                NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_PROPERTY_TYPE, false,
false, false, false);
 
         if (propDef == null) {
             throw new NotExecutableException("No not protected property def found.");

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?rev=164563&r1=164562&r2=164563&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java
Mon Apr 25 05:36:19 2005
@@ -44,6 +44,8 @@
  */
 public class NodeTypeUtil {
 
+    public static final int ANY_PROPERTY_TYPE = -1;
+
     /**
      * Locate a child node def parsing all node types
      *
@@ -178,8 +180,8 @@
      * Locate a property def parsing all node types
      *
      * @param session      the session to access the node types
-     * @param propertyType the type of the returned property. <cod>PropertyType.UNDEFINED</code>
-     *                     returns a property of any type
+     * @param propertyType the type of the returned property. -1 indicates to
+     *                     return a property of any type but not UNDEFIEND
      * @param multiple     if true, the returned <code>PropertyDef</code> is
      *                     multiple, else not
      * @param isProtected  if true, the returned <code>PropertyDef</code> is
@@ -206,9 +208,13 @@
             for (int i = 0; i < propDefs.length; i++) {
                 PropertyDefinition propDef = propDefs[i];
 
-                // PropertyType.UNDEFINED is in use to get a property of any type
-                if (propertyType != PropertyType.UNDEFINED &&
+                if (propertyType != ANY_PROPERTY_TYPE &&
                         propDef.getRequiredType() != propertyType) {
+                    continue;
+                }
+
+                if (propertyType == ANY_PROPERTY_TYPE &&
+                        propDef.getRequiredType() == PropertyType.UNDEFINED) {
                     continue;
                 }
 



Mime
View raw message