db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/schema ojbtest-schema.xml
Date Tue, 06 Apr 2004 15:29:21 GMT
arminw      2004/04/06 08:29:21

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/junit OJBTestCase.java
               src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java AllTests.java
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/junit PBTestCase.java
               src/test/org/apache/ojb/broker NumberAccuracyTest.java
  Log:
  - add new test case for accuracy of BigDecimal values
  handled by OJB
  - add new tests for objects multiple joined tables
  (there is a bug when build queries from sub objects to
  references of the super object)
  - add convenience PB junit base test case class
  
  Revision  Changes    Path
  1.112     +30 -1     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- repository_junit.xml	5 Apr 2004 17:11:48 -0000	1.111
  +++ repository_junit.xml	6 Apr 2004 15:29:20 -0000	1.112
  @@ -2891,6 +2891,35 @@
       </class-descriptor>
   
   
  +<!-- ************************************************* -->
  +<!--    PB-api NumberAccuracyTest                      -->
  +<!-- ************************************************* -->
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.NumberAccuracyTest$NumberObject"
  +        table="NUMBER_ACCURACY_TEST"
  +    >
  +        <field-descriptor
  +            name="id"
  +            column="OBJ_ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +            name="scaleTwo"
  +            column="SCALE_TWO"
  +            jdbc-type="DECIMAL"
  +        />
  +
  +        <field-descriptor
  +            name="scaleFour"
  +            column="SCALE_FOUR"
  +            jdbc-type="DECIMAL"
  +        />
  +    </class-descriptor>
  +
   
   <!-- ************************************************* -->
   <!--      user data for second test database           -->
  
  
  
  1.2       +3 -3      db-ojb/src/test/org/apache/ojb/junit/OJBTestCase.java
  
  Index: OJBTestCase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/junit/OJBTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OJBTestCase.java	5 Apr 2004 17:11:49 -0000	1.1
  +++ OJBTestCase.java	6 Apr 2004 15:29:21 -0000	1.2
  @@ -11,7 +11,7 @@
   public class OJBTestCase extends TestCase
   {
       private static final String SKIP_STR = "OJB.skip.issues";
  -    private static final String SKIP_DEFAULT_VALUE = "true";
  +    private static final String SKIP_DEFAULT_VALUE = "false";
   
       public OJBTestCase()
       {
  @@ -40,7 +40,7 @@
       public boolean skipKnownIssueProblem(String message)
       {
           String result = SKIP_DEFAULT_VALUE;
  -        boolean skip = true;
  +        boolean skip = false;
           try
           {
               result = System.getProperty(SKIP_STR, result);
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/junit/PBTestCase.java
  
  Index: PBTestCase.java
  ===================================================================
  package org.apache.ojb.junit;
  
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  
  /**
   * A base class for PB-api based test cases.
   * NOTE: The PB instance is declared <tt>public</tt> (no getter/setter) for
easy use.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: PBTestCase.java,v 1.1 2004/04/06 15:29:21 arminw Exp $
   */
  public class PBTestCase extends OJBTestCase
  {
      public PersistenceBroker broker;
  
      public PBTestCase()
      {
      }
  
      public PBTestCase(String name)
      {
          super(name);
      }
  
      public void setUp()
      {
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
      }
  
      public void tearDown()
      {
           if(broker != null)
           {
               broker.close();
           }
      }
  }
  
  
  
  1.3       +32 -1     db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InheritanceMultipleTableTest.java	5 Apr 2004 17:11:48 -0000	1.2
  +++ InheritanceMultipleTableTest.java	6 Apr 2004 15:29:21 -0000	1.3
  @@ -190,6 +190,37 @@
           assertEquals("snob allee", retManager.getAddress().getStreet());
       }
   
  +    public void testQuery_InheritedReference_1()
  +    {
  +        // TODO: skip this test, we have to fix this after 1.0
  +        if(ojbSkipKnownIssueProblem()) return;
  +
  +        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Executive.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
  +    public void testQuery_InheritedReference_3()
  +    {
  +        String name = "testQuery_InheritedReference" + System.currentTimeMillis();
  +        prepareForQueryTests(name);
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addLike("name", name + "%");
  +        crit.addEqualTo("address.street", "snob allee");
  +        Query query = QueryFactory.newQuery(Employee.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +    }
  +
       public void testInsertQuery()
       {
           String name = "testInsert" + System.currentTimeMillis();
  
  
  
  1.43      +1 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- AllTests.java	5 Apr 2004 17:11:48 -0000	1.42
  +++ AllTests.java	6 Apr 2004 15:29:21 -0000	1.43
  @@ -88,6 +88,7 @@
           suite.addTestSuite(InheritanceMultipleTableTest.class);
           suite.addTestSuite(M2NTest.class);
           suite.addTestSuite(CollectionTest2.class);
  +        suite.addTestSuite(NumberAccuracyTest.class);
           return suite;
       }
   
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/NumberAccuracyTest.java
  
  Index: NumberAccuracyTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import java.math.BigDecimal;
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.commons.lang.builder.ToStringStyle;
  import org.apache.ojb.junit.PBTestCase;
  
  /**
   * Test case to check the accuracy of {@link BigDecimal} values stored in DB.
   *
   * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
   * @version $Id: NumberAccuracyTest.java,v 1.1 2004/04/06 15:29:21 arminw Exp $
   */
  public class NumberAccuracyTest extends PBTestCase
  {
      public static void main(String[] args)
      {
          junit.textui.TestRunner.main(new String[] {NumberAccuracyTest.class.getName()});
      }
  
      public NumberAccuracyTest()
      {
      }
  
      public NumberAccuracyTest(String name)
      {
          super(name);
      }
  
      public void testBigDecimal()
      {
          BigDecimal scaleTwo = new BigDecimal("17.34554");
          BigDecimal scaleFour = new BigDecimal("67.345567");
          // round half up values
          scaleTwo = scaleTwo.setScale(2, BigDecimal.ROUND_HALF_UP);
          scaleFour = scaleFour.setScale(4, BigDecimal.ROUND_HALF_UP);
  
          NumberObject no = new NumberObject();
          no.setScaleTwo(scaleTwo);
          no.setScaleFour(scaleFour);
  
  //        System.out.println("# " + no.getScaleTwoDouble());
  //        System.out.println("# " + no.getScaleFourDouble());
          broker.beginTransaction();
          broker.store(no);
          broker.commitTransaction();
  
          Identity oidNo = new Identity(no, broker);
          broker.clearCache();
          NumberObject newNo = (NumberObject) broker.getObjectByIdentity(oidNo);
  //        System.out.println("# " + newNo.getScaleTwoDouble());
  //        System.out.println("# " + newNo.getScaleFourDouble());
          assertEquals(17.35d ,newNo.getScaleTwoDouble(), 0.001);
          assertEquals(67.3456 ,newNo.getScaleFourDouble(), 0.00001);
          assertTrue(0 == scaleTwo.compareTo(newNo.getScaleTwo()));
          assertTrue(0 == scaleFour.compareTo(newNo.getScaleFour()));
  
  
          BigDecimal newScaleTwo = newNo.getScaleTwo().multiply(new BigDecimal(10));
          newNo.setScaleTwo(newScaleTwo);
          BigDecimal newScaleFour = newNo.getScaleFour().multiply(new BigDecimal(10));
          newNo.setScaleFour(newScaleFour);
          broker.beginTransaction();
          broker.store(newNo);
          broker.commitTransaction();
  
          broker.clearCache();
          NumberObject newNo_2 = (NumberObject) broker.getObjectByIdentity(oidNo);
  //        System.out.println("# " + newNo.getScaleTwoDouble());
  //        System.out.println("# " + newNo.getScaleFourDouble());
          assertEquals(173.5d ,newNo_2.getScaleTwoDouble(), 0.1);
          assertEquals(673.455 ,newNo_2.getScaleFourDouble(), 0.001);
          assertTrue(0 == newScaleTwo.compareTo(newNo_2.getScaleTwo()));
          assertTrue(0 == newScaleFour.compareTo(newNo_2.getScaleFour()));
      }
  
      public static class NumberObject
      {
          private Integer id;
          private BigDecimal scaleTwo;
          private BigDecimal scaleFour;
  
          public Integer getId()
          {
              return id;
          }
  
          public void setId(Integer id)
          {
              this.id = id;
          }
  
          public BigDecimal getScaleTwo()
          {
              return scaleTwo;
          }
  
          public void setScaleTwo(BigDecimal scaleTwo)
          {
              this.scaleTwo = scaleTwo;
          }
  
          public double getScaleTwoDouble()
          {
              return scaleTwo.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
          }
  
          public BigDecimal getScaleFour()
          {
              return scaleFour;
          }
  
          public void setScaleFour(BigDecimal scalefour)
          {
              this.scaleFour = scalefour;
          }
  
          public double getScaleFourDouble()
          {
              return scaleFour.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
          }
  
          public String toString()
          {
              return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
          }
      }
  }
  
  
  
  1.72      +9 -0      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- ojbtest-schema.xml	5 Apr 2004 17:23:16 -0000	1.71
  +++ ojbtest-schema.xml	6 Apr 2004 15:29:21 -0000	1.72
  @@ -670,6 +670,15 @@
       </table>
   
       <!-- =================================================== -->
  +    <!-- NumberAccuarcyTest                                  -->
  +    <!-- =================================================== -->
  +    <table name="NUMBER_ACCURACY_TEST">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="SCALE_TWO" type="DECIMAL" size="15,6"/>
  +        <column name="SCALE_FOUR" type="DECIMAL" size="15,6"/>
  +    </table>
  +
  +    <!-- =================================================== -->
       <!-- Perf-test table                                     -->
       <!-- =================================================== -->
       <!--
  
  
  

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


Mime
View raw message