use of com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator in project struts by apache.
the class ShortRangeFieldValidatorTest method testMinValidation.
public void testMinValidation() throws Exception {
// given
ValidationAction action = prepareAction((short) 1);
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 1", context.getFieldErrors().get("shortRange").get(0));
}
use of com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator in project struts by apache.
the class ShortRangeFieldValidatorTest method prepareValidator.
private ShortRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext context) {
ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
valueStack.push(action);
ShortRangeFieldValidator validator = new ShortRangeFieldValidator();
validator.setValueStack(valueStack);
validator.setMaxExpression("${shortMaxValue}");
validator.setMinExpression("${shortMinValue}");
validator.setValidatorContext(context);
validator.setFieldName("shortRange");
validator.setDefaultMessage("Max is ${shortMaxValue}, min is ${shortMinValue} but value is ${shortRange}");
return validator;
}
use of com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator 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.validators.ShortRangeFieldValidator 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