Search in sources :

Example 31 with ValueFormatException

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

the class SimpleValueFactoryTest method testDecimal.

public void testDecimal() throws RepositoryException {
    BigDecimal a = new BigDecimal(1234567890);
    Value value = factory.createValue(a);
    assertEquals(PropertyType.DECIMAL, value.getType());
    assertEquals(value, factory.createValue(a));
    try {
        value.getBoolean();
        fail();
    } catch (ValueFormatException e) {
    }
    assertEquals(a.longValue(), value.getDate().getTimeInMillis());
    assertEquals(a, value.getDecimal());
    assertEquals(a.doubleValue(), value.getDouble());
    assertEquals(a.longValue(), value.getLong());
    assertEquals(a.toString(), value.getString());
// TODO: binary representation
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) BigDecimal(java.math.BigDecimal)

Example 32 with ValueFormatException

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

the class SimpleValueFactoryTest method testLong.

public void testLong() throws RepositoryException {
    long a = 1234567890;
    Value value = factory.createValue(a);
    assertEquals(PropertyType.LONG, value.getType());
    assertEquals(value, factory.createValue(a));
    try {
        value.getBoolean();
        fail();
    } catch (ValueFormatException e) {
    }
    assertEquals(a, value.getDate().getTimeInMillis());
    assertEquals(new BigDecimal(a), value.getDecimal());
    assertEquals((double) a, value.getDouble());
    assertEquals(a, value.getLong());
    assertEquals(Long.toString(a), value.getString());
// TODO: binary representation
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) BigDecimal(java.math.BigDecimal)

Example 33 with ValueFormatException

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

the class SimpleValueFactoryTest method testBoolean.

public void testBoolean() throws RepositoryException {
    Value value = factory.createValue(true);
    assertEquals(PropertyType.BOOLEAN, value.getType());
    assertEquals(value, factory.createValue(true));
    assertTrue(value.getBoolean());
    try {
        value.getDate();
        fail();
    } catch (ValueFormatException e) {
    }
    try {
        value.getDecimal();
        fail();
    } catch (ValueFormatException e) {
    }
    try {
        value.getDouble();
        fail();
    } catch (ValueFormatException e) {
    }
    try {
        value.getLong();
        fail();
    } catch (ValueFormatException e) {
    }
    assertEquals(Boolean.TRUE.toString(), value.getString());
// TODO: binary representation
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 34 with ValueFormatException

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

the class DoublePropertyTest method testGetBoolean.

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

Example 35 with ValueFormatException

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

the class NamePropertyTest method testGetLong.

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

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