use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class AnnotationActionValidatorManagerTest method testShortCircuitNoErrors.
public void testShortCircuitNoErrors() {
// get validators
List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
assertEquals(10, validatorList.size());
try {
AnnotationUser user = new AnnotationUser();
user.setName("Mark");
user.setEmail("mark@mycompany.com");
user.setEmail2("mark@mycompany.com");
ValidatorContext context = new DummyValidatorContext(user, tpf);
annotationActionValidatorManager.validate(user, null, context);
assertFalse(context.hasErrors());
} catch (ValidationException ex) {
ex.printStackTrace();
fail("Validation error: " + ex.getMessage());
}
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext 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.DummyValidatorContext 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));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RequiredFieldValidatorTest method testNullObject.
@Test
public void testNullObject() throws Exception {
// given
RequiredFieldValidator rfv = container.inject(RequiredFieldValidator.class);
rfv.setValueStack(ActionContext.getContext().getValueStack());
rfv.setFieldName("stringValue");
rfv.setDefaultMessage("${fieldName} field is required!");
ValidationAction action = new ValidationAction();
DummyValidatorContext context = new DummyValidatorContext(action, container.getInstance(TextProviderFactory.class));
rfv.setValidatorContext(context);
// when
rfv.validate(action);
// then
assertTrue(context.hasFieldErrors());
assertEquals(1, context.getFieldErrors().size());
assertNotNull(context.getFieldErrors().get("stringValue"));
assertEquals("stringValue field is required!", context.getFieldErrors().get("stringValue").get(0));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RequiredFieldValidatorTest method testCollectionObject.
@Test
public void testCollectionObject() throws Exception {
// given
RequiredFieldValidator rfv = container.inject(RequiredFieldValidator.class);
rfv.setValueStack(ActionContext.getContext().getValueStack());
rfv.setFieldName("shorts");
rfv.setDefaultMessage("${fieldName} field is required!");
ValidationAction action = new ValidationAction();
action.setShorts(new ArrayList<Short>());
DummyValidatorContext context = new DummyValidatorContext(action, container.getInstance(TextProviderFactory.class));
rfv.setValidatorContext(context);
// when
rfv.validate(action);
// then
assertTrue(context.hasFieldErrors());
assertEquals(1, context.getFieldErrors().size());
assertNotNull(context.getFieldErrors().get("shorts"));
assertEquals("shorts field is required!", context.getFieldErrors().get("shorts").get(0));
}
Aggregations