use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class RequiredStringValidatorTest method testRequiredStringPass.
public void testRequiredStringPass() throws Exception {
// given
ValueStack valueStack = ActionContext.getContext().getValueStack();
ValidationAction action = new ValidationAction();
action.setStringValue("a string");
valueStack.push(action);
ValidatorContext context = new DummyValidatorContext(action, tpf);
RequiredStringValidator validator = new RequiredStringValidator();
validator.setValidatorContext(context);
validator.setFieldName("stringValue");
validator.setValueStack(valueStack);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class ShortRangeFieldValidatorTest method testMaxValidation.
public void testMaxValidation() throws Exception {
// given
ValidationAction action = prepareAction((short) 11);
ValidatorContext context = new DummyValidatorContext(action, tpf);
ShortRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 1);
assertEquals("Max is 10, min is 2 but value is 11", context.getFieldErrors().get("shortRange").get(0));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class ShortRangeFieldValidatorTest method testPassValidation.
public void testPassValidation() throws Exception {
// given
ValidationAction action = prepareAction((short) 5);
ValidatorContext context = new DummyValidatorContext(action, tpf);
ShortRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
Aggregations