Uploaded image for project: 'Tuscany'
  1. Tuscany
  2. TUSCANY-579

getString on Date field results in IllegalArgumentException

    XMLWordPrintableJSON

Details

    Description

      On page 146 of V2.01 of the spec, it is stated that conversion from Date to String is supported. However, getString on Date type results in an IllegalArgumentException. Here is a code segment:

      public void testShowErrorsInSimpleFormat() throws Exception

      { DataObject test_obj = DataFactory.INSTANCE.create(API_TEST_TYPE); Date current_date = new Date(System.currentTimeMillis()); // getString does not work on Date type test_obj.setDate("dateVal", current_date); String returned_string = test_obj.getString("dateVal"); //Gives IllegalArgumentException }

      And here is the XSD:
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:sdo="commonj.sdo"
      xmlns:simple="http://www.example.com/api_test"
      targetNamespace="http://www.example.com/api_test">
      <xsd:import namespace="commonj.sdo" schemaLocation="sdoModel.xsd"/>
      <xsd:element name="apiTestElem" type="simple:APITest"/>

      <xsd:complexType mixed="true" name="APITest">

      <xsd:sequence>
      <xsd:element name="stringVal" type="sdo:String"/>
      <xsd:element name="booleanVal" type="sdo:Boolean"/>
      <xsd:element name="booleanVal2" type="sdo:Boolean"/>
      <xsd:element name="byteVal" type="sdo:Byte"/>
      <xsd:element name="stringVal2" type="sdo:String"/>
      <xsd:element name="decimalVal" type="sdo:Decimal"/>
      <xsd:element name="decimalVal2" type="sdo:Decimal"/>
      <xsd:element name="intVal" type="sdo:Int"/>
      <xsd:element name="floatVal" type="sdo:Float"/>
      <xsd:element name="doubleVal" type="sdo:Double"/>
      <xsd:element name="dateVal" type="sdo:Date"/>
      <xsd:element name="shortVal" type="sdo:Short"/>
      <xsd:element name="longVal" type="sdo:Long"/>
      <xsd:element maxOccurs="unbounded" minOccurs="0"
      name="children" type="simple:APITest"/>
      <xsd:element name="bytesVal" type="sdo:Bytes"/>
      <xsd:element name="integerVal" type="sdo:Integer"/>
      <xsd:element name="charVal" type="sdo:Character"/>
      </xsd:sequence>
      </xsd:complexType>

      I originally thought that also getDate was not working on String, but this was an error in my test case. I had been setting the String value to be Date.toString(). Fuhwei correctly pointed out that the String format that would allow conversion is given on page 72 of the specification and is different than what is returned by Date.toString(). I have tested with the correct String format and found that getDate works, so clearly this is not an error. However, I wonder if it would be a good idea to aditionally support the String format that results from Date.toString().

      Attachments

        1. Tuscany579.patch
          2 kB
          Brian Murray
        2. Tuscany579.patch
          2 kB
          Brian Murray
        3. api_test.xsd
          2 kB
          Brian Murray
        4. TypeConversionTestCase.java
          38 kB
          Brian Murray
        5. DateConversionTest.java
          2 kB
          Fuhwei Lwo

        Activity

          People

            frankb Frank John Budinsky
            okstatendn Brian Murray
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: