📄 setpropertyassumetypetest.java
字号:
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); // some implementations may require a save after addMixin() testRootNode.save(); 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 testValueConstraintViolationExceptionBecauseOfInvalidTypeParameter() throws NotExecutableException, RepositoryException { try { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(0)); Value v = superuser.getValueFactory().createValue(ISO8601.format(cal)); testNode.setProperty(propertyName1, v, PropertyType.DATE); testRootNode.save(); fail("Node.setProperty(String, Value, int) must throw a " + "ConstraintViolationExcpetion if the type parameter and the " + "type of the property do not match." ); } 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 testStringConstraintViolationExceptionBecauseOfInvalidTypeParameter() throws NotExecutableException, RepositoryException { try { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(0)); testNode.setProperty(propertyName1, ISO8601.format(cal), PropertyType.DATE); testRootNode.save(); fail("Node.setProperty(String, Value, int) must throw a " + "ConstraintViolationExcpetion if the type parameter and the " + "type of the property do not match." ); } catch (ConstraintViolationException e) { // success } } /** * Tests if <code>Node.setProperty(String, Value[], int)</code> throws a * ConstraintViolationException or ValueFormatException 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 testValuesConstraintViolationExceptionBecauseOfInvalidTypeParameter() throws NotExecutableException, RepositoryException { try { testNode.setProperty(propertyName1, stringValues, PropertyType.DATE); testRootNode.save(); fail("Node.setProperty(String, Value, int) must throw a " + "ConstraintViolationExcpetion or a ValueFormatException if " + "the type parameter and the type of the property do not match."); } catch (ConstraintViolationException e) { // success } catch (ValueFormatException 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."); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -