Search in sources :

Example 91 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class ReferencePropertyTest method testGetBoolean.

/**
 * Tests failure of conversion from Reference type to Boolean type.
 */
public void testGetBoolean() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getBoolean();
        fail("Conversion from a Reference value to a Boolean value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 92 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class QValueTest method testGetLongOnBooleanValue.

public void testGetLongOnBooleanValue() throws RepositoryException {
    try {
        QValue v = factory.create(true);
        v.getLong();
        fail("'true' cannot be converted to a valid long value.");
    } catch (ValueFormatException e) {
    // ok
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ValueFormatException(javax.jcr.ValueFormatException)

Example 93 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class QValueTest method testGetDoubleOnBooleanValue.

public void testGetDoubleOnBooleanValue() throws RepositoryException {
    try {
        QValue v = factory.create(true);
        v.getDouble();
        fail("'true' cannot be converted to a valid double value.");
    } catch (ValueFormatException e) {
    // ok
    }
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ValueFormatException(javax.jcr.ValueFormatException)

Example 94 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class ValueHelper method convert.

/**
 * @param srcValues
 * @param targetType
 * @param factory
 * @throws ValueFormatException
 * @throws IllegalArgumentException
 * @see #convert(Value, int, ValueFactory)
 */
public static Value[] convert(Value[] srcValues, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException {
    if (srcValues == null) {
        return null;
    }
    Value[] newValues = new Value[srcValues.length];
    int srcValueType = PropertyType.UNDEFINED;
    for (int i = 0; i < srcValues.length; i++) {
        if (srcValues[i] == null) {
            newValues[i] = null;
            continue;
        }
        // check type of values
        if (srcValueType == PropertyType.UNDEFINED) {
            srcValueType = srcValues[i].getType();
        } else if (srcValueType != srcValues[i].getType()) {
            // inhomogeneous types
            String msg = "inhomogeneous type of values";
            throw new ValueFormatException(msg);
        }
        newValues[i] = convert(srcValues[i], targetType, factory);
    }
    return newValues;
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 95 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class SetValueValueFormatExceptionTest method testStringArray.

/**
 * Tests if setValue(String[]) throws a ValueFormatException immediately (not
 * on save) if a conversion fails.
 */
public void testStringArray() throws NotExecutableException, RepositoryException {
    Property dateProperty = createProperty(PropertyType.DATE, true);
    try {
        String[] values = new String[] { "abc" };
        dateProperty.setValue(values);
        fail("Property.setValue(String[]) must throw a ValueFormatException " + "immediately if a conversion fails.");
    } catch (ValueFormatException e) {
    // success
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Aggregations

ValueFormatException (javax.jcr.ValueFormatException)106 Value (javax.jcr.Value)53 Property (javax.jcr.Property)34 RepositoryException (javax.jcr.RepositoryException)16 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 Calendar (java.util.Calendar)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 Node (javax.jcr.Node)10 QValue (org.apache.jackrabbit.spi.QValue)10 PathNotFoundException (javax.jcr.PathNotFoundException)6 Name (org.apache.jackrabbit.spi.Name)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 InputStream (java.io.InputStream)4 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 Path (org.apache.jackrabbit.spi.Path)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3