Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 1788 invoked from network); 25 Apr 2005 12:36:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Apr 2005 12:36:25 -0000 Received: (qmail 718 invoked by uid 500); 25 Apr 2005 12:36:53 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 701 invoked by uid 500); 25 Apr 2005 12:36:53 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 697 invoked by uid 99); 25 Apr 2005 12:36:53 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 25 Apr 2005 05:36:52 -0700 Received: (qmail 1776 invoked by uid 65534); 25 Apr 2005 12:36:22 -0000 Message-ID: <20050425123622.1775.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 -0000 To: jackrabbit-cvs@incubator.apache.org From: mreutegg@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: mreutegg Date: Mon Apr 25 05:36:19 2005 New Revision: 164563 URL: http://svn.apache.org/viewcvs?rev=3D164563&view=3Drev Log: Add test cases, contributed by Vinzenz Wyser. Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyAssumeTypeTest.java (with props) Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestR= esult.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyStringTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyValueTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Test= All.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyLongTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyMultipleTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/NodeTypeUtil.java Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JC= RTestResult.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/JCRTestResult.java?rev=3D164563&r1=3D164562&r2=3D164= 563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestR= esult.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JCRTestR= esult.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/S= etPropertyAssumeTypeTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/SetPropertyAssumeTypeTest.java?rev=3D164563&view= =3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyAssumeTypeTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyAssumeTypeTest.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; + +/** + * SetPropertyAssumeTypeTest tests if when setting a property + * of type PropertyType.UNDEFINED the type is assumed correct= ly. + * The signatures Node.setProperty(String, Value, int), + * Node.setProperty(String, String, int), + * Node.setProperty(String, Value[], int) and + * Node.setProperty(String, Node) 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 =3D NodeTypeUtil.getValueOfType(PropertyType.BINARY); + booleanValue =3D NodeTypeUtil.getValueOfType(PropertyType.BOOLEAN); + dateValue =3D NodeTypeUtil.getValueOfType(PropertyType.DATE); + doubleValue =3D NodeTypeUtil.getValueOfType(PropertyType.DOUBLE); + longValue =3D NodeTypeUtil.getValueOfType(PropertyType.LONG); + nameValue =3D NodeTypeUtil.getValueOfType(PropertyType.NAME); + pathValue =3D NodeTypeUtil.getValueOfType(PropertyType.PATH); + stringValue =3D NodeTypeUtil.getValueOfType(PropertyType.STRING); + + binaryValues =3D new Value[] {binaryValue}; + booleanValues =3D new Value[] {booleanValue}; + dateValues =3D new Value[] {dateValue}; + doubleValues =3D new Value[] {doubleValue}; + longValues =3D new Value[] {longValue}; + nameValues =3D new Value[] {nameValue}; + pathValues =3D new Value[] {pathValue}; + stringValues =3D new Value[] {stringValue}; + } + + /** + * Tests if Node.setProperty(String, Value, int) if the n= ode + * type of this node does not indicate a specific property type, then = the + * type parameter is used. + */ + public void testValue() throws NotExecutableException, RepositoryExcep= tion { + + setUpNodeWithUndefinedProperty(false); + + Property prop; + + // create an extra value for BINARY property to avoid IllegalState= Exception + Value stringValueForBinary =3D NodeTypeUtil.getValueOfType(Propert= yType.STRING); + prop =3D testNode.setProperty(testPropName, stringValueForBinary, = PropertyType.BINARY); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BINARY, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, stringValue, PropertyT= ype.BOOLEAN); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BOOLEAN, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, doubleValue, PropertyT= ype.DATE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DATE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValue, PropertyTyp= e=2EDOUBLE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DOUBLE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValue, PropertyTyp= e=2ELONG); + assertEquals("setProperty(String, Value, int) of a property of typ= e 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 pro= perty + Value valueConvertibleToName =3D PathValue.valueOf(nameValue.getSt= ring()); + prop =3D testNode.setProperty(testPropName, valueConvertibleToName= , PropertyType.NAME); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.NAME, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, nameValue, PropertyTyp= e=2EPATH); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.PATH, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValue, PropertyTyp= e=2ESTRING); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.STRING, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, Value[], int) 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, RepositoryExce= ption { + + setUpNodeWithUndefinedProperty(true); + + Property prop; + + // create an extra value for BINARY property to avoid IllegalState= Exception + Value stringValuesForBinary[] =3D + new Value[] {NodeTypeUtil.getValueOfType(PropertyType.STRING)}; + prop =3D testNode.setProperty(testPropName, stringValuesForBinary,= PropertyType.BINARY); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BINARY, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, stringValues, Property= Type.BOOLEAN); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BOOLEAN, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, doubleValues, Property= Type.DATE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DATE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValues, PropertyTy= pe.DOUBLE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DOUBLE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValues, PropertyTy= pe.LONG); + assertEquals("setProperty(String, Value, int) of a property of typ= e 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 pro= perty + Value valuesConvertibleToName[] =3D + new Value[] {PathValue.valueOf(nameValue.getString())}; + prop =3D testNode.setProperty(testPropName, valuesConvertibleToNam= e, PropertyType.NAME); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.NAME, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, nameValues, PropertyTy= pe.PATH); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.PATH, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValues, PropertyTy= pe.STRING); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.STRING, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, String, int) 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, RepositoryExce= ption { + + setUpNodeWithUndefinedProperty(false); + + Property prop; + + prop =3D testNode.setProperty(testPropName, binaryValue.getString(= ), PropertyType.BINARY); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BINARY, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, booleanValue.getString= (), PropertyType.BOOLEAN); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.BOOLEAN, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValue.getString(),= PropertyType.DATE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DATE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, doubleValue.getString(= ), PropertyType.DOUBLE); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.DOUBLE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, longValue.getString(),= PropertyType.LONG); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.LONG, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, nameValue.getString(),= PropertyType.NAME); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.NAME, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, pathValue.getString(),= PropertyType.PATH); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.PATH, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, stringValue.getString(= ), PropertyType.STRING); + assertEquals("setProperty(String, Value, int) of a property of typ= e undefined " + + "must assume the property type of the type parameter.= ", + PropertyType.STRING, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, Value) if the node t= ype of + * this node does not indicate a specific property type, then the prop= erty + * type of the supplied Value object is used and if the property alrea= dy + * exists (has previously been set) it assumes the new property type. + */ + public void testValueAssumeTypeOfValue() throws NotExecutableException= , RepositoryException { + + setUpNodeWithUndefinedProperty(false); + + Property prop; + + prop =3D testNode.setProperty(testPropName, binaryValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.BINARY, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, booleanValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.BOOLEAN, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.DATE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, doubleValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.DOUBLE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, longValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.LONG, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, nameValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.NAME, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, pathValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.PATH, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, stringValue); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.STRING, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, Node) if the node ty= pe of + * this node does not indicate a specific property type, then the prop= erty + * type of the supplied Value object is used and if the property alrea= dy + * exists (has previously been set) it assumes the new property type. + */ + public void testNodeAssumeTypeOfValue() + throws NotExecutableException, RepositoryException { + + setUpNodeWithUndefinedProperty(false); + + Node referenceableNode =3D testRootNode.addNode(nodeName2); + referenceableNode.addMixin(mixReferenceable); + + Property prop =3D testNode.setProperty(testPropName, referenceable= Node); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.REFERENCE, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, Value[]) if the node= type of + * this node does not indicate a specific property type, then the prop= erty + * type of the supplied Value object is used and if the property alrea= dy + * exists (has previously been set) it assumes the new property type. + */ + public void testValuesAssumeTypeOfValue() throws NotExecutableExceptio= n, RepositoryException { + + setUpNodeWithUndefinedProperty(true); + + Property prop; + + prop =3D testNode.setProperty(testPropName, binaryValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.BINARY, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, booleanValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.BOOLEAN, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, dateValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.DATE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, doubleValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.DOUBLE, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, longValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.LONG, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, nameValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.NAME, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, pathValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.PATH, + prop.getType()); + + prop =3D testNode.setProperty(testPropName, stringValues); + assertEquals("setProperty(String, Value) of a property of type und= efined " + + "must assume the property type of the supplied value = object.", + PropertyType.STRING, + prop.getType()); + } + + /** + * Tests if Node.setProperty(String, Value, int) throws a + * ConstraintViolationException if the type parameter and the type of = the + * property do not match. The exception has to be thrown either immedi= ately + * (by this method) or on save. + */ + public void testValueConstraintVioloationExceptionBecauseOfInvalidType= Parameter() + throws NotExecutableException, RepositoryException { + + // locate a property definition of type string + PropertyDefinition propDef =3D + NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STR= ING, false, false, false, false); + + if (propDef =3D=3D null) { + throw new NotExecutableException("No testable property has bee= n found."); + } + + // create a node of type propDef.getDeclaringNodeType() + String nodeType =3D propDef.getDeclaringNodeType().getName(); + Node testNode =3D testRootNode.addNode(nodeName1, nodeType); + String testPropName =3D propDef.getName(); + + try { + testNode.setProperty(testPropName, stringValue, PropertyType.D= ATE); + testRootNode.save(); + fail("Node.setProperty(String, Value, int) must throw a " + + "ConstraintViolationExcpetion if" ); + } + catch (ConstraintViolationException e) { + // success + } + } + + /** + * Tests if Node.setProperty(String, String, int) throws a + * ConstraintViolationException if the type parameter and the type of = the + * property do not match. The exception has to be thrown either immedi= ately + * (by this method) or on save. + */ + public void testStringConstraintVioloationExceptionBecauseOfInvalidTyp= eParameter() + throws NotExecutableException, RepositoryException { + + // locate a property definition of type string + PropertyDefinition propDef =3D + NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STR= ING, false, false, false, false); + + if (propDef =3D=3D null) { + throw new NotExecutableException("No testable property has bee= n found."); + } + + // create a node of type propDef.getDeclaringNodeType() + String nodeType =3D propDef.getDeclaringNodeType().getName(); + Node testNode =3D testRootNode.addNode(nodeName1, nodeType); + String testPropName =3D 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 Node.setProperty(String, Value[], int) throws= a + * ConstraintViolationException if the type parameter and the type of = the + * property do not match. The exception has to be thrown either immedi= ately + * (by this method) or on save. + */ + public void testValuesConstraintVioloationExceptionBecauseOfInvalidTyp= eParameter() + throws NotExecutableException, RepositoryException { + + // locate a property definition of type string + PropertyDefinition propDef =3D + NodeTypeUtil.locatePropertyDef(superuser, PropertyType.STR= ING, true, false, false, false); + + if (propDef =3D=3D null) { + throw new NotExecutableException("No testable property has bee= n found."); + } + + // create a node of type propDef.getDeclaringNodeType() + String nodeType =3D propDef.getDeclaringNodeType().getName(); + Node testNode =3D testRootNode.addNode(nodeName1, nodeType); + String testPropName =3D 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 =3D + NodeTypeUtil.locatePropertyDef(superuser, PropertyType= .UNDEFINED, multiple, false, false, false); + + if (propDef =3D=3D null) { + throw new NotExecutableException("No testable property of = type " + + "UNDEFINED has been found= ."); + } + + // create a node of type propDef.getDeclaringNodeType() + String nodeType =3D propDef.getDeclaringNodeType().getName(); + testNode =3D testRootNode.addNode(nodeName1, nodeType); + testPropName =3D propDef.getName(); + } + catch (RepositoryException e) { + throw new NotExecutableException("Not able to set up test item= s=2E"); + } + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/SetPropertyAssumeTypeTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/SetPropertyStringTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/SetPropertyStringTest.java?rev=3D164563&r1=3D164= 562&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyStringTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyStringTest.java Mon Apr 25 05:36:19 2005 @@ -76,6 +76,9 @@ vArray2[2] =3D new StringValue("z"); } =20 + + // String + /** * Tests if adding a property with Node.setProperty(String, * String) works with Session.save() @@ -156,6 +159,92 @@ testNode.hasProperty(propertyName1)); } =20 + + // String with PropertyType + + /** + * Tests if adding a property with Node.setProperty(String, + * String, int) works with Session.save() + */ + public void testNewStringPropertySessionWithPropertyType() throws Exce= ption { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + superuser.save(); + assertEquals("Setting property with Node.setProperty(String, Strin= g, int) and Session.save() not working", + s1, + testNode.getProperty(propertyName1).getString()); + } + + /** + * Tests if modifying a property with Node.setProperty(String, + * String, int) works with Session.save() + */ + public void testModifyStringPropertySessionWithPropertyType() throws E= xception { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + superuser.save(); + testNode.setProperty(propertyName1, s2, PropertyType.STRING); + superuser.save(); + assertEquals("Modifying property with Node.setProperty(String, Str= ing, int) and Session.save() not working", + s2, + testNode.getProperty(propertyName1).getString()); + } + + /** + * Tests if adding a property with Node.setProperty(String, + * String, int) works with parentNode.save() + */ + public void testNewStringPropertyParentWithPropertyType() throws Excep= tion { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + testRootNode.save(); + assertEquals("Setting property with Node.setProperty(String, Strin= g, int) and parentNode.save() not working", + s1, + testNode.getProperty(propertyName1).getString()); + } + + /** + * Tests if modifying a property with Node.setProperty(String, + * String, int) works with parentNode.save() + */ + public void testModifyStringPropertyParentWithPropertyType() throws Ex= ception { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + testRootNode.save(); + testNode.setProperty(propertyName1, s2, PropertyType.STRING); + testRootNode.save(); + assertEquals("Modifying property with Node.setProperty(String, Str= ing, int) and parentNode.save() not working", + s2, + testNode.getProperty(propertyName1).getString()); + } + + /** + * Tests if removing a String property with + * Node.setProperty(String, null, int) works with + * Session.save() + */ + public void testRemoveStringPropertySessionWithPropertyType() throws E= xception { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + superuser.save(); + testNode.setProperty(propertyName1, (String) null, PropertyType.ST= RING); + superuser.save(); + assertFalse("Removing property with Node.setProperty(String, (Stri= ng)null, int) and Session.save() not working", + testNode.hasProperty(propertyName1)); + } + + /** + * Tests if removing a String property with + * Node.setProperty(String, null, int) works with + * parentNode.save() + */ + public void testRemoveStringPropertyParentWithPropertyType() throws Ex= ception { + testNode.setProperty(propertyName1, s1, PropertyType.STRING); + testRootNode.save(); + testNode.setProperty(propertyName1, (String) null, PropertyType.ST= RING); + testRootNode.save(); + assertFalse("Removing property with Node.setProperty(String, (Stri= ng)null, int) and parentNode.save() not working", + testNode.hasProperty(propertyName1)); + } + + + // String[] + /** * Tests if adding properties with Node.setProperty(String, * String[]) works with Session.save() @@ -267,6 +356,9 @@ Arrays.asList(testNode.getProperty(propertyName2).getValue= s())); } =20 + + // String[] with PropertyType + /** * Tests if adding properties with Node.setProperty(String, Stri= ng[], * int) works with Session.save() @@ -378,4 +470,4 @@ Arrays.asList(testNode.getProperty(propertyName2).getValue= s())); } =20 -} \ No newline at end of file +} Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/SetPropertyValueTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/SetPropertyValueTest.java?rev=3D164563&r1=3D1645= 62&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyValueTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/SetP= ropertyValueTest.java Mon Apr 25 05:36:19 2005 @@ -72,6 +72,11 @@ vArrayWithNulls[3] =3D new StringValue("z"); } =20 + + /** + * Value + */ + /** * Tests if adding a property with Node.setProperty(String, * Value) works with Session.save() @@ -149,6 +154,90 @@ testNode.setProperty(propertyName1, (Value) null); testRootNode.save(); assertFalse("Removing property with Node.setProperty(String, (Valu= e)null) and parentNode.save() not working", + testNode.hasProperty(propertyName1)); + } + + /** + * Value with PropertyType + */ + + /** + * Tests if adding a property with Node.setProperty(String, + * Value, int) works with Session.save() + */ + public void testNewValuePropertySessionWithPropertyType() throws Excep= tion { + 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 Node.setProperty(String, + * Value, int) works with Session.save() + */ + public void testModifyValuePropertySessionWithPropertyType() throws Ex= ception { + testNode.setProperty(propertyName1, v1, PropertyType.STRING); + superuser.save(); + testNode.setProperty(propertyName1, v2, PropertyType.STRING); + superuser.save(); + assertEquals("Modifying property with Node.setProperty(String, Val= ue, int) and Session.save() not working", + v2, + testNode.getProperty(propertyName1).getValue()); + } + + /** + * Tests if adding a property with Node.setProperty(String, + * Value, int) works with parentNode.save() + */ + public void testNewValuePropertyParentWithPropertyType() throws Except= ion { + 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 Node.setProperty(String, + * Value, int) works with parentNode.save() + */ + public void testModifyValuePropertyParentWithPropertyType() throws Exc= eption { + testNode.setProperty(propertyName1, v1, PropertyType.STRING); + testRootNode.save(); + testNode.setProperty(propertyName1, v2, PropertyType.STRING); + testRootNode.save(); + assertEquals("Modifying property with Node.setProperty(String, Val= ue, int) and parentNode.save() not working", + v2, + testNode.getProperty(propertyName1).getValue()); + } + + /** + * Tests if removing a Value property with + * Node.setProperty(String, null, int) works with + * Session.save() + */ + public void testRemoveValuePropertySessionWithPropertyType() throws Ex= ception { + testNode.setProperty(propertyName1, v1, PropertyType.STRING); + superuser.save(); + testNode.setProperty(propertyName1, (Value) null, PropertyType.STR= ING); + superuser.save(); + assertFalse("Removing property with Node.setProperty(String, (Valu= e)null, int) and Session.save() not working", + testNode.hasProperty(propertyName1)); + } + + /** + * Tests if removing a Value property with + * Node.setProperty(String, null, int) works with + * parentNode.save() + */ + public void testRemoveValuePropertyParentWithPropertyType() throws Exc= eption { + testNode.setProperty(propertyName1, v1, PropertyType.STRING); + testRootNode.save(); + testNode.setProperty(propertyName1, (Value) null, PropertyType.STR= ING); + testRootNode.save(); + assertFalse("Removing property with Node.setProperty(String, (Valu= e)null, int) and parentNode.save() not working", testNode.hasProperty(propertyName1)); } =20 Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/TestAll.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/TestAll.java?rev=3D164563&r1=3D164562&r2=3D16456= 3&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Test= All.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Test= All.java Mon Apr 25 05:36:19 2005 @@ -96,6 +96,7 @@ suite.addTestSuite(SetPropertyStringTest.class); suite.addTestSuite(SetPropertyValueTest.class); suite.addTestSuite(SetPropertyConstraintViolationExceptionTest.cla= ss); + suite.addTestSuite(SetPropertyAssumeTypeTest.class); =20 suite.addTestSuite(NodeItemIsModifiedTest.class); suite.addTestSuite(NodeItemIsNewTest.class); Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/nodetype/CanSetPropertyLongTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/nodetype/CanSetPropertyLongTest.java?rev=3D16456= 3&r1=3D164562&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyLongTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyLongTest.java Mon Apr 25 05:36:19 2005 @@ -32,7 +32,7 @@ /** * Test of NodeType.canSetProperty(String propertyName, Value * value) and NodeType.canSetProperty(String propertyName, Va= lue[] - * values) where property is of type Double. + * values) where property is of type Long. * * @test * @sources CanSetPropertyLongTest.java @@ -74,7 +74,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.DOUBL= E, false, false, false, false); + NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG,= false, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No long property def that me= ets the " + @@ -149,7 +149,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.DOUBL= E, true, false, false, false); + NodeTypeUtil.locatePropertyDef(session, PropertyType.LONG,= true, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No multiple long property de= f that meets the " + Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/nodetype/CanSetPropertyMultipleTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/nodetype/CanSetPropertyMultipleTest.java?rev=3D1= 64563&r1=3D164562&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyMultipleTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/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; =20 /** @@ -71,7 +70,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, true, true, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, true, true, false, false); =20 // will never happen since at least jcr:mixinTypes of nt:base acco= mplish the request if (propDef =3D=3D null) { @@ -96,7 +95,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, false, false, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, false, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No not multiple, not protect= ed property def found"); @@ -119,7 +118,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, true, false, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, true, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No not protected, multiple p= roperty def found"); Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/nodetype/CanSetPropertyTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/nodetype/CanSetPropertyTest.java?rev=3D164563&r1= =3D164562&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/CanSetPropertyTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/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; =20 /** @@ -70,7 +69,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, false, true, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, false, true, false, false); =20 // will never happen since at least jcr:primaryType of nt:base acc= omplish the request if (propDef =3D=3D null) { @@ -94,7 +93,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, true, false, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, true, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No multiple, not protected p= roperty def found."); @@ -116,7 +115,7 @@ throws NotExecutableException, RepositoryException { =20 PropertyDefinition propDef =3D - NodeTypeUtil.locatePropertyDef(session, PropertyType.UNDEF= INED, false, false, false, false); + NodeTypeUtil.locatePropertyDef(session, NodeTypeUtil.ANY_P= ROPERTY_TYPE, false, false, false, false); =20 if (propDef =3D=3D null) { throw new NotExecutableException("No not protected property de= f found."); Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/ap= i/nodetype/NodeTypeUtil.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/nodetype/NodeTypeUtil.java?rev=3D164563&r1=3D164= 562&r2=3D164563&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/NodeTypeUtil.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/node= type/NodeTypeUtil.java Mon Apr 25 05:36:19 2005 @@ -44,6 +44,8 @@ */ public class NodeTypeUtil { =20 + public static final int ANY_PROPERTY_TYPE =3D -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. Propert= yType.UNDEFINED - * 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 PropertyDef = is * multiple, else not * @param isProtected if true, the returned PropertyDef = is @@ -206,9 +208,13 @@ for (int i =3D 0; i < propDefs.length; i++) { PropertyDefinition propDef =3D propDefs[i]; =20 - // PropertyType.UNDEFINED is in use to get a property of a= ny type - if (propertyType !=3D PropertyType.UNDEFINED && + if (propertyType !=3D ANY_PROPERTY_TYPE && propDef.getRequiredType() !=3D propertyType) { + continue; + } + + if (propertyType =3D=3D ANY_PROPERTY_TYPE && + propDef.getRequiredType() =3D=3D PropertyType.UNDE= FINED) { continue; } =20