コード例 #1
0
  public void testFindConversionErrorMessage() {
    ModelDrivenAnnotationAction action = new ModelDrivenAnnotationAction();
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(action);
    stack.push(action.getModel());

    String message = XWorkConverter.getConversionErrorMessage("birth", stack);
    assertNotNull(message);
    assertEquals("Invalid date for birth.", message);

    message = XWorkConverter.getConversionErrorMessage("foo", stack);
    assertNotNull(message);
    assertEquals("Invalid field value for field \"foo\".", message);
  }
コード例 #2
0
  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"));
  }