use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class CreditCardAction method setUp.
protected void setUp() throws Exception {
super.setUp();
validator = new CreditCardValidator();
action = new CreditCardAction();
TextProviderFactory tpf = container.getInstance(TextProviderFactory.class);
context = new DummyValidatorContext(action, tpf);
validator.setValidatorContext(context);
ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
valueStack.push(action);
validator.setValueStack(valueStack);
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class DateRangeFieldValidatorTest method testPassValidation.
public void testPassValidation() throws Exception {
// given
ValidationAction action = prepareAction(createDate(2013, 6, 6));
ValidatorContext context = new DummyValidatorContext(action, tpf);
DateRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertEquals(0, context.getFieldErrors().size());
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class IntRangeFieldValidatorTest method testArrayOfIntValidation.
public void testArrayOfIntValidation() throws Exception {
// given
ValidationAction action = new ValidationAction();
action.setInts(new Integer[] { 99, 100, 101, 102 });
ValidatorContext context = new DummyValidatorContext(action, tpf);
IntRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.setMin(100);
validator.setMax(101);
validator.setFieldName("ints");
validator.setDefaultMessage("Max is ${max}, min is ${min} but value is ${currentValue}");
validator.validate(action);
// then
assertEquals(1, context.getFieldErrors().size());
assertEquals(2, context.getFieldErrors().get("ints").size());
assertEquals("Max is 101, min is 100 but value is 99", context.getFieldErrors().get("ints").get(0));
assertEquals("Max is 101, min is 100 but value is 102", context.getFieldErrors().get("ints").get(1));
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class IntRangeFieldValidatorTest method testPassValidation.
public void testPassValidation() throws Exception {
// given
ValidationAction action = prepareAction(100);
ValidatorContext context = new DummyValidatorContext(action, tpf);
IntRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
use of com.opensymphony.xwork2.validator.DummyValidatorContext in project struts by apache.
the class IntRangeFieldValidatorTest method testMinValidation.
public void testMinValidation() throws Exception {
// given
ValidationAction action = prepareAction(98);
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 98", context.getFieldErrors().get("intRange").get(0));
}
Aggregations