use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class IntRangeFieldValidatorTest method testMaxValidation.
public void testMaxValidation() throws Exception {
// given
ValidationAction action = prepareAction(102);
ValidatorContext context = new DummyValidatorContext(action, tpf);
IntRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals("Max is 101, min is 99 but value is 102", context.getFieldErrors().get("intRange").get(0));
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class AnnotationActionValidatorManagerTest method testActionLevelShortCircuit.
public void testActionLevelShortCircuit() throws Exception {
List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
assertEquals(10, validatorList.size());
AnnotationUser user = new AnnotationUser();
// all fields will trigger error, but sc of action-level, cause it to not appear
user.setName(null);
user.setEmail("rainerh(at)example.com");
user.setEmail("rainer_h(at)example.com");
ValidatorContext context = new DummyValidatorContext(user, tpf);
annotationActionValidatorManager.validate(user, null, context);
// check field level errors
// shouldn't have any because action error prevents validation of anything else
List l = context.getFieldErrors().get("email2");
assertNull(l);
// check action errors
assertTrue(context.hasActionErrors());
l = (List) context.getActionErrors();
assertNotNull(l);
// we only get one, because AnnotationUserMarker-validation.xml action-level validator
// already sc it :-)
assertEquals(1, l.size());
assertEquals("Email not the same as email2", l.get(0));
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class AnnotationValidationConfigurationBuilderTest method testValidationAnnotation.
public void testValidationAnnotation() throws Exception {
// given
AnnotationActionValidatorManager manager = createValidationManager(AnnotationValidationAction.class, Locale.US);
// when
List<Validator> validators = manager.getValidators(AnnotationValidationAction.class, null);
// then
assertEquals(validators.size(), 18);
for (Validator validator : validators) {
validate(validator);
}
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class LongRangeFieldValidatorTest method testMaxValidation.
public void testMaxValidation() throws Exception {
// given
ValidationAction action = prepareAction(102);
ValidatorContext context = new DummyValidatorContext(action, tpf);
LongRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals("Max is 101, min is 99 but value is 102", context.getFieldErrors().get("longRange").get(0));
}
use of com.opensymphony.xwork2.validator.Validator in project struts by apache.
the class LongRangeFieldValidatorTest method testMinValidation.
public void testMinValidation() throws Exception {
// given
ValidationAction action = prepareAction(98);
ValidatorContext context = new DummyValidatorContext(action, tpf);
LongRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals("Max is 101, min is 99 but value is 98", context.getFieldErrors().get("longRange").get(0));
}
Aggregations