Search in sources :

Example 61 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.

the class SetValueConstraintViolationExceptionTest method testMultipleLongProperty.

/**
 * Tests if setValue(Value[] values) where values are of type LongValue
 * throw a ConstraintViolationException if the change would violate a value
 * constraint
 */
public void testMultipleLongProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.LONG, true, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple long 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 multiple long 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(), new Value[] { 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(Value value)
    try {
        prop.setValue(new Value[] { 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 62 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.

the class SetValueConstraintViolationExceptionTest method testDateProperty.

/**
 * Tests if setValue(Calendar value) and setValue(Value value) where value
 * is a DateValue throw a ConstraintViolationException if the change would
 * violate a value constraint
 */
public void testDateProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.DATE, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No date 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 date 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(Calendar value)
    try {
        prop.setValue(valueNotSatisfied.getDate());
        node.save();
        fail("setValue(Date 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 63 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.

the class SetValueConstraintViolationExceptionTest method testMultipleBinaryProperty.

/**
 * Tests if setValue(Value[] values) where values are of type BinaryValue
 * throw a ConstraintViolationException if the change would violate a value
 * constraint
 */
public void testMultipleBinaryProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BINARY, true, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No multiple binary 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 multiple binary 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(), new Value[] { 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.");
    }
    try {
        prop.setValue(new Value[] { valueNotSatisfied });
        node.save();
        fail("setValue(Value[] values) 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 64 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit by apache.

the class SetValueConstraintViolationExceptionTest method testBinaryProperty.

/**
 * Tests if setValue(InputStream value) and setValue(Value value) where
 * value is a BinaryValue throw a ConstraintViolationException if the change
 * would violate a value constraint
 */
public void testBinaryProperty() throws NotExecutableException, RepositoryException {
    // locate a PropertyDefinition with ValueConstraints
    PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BINARY, false, false, true, false);
    if (propDef == null) {
        throw new NotExecutableException("No binary property def with " + "testable value constraints has been found");
    }
    // find a Value that does not satisfy the ValueConstraints of propDef
    Value valueNotSatisfied1 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    Value valueNotSatisfied2 = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
    if (valueNotSatisfied1 == null || valueNotSatisfied2 == null) {
        throw new NotExecutableException("No binary 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(InputStream value)
    InputStream in = valueNotSatisfied1.getStream();
    try {
        prop.setValue(in);
        node.save();
        fail("setValue(InputStream value) must throw a ConstraintViolationException " + "if the change would violate a node type constraint " + "either immediately or on save");
    } catch (ConstraintViolationException e) {
    // success
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
    // test of signature setValue(Value value)
    try {
        prop.setValue(valueNotSatisfied2);
        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) InputStream(java.io.InputStream) Node(javax.jcr.Node) Value(javax.jcr.Value) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) IOException(java.io.IOException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Property(javax.jcr.Property)

Example 65 with ConstraintViolationException

use of javax.jcr.nodetype.ConstraintViolationException 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)

Aggregations

ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)180 Node (javax.jcr.Node)74 RepositoryException (javax.jcr.RepositoryException)40 Name (org.apache.jackrabbit.spi.Name)33 Value (javax.jcr.Value)31 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)28 Test (org.junit.Test)27 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)23 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)23 Session (javax.jcr.Session)18 ItemExistsException (javax.jcr.ItemExistsException)17 NodeState (org.apache.jackrabbit.core.state.NodeState)16 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)16 Property (javax.jcr.Property)14 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)14 ArrayList (java.util.ArrayList)13 NodeId (org.apache.jackrabbit.core.id.NodeId)13 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)13 NodeType (javax.jcr.nodetype.NodeType)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)12