Search in sources :

Example 66 with ValueFormatException

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

the class BinaryPropertyTest method testGetDate.

/**
 * Tests conversion from Binary type to Date type. This is done via String
 * conversion.
 */
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)

Example 67 with ValueFormatException

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

the class BinaryPropertyTest method testGetLong.

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

Example 68 with ValueFormatException

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

the class NodeAddMixinTest method testAddMixinReferencable.

/**
 * Tests if adding mix:referenceable automatically populates the jcr:uuid
 * value.
 */
public void testAddMixinReferencable() throws NotExecutableException, RepositoryException {
    // check if repository supports references
    checkMixReferenceable();
    // get session an create default node
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    ensureMixinType(node, mixReferenceable);
    // implementation specific: mixin may take effect only upon save
    testRootNode.getSession().save();
    // check that it did
    assertTrue(node.isNodeType(mixReferenceable));
    // (format of value is not defined so we can only test if not empty)
    try {
        String uuid = node.getProperty(jcrUUID).getValue().getString();
        // default value is null so check for null
        assertNotNull("Acessing jcr:uuid after assginment of mix:referencable returned null", uuid);
        // check if it was not set to an empty string
        assertTrue("Acessing jcr:uuid after assginment of mix:referencable returned an empty String!", uuid.length() > 0);
    } catch (ValueFormatException e) {
        // trying to access the uuid caused an exception
        fail("Acessing jcr:uuid after assginment of mix:referencable caused an ValueFormatException!");
    }
}
Also used : Node(javax.jcr.Node) ValueFormatException(javax.jcr.ValueFormatException)

Example 69 with ValueFormatException

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

the class NamePropertyTest method testGetBoolean.

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

Example 70 with ValueFormatException

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

the class NamePropertyTest method testGetDate.

/**
 * Tests failure of conversion from Name type to Date type.
 *
 * @throws RepositoryException
 */
public void testGetDate() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getDate();
        fail("Conversion from a Name value to a Date 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