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
}
}
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
}
}
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
}
}
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;
}
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
}
}
Aggregations