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