Search in sources :

Example 1 with ShortRangeFieldValidator

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));
}
Also used : DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext) ValidatorContext(com.opensymphony.xwork2.validator.ValidatorContext) DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext)

Example 2 with ShortRangeFieldValidator

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;
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) ValueStackFactory(com.opensymphony.xwork2.util.ValueStackFactory)

Example 3 with ShortRangeFieldValidator

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));
}
Also used : DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext) ValidatorContext(com.opensymphony.xwork2.validator.ValidatorContext) DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext)

Example 4 with ShortRangeFieldValidator

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);
}
Also used : DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext) ValidatorContext(com.opensymphony.xwork2.validator.ValidatorContext) DummyValidatorContext(com.opensymphony.xwork2.validator.DummyValidatorContext)

Aggregations

DummyValidatorContext (com.opensymphony.xwork2.validator.DummyValidatorContext)3 ValidatorContext (com.opensymphony.xwork2.validator.ValidatorContext)3 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)1