Search in sources :

Example 1 with SimpleAnnotationAction

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

the class AnnotationXWorkConverterTest method testFieldErrorMessageAddedWhenConversionFails.

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

Example 2 with SimpleAnnotationAction

use of com.opensymphony.xwork2.SimpleAnnotationAction 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

ValueStack (com.opensymphony.xwork2.util.ValueStack)2