use of javax.jcr.Property in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testCalendar.
/**
* Tests if setValue(Calendar) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testCalendar() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(Calendar.getInstance());
fail("Property.setValue(Calendar) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class SetValueConstraintViolationExceptionTest method testDoubleProperty.
/**
* Tests if setValue(Double value) and setValue(Value value) where value is
* a DoubleValue throw a ConstraintViolationException if the change would
* violate a value constraint
*/
public void testDoubleProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.DOUBLE, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
}
// find a Value that does not satisfy the ValueConstraints of propDef
Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (valueNotSatisfied == null) {
throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
}
// find a Value that does satisfy the ValueConstraints of propDef
Value valueSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, true);
if (valueSatisfied == null) {
throw new NotExecutableException("The value constraints do not allow any value.");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
// and add a property with constraints to this node
Node node;
Property prop;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
prop = node.setProperty(propDef.getName(), valueSatisfied);
testRootNode.getSession().save();
} catch (ConstraintViolationException e) {
// implementation specific constraints do not allow to set up test environment
throw new NotExecutableException("Not able to create required test items.");
}
// test of signature setValue(double value)
try {
prop.setValue(valueNotSatisfied.getDouble());
node.save();
fail("setValue(double value) must throw a ConstraintViolationException " + "if the change would violate a node type constraint " + "either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
// test of signature setValue(Value value)
try {
prop.setValue(valueNotSatisfied);
node.save();
fail("setValue(Value value) must throw a ConstraintViolationException " + "if the change would violate a node type constraint " + "either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class SetPropertyAssumeTypeTest method testValueAssumeTypeOfValue.
/**
* 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());
}
use of javax.jcr.Property in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testLong.
/**
* Tests if setValue(long) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testLong() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(123);
fail("Property.setValue(long) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
use of javax.jcr.Property in project jackrabbit by apache.
the class SetValueValueFormatExceptionTest method testDouble.
/**
* Tests if setValue(double) throws a ValueFormatException immediately (not
* on save) if a conversion fails.
*/
public void testDouble() throws NotExecutableException, RepositoryException {
Property booleanProperty = createProperty(PropertyType.BOOLEAN, false);
try {
booleanProperty.setValue(1.23);
fail("Property.setValue(double) must throw a ValueFormatException " + "immediately if a conversion fails.");
} catch (ValueFormatException e) {
// success
}
}
Aggregations