Search in sources :

Example 1 with AnnotatedTestBean

use of com.opensymphony.xwork2.AnnotatedTestBean in project struts by apache.

the class AnnotationActionValidatorManagerTest method testDefaultMessageInterpolation.

public void testDefaultMessageInterpolation() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotatedTestBean.class, "beanMessageBundle");
    assertEquals(3, validatorList.size());
    try {
        AnnotatedTestBean bean = new AnnotatedTestBean();
        bean.setName("foo");
        bean.setCount(99);
        ValidatorContext context = new DummyValidatorContext(bean, tpf);
        annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
        assertTrue(context.hasErrors());
        assertTrue(context.hasFieldErrors());
        List<String> l = context.getFieldErrors().get("count");
        assertNotNull(l);
        assertEquals(1, l.size());
        assertEquals("Smaller Invalid Count: 99", l.get(0));
    } catch (ValidationException ex) {
        ex.printStackTrace();
        fail("Validation error: " + ex.getMessage());
    }
}
Also used : AnnotatedTestBean(com.opensymphony.xwork2.AnnotatedTestBean) List(java.util.List)

Example 2 with AnnotatedTestBean

use of com.opensymphony.xwork2.AnnotatedTestBean in project struts by apache.

the class AnnotationActionValidatorManagerTest method testMessageInterpolation.

public void testMessageInterpolation() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotatedTestBean.class, "beanMessageBundle");
    assertEquals(3, validatorList.size());
    try {
        AnnotatedTestBean bean = new AnnotatedTestBean();
        bean.setName("foo");
        bean.setCount(150);
        ValidatorContext context = new DummyValidatorContext(bean, tpf);
        annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
        assertTrue(context.hasErrors());
        assertTrue(context.hasFieldErrors());
        List<String> l = context.getFieldErrors().get("count");
        assertNotNull(l);
        assertEquals(1, l.size());
        assertEquals("Count must be between 1 and 100, current value is 150.", l.get(0));
    } catch (ValidationException ex) {
        ex.printStackTrace();
        fail("Validation error: " + ex.getMessage());
    }
}
Also used : AnnotatedTestBean(com.opensymphony.xwork2.AnnotatedTestBean) List(java.util.List)

Example 3 with AnnotatedTestBean

use of com.opensymphony.xwork2.AnnotatedTestBean in project struts by apache.

the class AnnotationXWorkConverterTest method testFieldErrorMessageAddedForComplexProperty.

public void testFieldErrorMessageAddedForComplexProperty() {
    SimpleAnnotationAction action = new SimpleAnnotationAction();
    action.setBean(new AnnotatedTestBean());
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(action);
    Map<String, Object> ognlStackContext = stack.getContext();
    ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    ognlStackContext.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, "bean.birth");
    String[] value = new String[] { "invalid date" };
    assertEquals("Conversion should have failed.", OgnlRuntime.NoConversionPossible, converter.convertValue(ognlStackContext, action.getBean(), null, "birth", value, Date.class));
    stack.pop();
    Map<String, ConversionData> conversionErrors = stack.getActionContext().getConversionErrors();
    assertNotNull(conversionErrors);
    assertEquals(1, conversionErrors.size());
    assertEquals(value, conversionErrors.get("bean.birth").getValue());
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Aggregations

AnnotatedTestBean (com.opensymphony.xwork2.AnnotatedTestBean)2 List (java.util.List)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)1