Search in sources :

Example 36 with ValueFormatException

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

the class NamePropertyTest method testGetNode.

/**
 * Since JCR 2.0 a path property can be dereferenced if it points to a
 * Node.
 * TODO: create several tests out of this one
 */
public void testGetNode() throws RepositoryException {
    if (!multiple) {
        String path = prop.getString();
        if (prop.getParent().hasNode(path)) {
            Node n = prop.getNode();
            assertEquals("The name of the dereferenced property must be equal to the value", path, n.getName());
        } else {
            try {
                prop.getNode();
                fail("Calling Property.getNode() for a NAME value that doesn't have a corresponding Node, ItemNotFoundException is expected");
            } catch (ItemNotFoundException e) {
            // success.
            }
        }
    } else {
        try {
            prop.getNode();
            fail("Property.getNode() called on a multivalue property " + "should throw a ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : Node(javax.jcr.Node) ValueFormatException(javax.jcr.ValueFormatException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 37 with ValueFormatException

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

the class BinaryPropertyTest method testGetDouble.

/**
 * Tests conversion from Binary type to Double type. This is done via String
 * conversion.
 */
public void testGetDouble() throws RepositoryException {
    Value val = PropertyUtil.getValue(prop);
    String str = val.getString();
    // double
    try {
        Double.parseDouble(str);
        double d = val.getDouble();
        assertEquals("Wrong conversion from Binary to Double", new Double(d), Double.valueOf(str));
    } catch (NumberFormatException nfe) {
        try {
            val.getDouble();
            fail("Conversion from malformed Binary to Double " + "should throw ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 38 with ValueFormatException

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

the class DatePropertyTest method testValue.

/**
 * Tests that Property.getDate() delivers the same as Value.getDate() and
 * that in case of a multivalue property a ValueFormatException is thrown.
 */
public void testValue() throws RepositoryException {
    if (multiple) {
        try {
            prop.getDate();
            fail("Property.getDate() called on a multivalue property " + "should throw a ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    } else {
        Calendar calendar = prop.getValue().getDate();
        Calendar calendar2 = prop.getDate();
        assertEquals("Value.getDate() and Property.getDate() return different values.", calendar, calendar2);
    }
}
Also used : Calendar(java.util.Calendar) ValueFormatException(javax.jcr.ValueFormatException)

Example 39 with ValueFormatException

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

the class StringPropertyTest method testGetDouble.

/**
 * Tests conversion from String type to Double type.
 */
public void testGetDouble() throws RepositoryException {
    Value val = PropertyUtil.getValue(prop);
    String str = val.getString();
    // double
    try {
        Double.parseDouble(str);
        double d = val.getDouble();
        assertEquals("Wrong conversion from String to Double.", new Double(d), Double.valueOf(str));
    } catch (NumberFormatException nfe) {
        try {
            val.getDouble();
            fail("Conversion from malformed String to Double should throw ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 40 with ValueFormatException

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

the class StringPropertyTest method testGetDate.

/**
 * Tests conversion from String type to Date type.
 */
public void testGetDate() throws RepositoryException {
    Value val = PropertyUtil.getValue(prop);
    if (PropertyUtil.isDateFormat(val.getString())) {
        val.getDate();
    } else {
        try {
            val.getDate();
            fail("Conversion from a malformed String to a Date " + "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