use of com.github.bordertech.wcomponents.validator.AbstractFieldValidator in project wcomponents by BorderTech.
the class AbstractInput_Test method testValidateComponent.
@Test
public void testValidateComponent() {
// No Validation
AbstractInput input = new MyInput();
List<Diagnostic> diags = new ArrayList<>();
input.validate(diags);
Assert.assertTrue("Input with no validation should return an empty daignostics list", diags.isEmpty());
// Mandatory with no value - Validation Error
input = new MyInput();
diags.clear();
input.setMandatory(true);
input.validate(diags);
Assert.assertEquals("Mandatory input with no value should return a diagnostic message", 1, diags.size());
// Switch to ReadOnly and should have no validation errors
input.setReadOnly(true);
diags.clear();
input.validate(diags);
Assert.assertTrue("Mandatory input that is ReadOnly with no value should return an empty diagnostic message", diags.isEmpty());
// Mandatory with a value - No Validation Errors
input = new MyInput();
diags.clear();
input.setMandatory(true);
input.setData("value");
input.validate(diags);
Assert.assertTrue("Mandatory input with a value should return an empty daignostics list", diags.isEmpty());
// Custom Validator - Validation Error
FieldValidator validator = new AbstractFieldValidator() {
@Override
protected boolean isValid() {
return false;
}
};
input = new MyInput();
diags.clear();
input.addValidator(validator);
input.validate(diags);
Assert.assertEquals("Input with custom validator should return a diagnostic message", 1, diags.size());
}
use of com.github.bordertech.wcomponents.validator.AbstractFieldValidator in project wcomponents by BorderTech.
the class AbstractInput_Test method testValidatorsAccessors.
@Test
public void testValidatorsAccessors() {
AbstractInput input = new MyInput();
Assert.assertFalse("Default input should have no validators", input.getValidators().hasNext());
// Add validator
FieldValidator validator = new AbstractFieldValidator() {
@Override
protected boolean isValid() {
return false;
}
};
input.addValidator(validator);
Assert.assertEquals("Validator Iterator did not contain the valid validator", validator, input.getValidators().next());
}
Aggregations