use of grails.validation.Constraint in project grails-core by grails.
the class ScaleConstraintTests method testValidationOnInvalidField.
public void testValidationOnInvalidField() {
Constraint constraint = getConstraint("testString", 2);
try {
proceedValidation(constraint, "123");
fail("ScaleConstraint must throw an exception when applied to field with unsupported type");
} catch (IllegalArgumentException iae) {
// Great
}
}
use of grails.validation.Constraint in project grails-core by grails.
the class ScaleConstraintTests method testDouble.
private void testDouble(int scale, double value, double result) {
Constraint constraint = getConstraint("testDouble", scale);
assertEquals(Double.valueOf(result), proceedValidation(constraint, value));
}
use of grails.validation.Constraint in project grails-core by grails.
the class ValidatorConstraintTests method testConstraintCreation.
public void testConstraintCreation() {
Constraint validatorConstraint = new ValidatorConstraint();
assertEquals(ConstrainedProperty.VALIDATOR_CONSTRAINT, validatorConstraint.getName());
assertTrue(validatorConstraint.supports(TestClass.class));
assertFalse(validatorConstraint.supports(null));
validatorConstraint.setOwningClass(TestClass.class);
validatorConstraint.setPropertyName(PROP_NAME);
try {
getConstraint("testString", "Test");
fail("ValidatorConstraint must throw an exception for non-closure parameter.");
} catch (IllegalArgumentException iae) {
// Great since validator constraint only applicable for Closure parameter
}
try {
getConstraint("{ param1, param2, param3, param4 -> return true}");
fail("ValidatorConstraint must throw exception about closure with more that 3 params");
} catch (IllegalArgumentException iae) {
// Great since validator constraint only applicable for Closure's with 1, 2 or 3 params
}
}
use of grails.validation.Constraint in project grails-core by grails.
the class ScaleConstraintTests method testNullPasses.
public void testNullPasses() {
Constraint constraint = getConstraint("testBigDecimal", 2);
assertEquals(null, proceedValidation(constraint, null));
}
use of grails.validation.Constraint in project grails-core by grails.
the class ScaleConstraintTests method testFloat.
private void testFloat(int scale, float value, float result) {
Constraint constraint = getConstraint("testFloat", scale);
assertEquals(result, proceedValidation(constraint, value));
}
Aggregations