Пример #1
0
  /*
   * (non-Javadoc)
   *
   * @seeorg.eclipse.birt.report.model.metadata.PropertyTypeTestCase#
   * testValidateInputString()
   */
  public void testValidateInputString() throws PropertyValueException {
    assertEquals(null, type.validateInputString(design, null, propDefn, null));
    assertEquals(null, type.validateInputString(design, null, propDefn, "")); // $NON-NLS-1$

    ModuleOption options = new ModuleOption();
    design.setOptions(options);

    // String
    options.setLocale(ULocale.ENGLISH);
    Date value =
        (Date) type.validateInputString(design, null, propDefn, "08/25/2004"); // $NON-NLS-1$
    calendar.setTime(value);
    assertEquals(2004 - 1900, calendar.get(Calendar.YEAR) - 1900);
    assertEquals(7, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DAY_OF_MONTH));

    options.setLocale(ULocale.CHINA);
    value = (Date) type.validateInputString(design, null, propDefn, "2004-08-25"); // $NON-NLS-1$
    assertEquals(2004 - 1900, calendar.get(Calendar.YEAR) - 1900);
    assertEquals(7, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DAY_OF_MONTH));

    try {
      type.validateInputString(design, null, propDefn, "wrong-datetime-value"); // $NON-NLS-1$
      fail();
    } catch (PropertyValueException e) {
      assertEquals(PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE, e.getErrorCode());
    }
  }