public void testFieldErrorMessageAddedWhenConversionFailsOnModelDriven() { ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction(); ValueStack stack = ActionContext.getContext().getValueStack(); stack.push(action); stack.push(action.getModel()); 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, "birth", value, Date.class)); stack.pop(); stack.pop(); Map conversionErrors = (Map) ognlStackContext.get(ActionContext.CONVERSION_ERRORS); assertNotNull(conversionErrors); assertEquals(1, conversionErrors.size()); assertNotNull(conversionErrors.get("birth")); assertEquals(value, conversionErrors.get("birth")); }
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 conversionErrors = (Map) stack.getContext().get(ActionContext.CONVERSION_ERRORS); assertNotNull(conversionErrors); assertTrue(conversionErrors.size() == 1); assertEquals(value, conversionErrors.get("bean.birth")); }