use of com.opensymphony.xwork2.validator.Validator 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.Validator 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.Validator in project struts by apache.
the class IntRangeFieldValidatorTest method prepareValidator.
private IntRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext context) {
ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
valueStack.push(action);
IntRangeFieldValidator validator = new IntRangeFieldValidator();
validator.setValueStack(valueStack);
validator.setMaxExpression("${intMaxValue}");
validator.setMinExpression("${intMinValue}");
validator.setValidatorContext(context);
validator.setFieldName("intRange");
validator.setDefaultMessage("Max is ${intMaxValue}, min is ${intMinValue} but value is ${intRange}");
return validator;
}
use of com.opensymphony.xwork2.validator.Validator 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.Validator 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