db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject cvs commit: db-torque/src/rttest/org/apache/torque DataTest.java
Date Mon, 27 Dec 2004 19:52:48 GMT
tfischer    2004/12/27 11:52:48

  Modified:    src/rttest Tag: TORQUE_3_1_BRANCH bookstore-schema.xml
               src/rttest/org/apache/torque Tag: TORQUE_3_1_BRANCH
                        DataTest.java
  Log:
  added a test case where the accuracy of date/time/timestamp values are checked. For this,
a new table was added to the bookstore schema.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.13.2.1  +29 -0     db-torque/src/rttest/bookstore-schema.xml
  
  Index: bookstore-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/bookstore-schema.xml,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- bookstore-schema.xml	3 Aug 2003 13:42:40 -0000	1.13
  +++ bookstore-schema.xml	27 Dec 2004 19:52:47 -0000	1.13.2.1
  @@ -245,5 +245,34 @@
         <reference foreign="COL2" local="PARENT_COL2"/>
       </foreign-key>
     </table>
  +  
  +  <!-- =================================================== -->
  +  <!-- D A T E _ T E S T  T A B L E                        -->
  +  <!-- =================================================== -->
  +
  +  <table name="DATE_TEST" description="Table to test Date formats">
  +    <column
  +      name="DATE_TEST_ID"
  +      required="true"
  +      primaryKey="true"
  +      type="INTEGER"
  +    />
  +    <column
  +      name="DATE_VALUE"
  +      required="true"
  +      type="DATE"
  +    />
  +    <column
  +      name="TIME_VALUE"
  +      required="true"
  +      type="TIME"
  +    />
  +    <column
  +      name="TIMESTAMP_VALUE"
  +      required="true"
  +      type="TIMESTAMP"
  +    />
  +
  +  </table>
   
   </database>
  
  
  
  No                   revision
  No                   revision
  1.8.2.6   +79 -1     db-torque/src/rttest/org/apache/torque/DataTest.java
  
  Index: DataTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DataTest.java,v
  retrieving revision 1.8.2.5
  retrieving revision 1.8.2.6
  diff -u -r1.8.2.5 -r1.8.2.6
  --- DataTest.java	16 Dec 2004 08:04:36 -0000	1.8.2.5
  +++ DataTest.java	27 Dec 2004 19:52:47 -0000	1.8.2.6
  @@ -16,6 +16,9 @@
    * limitations under the License.
    */
   
  +import java.text.DateFormat;
  +import java.text.SimpleDateFormat;
  +import java.util.Date;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  @@ -28,6 +31,8 @@
   import org.apache.torque.test.BookPeer;
   import org.apache.torque.test.BooleanCheck;
   import org.apache.torque.test.BooleanCheckPeer;
  +import org.apache.torque.test.DateTest;
  +import org.apache.torque.test.DateTestPeer;
   import org.apache.torque.test.MultiPk;
   import org.apache.torque.test.MultiPkPeer;
   import org.apache.torque.test.NullValueTable;
  @@ -764,6 +769,79 @@
               }
           }
           catch( Exception e) 
  +        {
  +            e.printStackTrace();
  +            fail("Exception caught : " 
  +                     + e.getClass().getName() 
  +                     + " : " + e.getMessage());
  +        }
  +    }
  +    
  +    /**
  +     * Tests the date, time and datetime accuracy.
  +     * At the moment, no upper limit for the accuracy is checked,
  +     * the differences are printed to stdout.
  +     */
  +    public void testDateTime() 
  +    {
  +        try
  +        {
  +            // clean Date table
  +            Criteria criteria = new Criteria();
  +            criteria.add(
  +                    DateTestPeer.DATE_TEST_ID, 
  +                    (Long) null, 
  +                    Criteria.NOT_EQUAL);
  +            DateTestPeer.doDelete(criteria);
  +            
  +            // insert new DateTest object to db
  +            DateTest dateTest = new DateTest();
  +            Date now = new Date();
  +            dateTest.setDateValue(now);
  +            dateTest.setTimeValue(now);
  +            dateTest.setTimestampValue(now);
  +            dateTest.save();
  +            DateFormat dateFormat = new SimpleDateFormat();
  +            System.out.println(
  +                    "testDateTime() : set date to : " 
  +                    + dateFormat.format(now));
  +            
  +            // reload dateTest from db
  +            DateTest loadedDateTest 
  +                    = DateTestPeer.retrieveByPK(dateTest.getPrimaryKey());
  +            
  +            System.out.println(
  +                    "testDateTime() : retrieved date : " 
  +                    + dateFormat.format(loadedDateTest.getDateValue()));
  +            System.out.println(
  +                    "testDateTime() : retrieved time : " 
  +                    + dateFormat.format(loadedDateTest.getTimeValue()));
  +            System.out.println(
  +                    "testDateTime() : retrieved timestamp : " 
  +                    + dateFormat.format(loadedDateTest.getTimestampValue()));
  +
  +            // compute time differences between reloaded and original object
  +            long dateDifference 
  +                    = dateTest.getDateValue().getTime()
  +                        - loadedDateTest.getDateValue().getTime();
  +            long timeDifference 
  +                    = dateTest.getTimeValue().getTime()
  +                        - loadedDateTest.getTimeValue().getTime();
  +            long timestampDifference 
  +                    = dateTest.getTimestampValue().getTime()
  +                        - loadedDateTest.getTimestampValue().getTime();
  +            
  +            System.out.println(
  +                    "testDateTime() : Date difference (ms): " 
  +                    + dateDifference);
  +            System.out.println(
  +                    "testDateTime() : Time difference (ms): " 
  +                    + timeDifference);
  +            System.out.println(
  +                    "testDateTime() : Timestamp difference (ms): " 
  +                    + timestampDifference);
  +        }
  +        catch (Exception e)
           {
               e.printStackTrace();
               fail("Exception caught : " 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message