Search in sources :

Example 81 with Property

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
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 82 with Property

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
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Property(javax.jcr.Property)

Example 83 with Property

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());
}
Also used : Property(javax.jcr.Property)

Example 84 with Property

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
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 85 with Property

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
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15