Search in sources :

Example 46 with ValueFormatException

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

the class SetValueValueFormatExceptionTest method testString.

/**
 * Tests if setValue(String) throws a ValueFormatException immediately (not
 * on save) if a conversion fails.
 */
public void testString() throws NotExecutableException, RepositoryException {
    Property dateProperty = createProperty(PropertyType.DATE, false);
    try {
        dateProperty.setValue("abc");
        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)

Example 47 with ValueFormatException

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

the class ParserTest method fuzz.

public void fuzz(String query) throws Exception {
    for (int i = 0; i < 100; i++) {
        StringBuffer buff = new StringBuffer(query);
        int changes = 1 + (int) Math.abs(random.nextGaussian() * 2);
        for (int j = 0; j < changes; j++) {
            char newChar;
            if (random.nextBoolean()) {
                String s = "<>_.+\"*%&/()=?[]{}_:;,.-1234567890.qersdf";
                newChar = s.charAt(random.nextInt(s.length()));
            } else {
                newChar = (char) random.nextInt(255);
            }
            int pos = random.nextInt(buff.length());
            if (random.nextBoolean()) {
                // 50%: change one character
                buff.setCharAt(pos, newChar);
            } else {
                if (random.nextBoolean()) {
                    // 25%: delete one character
                    buff.deleteCharAt(pos);
                } else {
                    // 25%: insert one character
                    buff.insert(pos, newChar);
                }
            }
        }
        String q = buff.toString();
        try {
            parser.createQueryObjectModel(q);
        } catch (ValueFormatException e) {
        // OK
        } catch (InvalidQueryException e) {
        // OK
        } catch (NamespaceException e) {
        // OK?
        } catch (Throwable t) {
            t.printStackTrace();
            assertTrue("Unexpected exception for query " + q + ": " + t, false);
        }
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) Constraint(javax.jcr.query.qom.Constraint) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 48 with ValueFormatException

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

the class QValueTest method testGetDecimalOnBooleanValue.

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

Example 49 with ValueFormatException

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

the class QValueTest method testReadBooleanAsLong.

public void testReadBooleanAsLong() throws RepositoryException {
    try {
        QValue v = factory.create(true);
        v.getLong();
    } catch (ValueFormatException e) {
        // ok
        return;
    }
    assertTrue("Cannot convert value to long", false);
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) ValueFormatException(javax.jcr.ValueFormatException)

Example 50 with ValueFormatException

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

the class SingleValuedPropertyTest method testGetLengthsFromSingleValued.

/**
 * Tests if Property.getLengths() fails for single value property.
 */
public void testGetLengthsFromSingleValued() throws RepositoryException, NotExecutableException {
    Property singleProp = PropertyUtil.searchSingleValuedProperty(testRootNode);
    if (singleProp == null) {
        throw new NotExecutableException("No single valued property found.");
    }
    try {
        singleProp.getLengths();
        fail("Property.getLengths() called on a single value property must fail (ValueFormatException).");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) 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