Search in sources :

Example 26 with Validator

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

Example 27 with Validator

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

Example 28 with Validator

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

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

Example 30 with Validator

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

Aggregations

ValueStack (com.opensymphony.xwork2.util.ValueStack)19 DummyValidatorContext (com.opensymphony.xwork2.validator.DummyValidatorContext)18 ValidatorContext (com.opensymphony.xwork2.validator.ValidatorContext)18 URLValidator (com.opensymphony.xwork2.validator.validators.URLValidator)16 RegexFieldValidator (com.opensymphony.xwork2.validator.validators.RegexFieldValidator)12 EmailValidator (com.opensymphony.xwork2.validator.validators.EmailValidator)9 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)7 RequiredStringValidator (com.opensymphony.xwork2.validator.validators.RequiredStringValidator)6 HashMap (java.util.HashMap)6 ActionSupport (com.opensymphony.xwork2.ActionSupport)5 Validator (com.opensymphony.xwork2.validator.Validator)5 ExpressionValidator (com.opensymphony.xwork2.validator.validators.ExpressionValidator)5 VisitorFieldValidator (com.opensymphony.xwork2.validator.validators.VisitorFieldValidator)5 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)4 RequiredFieldValidator (com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)4 StringLengthFieldValidator (com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator)4 TextProviderFactory (com.opensymphony.xwork2.TextProviderFactory)3 ConversionErrorFieldValidator (com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator)3 DateRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)3 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)3