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());
}
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());
}
Aggregations