Search in sources :

Example 1 with DateRangeFieldValidator

use of com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator in project struts by apache.

the class DateRangeValidatorTest method testGetSetMinMax.

public void testGetSetMinMax() throws Exception {
    DateRangeFieldValidator val = new DateRangeFieldValidator();
    Date max = new Date();
    val.setMax(max);
    assertEquals(max, val.getMax());
    Date min = new Date();
    val.setMin(min);
    assertEquals(min, val.getMin());
}
Also used : DateRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)

Example 2 with DateRangeFieldValidator

use of com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator 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 3 with DateRangeFieldValidator

use of com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator in project struts by apache.

the class AnnotationActionValidatorManagerTest method no_testGetValidatorsFromInterface.

public void no_testGetValidatorsFromInterface() {
    List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction3.class, alias);
    // 17 in the class hierarchy + 1 in the interface + 1 in interface alias
    assertEquals(19, validatorList.size());
    final FieldValidator v = (FieldValidator) validatorList.get(0);
    assertEquals("bar", v.getFieldName());
    assertTrue(v instanceof RequiredFieldValidator);
    final FieldValidator v1 = (FieldValidator) validatorList.get(1);
    assertEquals("bar", v1.getFieldName());
    assertTrue(v1 instanceof IntRangeFieldValidator);
    final FieldValidator vdouble = (FieldValidator) validatorList.get(2);
    assertEquals("percentage", vdouble.getFieldName());
    assertTrue(vdouble instanceof DoubleRangeFieldValidator);
    final FieldValidator v2 = (FieldValidator) validatorList.get(3);
    assertEquals("baz", v2.getFieldName());
    assertTrue(v2 instanceof IntRangeFieldValidator);
    final FieldValidator v3 = (FieldValidator) validatorList.get(4);
    assertEquals("date", v3.getFieldName());
    assertTrue(v3 instanceof DateRangeFieldValidator);
    // action-level validator comes first
    final Validator v4 = (Validator) validatorList.get(5);
    assertTrue(v4 instanceof ExpressionValidator);
    // action-level validator comes first
    final Validator v5 = (Validator) validatorList.get(6);
    assertTrue(v5 instanceof ExpressionValidator);
    // action-level validator comes first
    final Validator v6 = (Validator) validatorList.get(7);
    assertTrue(v6 instanceof ExpressionValidator);
    // action-level validator comes first
    final Validator v7 = (Validator) validatorList.get(8);
    assertTrue(v7 instanceof ExpressionValidator);
    // action-level validator comes first
    final Validator v8 = (Validator) validatorList.get(9);
    assertTrue(v8 instanceof ExpressionValidator);
    final FieldValidator v9 = (FieldValidator) validatorList.get(10);
    assertEquals("datefield", v9.getFieldName());
    assertTrue(v9 instanceof DateRangeFieldValidator);
    final FieldValidator v10 = (FieldValidator) validatorList.get(11);
    assertEquals("emailaddress", v10.getFieldName());
    assertTrue(v10 instanceof EmailValidator);
    final FieldValidator v11 = (FieldValidator) validatorList.get(12);
    assertEquals("intfield", v11.getFieldName());
    assertTrue(v11 instanceof IntRangeFieldValidator);
    final FieldValidator v12 = (FieldValidator) validatorList.get(13);
    assertEquals("customfield", v12.getFieldName());
    assertTrue(v12 instanceof RequiredFieldValidator);
    final FieldValidator v13 = (FieldValidator) validatorList.get(14);
    assertEquals("stringisrequired", v13.getFieldName());
    assertTrue(v13 instanceof RequiredStringValidator);
    final FieldValidator v14 = (FieldValidator) validatorList.get(15);
    assertEquals("needstringlength", v14.getFieldName());
    assertTrue(v14 instanceof StringLengthFieldValidator);
    final FieldValidator v15 = (FieldValidator) validatorList.get(16);
    assertEquals("hreflocation", v15.getFieldName());
    assertTrue(v15 instanceof URLValidator);
    final FieldValidator v16 = (FieldValidator) validatorList.get(17);
    assertEquals("data", v16.getFieldName());
    assertTrue(v16 instanceof RequiredFieldValidator);
    final FieldValidator v17 = (FieldValidator) validatorList.get(18);
    assertEquals("data", v17.getFieldName());
    assertTrue(v17 instanceof RequiredStringValidator);
}
Also used : EmailValidator(com.opensymphony.xwork2.validator.validators.EmailValidator) StringLengthFieldValidator(com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator) URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator) DateRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator) StringLengthFieldValidator(com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator) DoubleRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator) IntRangeFieldValidator(com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator) RequiredFieldValidator(com.opensymphony.xwork2.validator.validators.RequiredFieldValidator) ExpressionValidator(com.opensymphony.xwork2.validator.validators.ExpressionValidator) List(java.util.List) IntRangeFieldValidator(com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator) DoubleRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator) RequiredFieldValidator(com.opensymphony.xwork2.validator.validators.RequiredFieldValidator) DateRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator) RequiredStringValidator(com.opensymphony.xwork2.validator.validators.RequiredStringValidator) RequiredStringValidator(com.opensymphony.xwork2.validator.validators.RequiredStringValidator) DateRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator) URLValidator(com.opensymphony.xwork2.validator.validators.URLValidator) ExpressionValidator(com.opensymphony.xwork2.validator.validators.ExpressionValidator) StringLengthFieldValidator(com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator) EmailValidator(com.opensymphony.xwork2.validator.validators.EmailValidator) DoubleRangeFieldValidator(com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator) IntRangeFieldValidator(com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator) RequiredFieldValidator(com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)

Example 4 with DateRangeFieldValidator

use of com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator in project struts by apache.

the class DateRangeFieldValidatorTest method prepareValidator.

private DateRangeFieldValidator prepareValidator(ValidationAction action, ValidatorContext context) {
    ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack();
    valueStack.getActionContext().withLocale(new Locale("de"));
    valueStack.push(action);
    DateRangeFieldValidator validator = new DateRangeFieldValidator();
    validator.setValueStack(valueStack);
    validator.setMaxExpression("${dateMaxValue}");
    validator.setMinExpression("${dateMinValue}");
    validator.setValidatorContext(context);
    validator.setFieldName("dateRange");
    validator.setDefaultMessage("Max is ${dateMaxValue}, min is ${dateMinValue} but value is ${dateRange}");
    return validator;
}
Also used : Locale(java.util.Locale) ValueStack(com.opensymphony.xwork2.util.ValueStack) ValueStackFactory(com.opensymphony.xwork2.util.ValueStackFactory)

Example 5 with DateRangeFieldValidator

use of com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator in project struts by apache.

the class DateRangeFieldValidatorTest method testMaxValidation.

public void testMaxValidation() throws Exception {
    // given
    ValidationAction action = prepareAction(createDate(2014, Calendar.APRIL, 4));
    ValidatorContext context = new DummyValidatorContext(action, tpf);
    DateRangeFieldValidator validator = prepareValidator(action, context);
    // when
    validator.validate(action);
    // then
    assertEquals(1, context.getFieldErrors().size());
    assertEquals("Max is 12.12.13, min is 01.01.13 but value is 04.04.14", context.getFieldErrors().get("dateRange").get(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 DateRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 ValueStackFactory (com.opensymphony.xwork2.util.ValueStackFactory)1 DoubleRangeFieldValidator (com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator)1 EmailValidator (com.opensymphony.xwork2.validator.validators.EmailValidator)1 ExpressionValidator (com.opensymphony.xwork2.validator.validators.ExpressionValidator)1 IntRangeFieldValidator (com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator)1 RequiredFieldValidator (com.opensymphony.xwork2.validator.validators.RequiredFieldValidator)1 RequiredStringValidator (com.opensymphony.xwork2.validator.validators.RequiredStringValidator)1 StringLengthFieldValidator (com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator)1 URLValidator (com.opensymphony.xwork2.validator.validators.URLValidator)1 List (java.util.List)1 Locale (java.util.Locale)1