use of com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator 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.validators.LongRangeFieldValidator 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.validators.LongRangeFieldValidator in project struts by apache.
the class LongRangeFieldValidatorTest method prepareValidator.
private LongRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext context) {
ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
valueStack.push(action);
LongRangeFieldValidator validator = new LongRangeFieldValidator();
validator.setValueStack(valueStack);
validator.setMaxExpression("${longMaxValue}");
validator.setMinExpression("${longMinValue}");
validator.setValidatorContext(context);
validator.setFieldName("longRange");
validator.setDefaultMessage("Max is ${longMaxValue}, min is ${longMinValue} but value is ${longRange}");
return validator;
}
use of com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator in project struts by apache.
the class LongRangeFieldValidatorTest method testPassValidation.
public void testPassValidation() throws Exception {
// given
ValidationAction action = prepareAction(100);
ValidatorContext context = new DummyValidatorContext(action, tpf);
LongRangeFieldValidator validator = prepareValidator(action, context);
// when
validator.validate(action);
// then
assertTrue(context.getFieldErrors().size() == 0);
}
Aggregations