Search in sources :

Example 1 with Constraint

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
    }
}
Also used : Constraint(grails.validation.Constraint)

Example 2 with Constraint

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));
}
Also used : Constraint(grails.validation.Constraint)

Example 3 with Constraint

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
    }
}
Also used : Constraint(grails.validation.Constraint) TestClass(grails.validation.TestClass)

Example 4 with Constraint

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));
}
Also used : Constraint(grails.validation.Constraint)

Example 5 with Constraint

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));
}
Also used : Constraint(grails.validation.Constraint)

Aggregations

Constraint (grails.validation.Constraint)7 ConstrainedProperty (grails.validation.ConstrainedProperty)1 TestClass (grails.validation.TestClass)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1