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/test/org/apache/ojb repository_junit.xml
Date Tue, 27 Jul 2004 23:38:50 GMT
arminw      2004/07/27 16:38:50

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker AllTests.java
                        MultipleTableExtentAwareQueryTest.java
               src/test/org/apache/ojb repository_junit.xml
  Added:       src/test/org/apache/ojb/broker MultiMappedTest.java
  Log:
  add new tests
  - extents with interface + abstract classes
  - multi mapped classes with interface + abstract classes
  
  Revision  Changes    Path
  1.84      +1 -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.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- ojbtest-schema.xml	13 Jul 2004 11:37:57 -0000	1.83
  +++ ojbtest-schema.xml	27 Jul 2004 23:38:49 -0000	1.84
  @@ -340,6 +340,7 @@
       <table name="EXTENT_TEST_D">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="NAME" required="false" type="VARCHAR" size="100"/>
  +        <column name="D_FIELD" required="false" type="VARCHAR" size="100"/>
       </table>
   
        <table name="TABLE_1">
  
  
  
  1.51      +2 -1      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.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- AllTests.java	8 Jul 2004 00:47:04 -0000	1.50
  +++ AllTests.java	27 Jul 2004 23:38:49 -0000	1.51
  @@ -4,6 +4,7 @@
   import junit.framework.TestSuite;
   import org.apache.ojb.broker.cache.LocalCacheTest;
   import org.apache.ojb.broker.cache.ObjectCacheTest;
  +import org.apache.ojb.broker.dirty.DirtyTest;
   import org.apache.ojb.broker.metadata.CustomAttributesTest;
   import org.apache.ojb.broker.metadata.MetadataMultithreadedTest;
   import org.apache.ojb.broker.metadata.MetadataTest;
  @@ -16,7 +17,6 @@
   import org.apache.ojb.broker.sequence.NativeIdentifierTest;
   import org.apache.ojb.broker.sequence.SMMultiThreadedTest;
   import org.apache.ojb.broker.sequence.SequenceManagerTest;
  -import org.apache.ojb.broker.dirty.DirtyTest;
   
   /**
    * the facade to all TestCases in this package.
  @@ -81,6 +81,7 @@
           suite.addTestSuite(ComplexReferenceTest.class);
           suite.addTestSuite(ExtentAwarePathExpressionsTest.class);
           suite.addTestSuite(MultipleTableExtentAwareQueryTest.class);
  +        suite.addTestSuite(MultiMappedTest.class);
           suite.addTestSuite(RepositoryElementsTest.class);
           suite.addTestSuite(ConnectionFactoryTest.class);
           suite.addTestSuite(NativeIdentifierTest.class);
  
  
  
  1.3       +164 -6    db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java
  
  Index: MultipleTableExtentAwareQueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleTableExtentAwareQueryTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MultipleTableExtentAwareQueryTest.java	5 Apr 2004 17:11:48 -0000	1.2
  +++ MultipleTableExtentAwareQueryTest.java	27 Jul 2004 23:38:49 -0000	1.3
  @@ -1,13 +1,16 @@
   package org.apache.ojb.broker;
   
  +import java.io.Serializable;
  +import java.util.Collection;
  +import java.util.Iterator;
  +
   import junit.framework.TestCase;
  +import org.apache.commons.lang.StringUtils;
  +import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
  +import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  -import org.apache.ojb.junit.OJBTestCase;
  -
  -import java.util.Collection;
  -import java.util.Iterator;
   
   /**
    * Test query against extent classes and abstract base class.
  @@ -156,11 +159,147 @@
                   objCount*3, count);
       }
   
  +    public void testQueryForInterfaceAndAbstractClass()
  +    {
  +        String name = "testQueryForInterfaceAndAbstractClass_"+System.currentTimeMillis();
  +        String dFieldName = "d_field_only";
  +
  +        ExtentA a1 = new ExtentA();
  +        a1.setName(name);
  +        ExtentA a2 = new ExtentA();
  +        a2.setName(name);
  +        ExtentB b = new ExtentB();
  +        b.setName(name);
  +        ExtentC c = new ExtentC();
  +        c.setName(name);
  +        ExtentD d1 = new ExtentD();
  +        ExtentD d2 = new ExtentD();
  +        d1.setName(name);
  +        d2.setName(name);
  +        d1.setdClassField(dFieldName);
  +        d2.setdClassField(dFieldName);
  +
  +        broker.beginTransaction();
  +        broker.store(a1);
  +        broker.store(a2);
  +        broker.store(b);
  +        broker.store(c);
  +        broker.store(d1);
  +        broker.store(d2);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        QueryByCriteria queryBaseClassIF = QueryFactory.newQuery(BaseClassIF.class, crit);
  +        QueryByCriteria queryBaseClass = QueryFactory.newQuery(BaseClass.class, crit);
  +        QueryByCriteria queryA = QueryFactory.newQuery(ExtentA.class, crit);
  +        QueryByCriteria queryB = QueryFactory.newQuery(ExtentB.class, crit);
  +        QueryByCriteria queryC = QueryFactory.newQuery(ExtentC.class, crit);
  +        QueryByCriteria queryD = QueryFactory.newQuery(ExtentD.class, crit);
  +
  +
  +        Collection result = broker.getCollectionByQuery(queryBaseClassIF);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 6, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'BaseClassIF'", o instanceof BaseClassIF);
  +        }
  +
  +        result = broker.getCollectionByQuery(queryBaseClass);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 6, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'BaseClass'", o instanceof BaseClass);
  +        }
  +
  +        result = broker.getCollectionByQuery(queryA);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 2, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'ExtentA'", o instanceof ExtentA);
  +        }
  +
  +        result = broker.getCollectionByQuery(queryB);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 4, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'ExtentB'", o instanceof ExtentB);
  +        }
  +
  +        result = broker.getCollectionByQuery(queryC);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 3, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'ExtentC'", o instanceof ExtentC);
  +        }
   
  +        result = broker.getCollectionByQuery(queryD);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of objects", 2, result.size());
  +        for (Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            Object o =  iterator.next();
  +            assertTrue("Expect only classes of type 'ExtentD'", o instanceof ExtentD);
  +            ExtentD d = (ExtentD) o;
  +            assertNotNull(d.getdClassField());
  +            assertTrue(d.getdClassField().indexOf(TestConversion.APPENDIX_JAVA) > -1);
  +        }
  +    }
   
       //********************************************************
       // inner classes test objects
       //********************************************************
  +    public static class TestConversion implements FieldConversion
  +    {
  +        public static final String APPENDIX_SQL = "_TestConversion_sql";
  +        public static final String APPENDIX_JAVA = "_TestConversion_java";
  +//        static int counter = 0;
  +        public Object javaToSql(Object source) throws ConversionException
  +        {
  +            String str = (String) source;
  +            str = StringUtils.substringBeforeLast(str, APPENDIX_JAVA) + APPENDIX_SQL;
  +//            try
  +//            {
  +//                ++counter;
  +//                throw new Exception("## Position: " + counter);
  +//            }
  +//            catch (Exception e)
  +//            {
  +//                e.printStackTrace();
  +//            }
  +
  +            return str;
  +        }
  +
  +        public Object sqlToJava(Object source) throws ConversionException
  +        {
  +            String str = (String) source;
  +            str = StringUtils.substringBeforeLast(str, APPENDIX_SQL) + APPENDIX_JAVA;
  +//            try
  +//            {
  +//                ++counter;
  +//                throw new Exception("## Position: " + counter);
  +//            }
  +//            catch (Exception e)
  +//            {
  +//                e.printStackTrace();
  +//            }
  +            return str;
  +        }
  +    }
  +
       public static class ExtentA extends BaseClass
       {
       }
  @@ -175,9 +314,28 @@
   
       public static class ExtentD extends ExtentC
       {
  +        private String dClassField;
  +
  +        public String getdClassField()
  +        {
  +            return dClassField;
  +        }
  +
  +        public void setdClassField(String dClassField)
  +        {
  +            this.dClassField = dClassField;
  +        }
  +    }
  +
  +    public static interface BaseClassIF extends Serializable
  +    {
  +        public int getObjId();
  +        public void setObjId(int objId);
  +        public String getName();
  +        public void setName(String name);
       }
   
  -    public abstract static class BaseClass
  +    public abstract static class BaseClass implements BaseClassIF
       {
           private int objId;
           private String name;
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/MultiMappedTest.java
  
  Index: MultiMappedTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.Iterator;
  
  import org.apache.commons.lang.StringUtils;
  import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
  import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.broker.query.QueryByCriteria;
  import org.apache.ojb.broker.query.QueryFactory;
  import org.apache.ojb.junit.PBTestCase;
  
  /**
   * Test case helper class.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: MultiMappedTest.java,v 1.1 2004/07/27 23:38:49 arminw Exp $
   */
  public class MultiMappedTest extends PBTestCase
  {
      public static void main(String[] args)
      {
          String[] arr = {MultiMappedTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public MultiMappedTest()
      {
      }
  
      public MultiMappedTest(String name)
      {
          super(name);
      }
  
      public void testQueryMultiMapped()
      {
          String name = "testQueryMultiMapped_" + System.currentTimeMillis();
          ObjectA a1 = new ObjectA();
          a1.setValue1(name);
          ObjectA a2 = new ObjectA();
          a2.setValue1(name);
          ObjectB b1 = new ObjectB();
          b1.setValue1(name);
          b1.setValue4("value4_1");
          ObjectB b2 = new ObjectB();
          b2.setValue1(name);
          b2.setValue4("value4_2");
          ObjectB b3 = new ObjectB();
          b3.setValue1(name);
          b3.setValue4("value4_3");
  
          broker.beginTransaction();
          broker.store(a1);
          broker.store(a2);
          broker.store(b1);
          broker.store(b2);
          broker.store(b3);
          broker.commitTransaction();
  
          broker.clearCache();
  
          Criteria crit = new Criteria();
          crit.addEqualTo("value1", name);
          QueryByCriteria queryBaseClassIF = QueryFactory.newQuery(BaseClassIF.class, crit);
          QueryByCriteria queryBaseClass = QueryFactory.newQuery(BaseClass.class, crit);
          QueryByCriteria queryA = QueryFactory.newQuery(ObjectA.class, crit);
          QueryByCriteria queryB = QueryFactory.newQuery(ObjectB.class, crit);
  
          Collection result = broker.getCollectionByQuery(queryBaseClassIF);
          assertNotNull(result);
          assertEquals("Wrong number of objects", 5, result.size());
          for (Iterator iterator = result.iterator(); iterator.hasNext();)
          {
              Object o =  iterator.next();
              assertTrue("Expect only classes of type 'BaseClassIF'", o instanceof BaseClassIF);
          }
  
          result = broker.getCollectionByQuery(queryBaseClass);
          assertNotNull(result);
          assertEquals("Wrong number of objects", 5, result.size());
          for (Iterator iterator = result.iterator(); iterator.hasNext();)
          {
              Object o =  iterator.next();
              assertTrue("Expect only classes of type 'BaseClass'", o instanceof BaseClass);
          }
  
          result = broker.getCollectionByQuery(queryA);
          assertNotNull(result);
          assertEquals("Wrong number of objects", 5, result.size());
          for (Iterator iterator = result.iterator(); iterator.hasNext();)
          {
              Object o =  iterator.next();
              assertTrue("Expect only classes of type 'ObjectA'", o instanceof ObjectA);
          }
  
          broker.clearCache();
          result = broker.getCollectionByQuery(queryB);
          assertNotNull(result);
          assertEquals("Wrong number of objects", 3, result.size());
          for (Iterator iterator = result.iterator(); iterator.hasNext();)
          {
              Object o =  iterator.next();
              assertTrue("Expect only classes of type 'ObjectB'", o instanceof ObjectB);
              ObjectB b = (ObjectB) o;
              assertNotNull(b.getValue4());
              assertTrue(b.getValue4().indexOf(TestConversion.APPENDIX_JAVA) > -1);
          }
      }
  
      //*******************************************************
      // Inner class
      //*******************************************************
      public static class TestConversion implements FieldConversion
      {
          public static final String APPENDIX_SQL = "_TestConversion_sql";
          public static final String APPENDIX_JAVA = "_TestConversion_java";
          static int counter = 0;
          public Object javaToSql(Object source) throws ConversionException
          {
              String str = (String) source;
  //            try
  //            {
  //                ++counter;
  //                throw new Exception("## Position: " + counter);
  //            }
  //            catch (Exception e)
  //            {
  //                e.printStackTrace();
  //            }
              return str;
          }
  
          public Object sqlToJava(Object source) throws ConversionException
          {
              String str = (String) source;
              str = StringUtils.substringBeforeLast(str, APPENDIX_SQL) + APPENDIX_JAVA;
  //            try
  //            {
  //                ++counter;
  //                throw new Exception("## Position: " + counter);
  //            }
  //            catch (Exception e)
  //            {
  //                e.printStackTrace();
  //            }
  //            System.out.println("** " + str);
              return str;
          }
      }
  
  
      public static interface BaseClassIF extends Serializable
      {
          public Integer getId();
  
          public void setId(Integer id);
  
          public String getOjbConcreteClass();
  
          public void setOjbConcreteClass(String ojbConcreteClass);
  
          public String getValue1();
  
          public void setValue1(String value1);
      }
  
  
      public abstract static class BaseClass implements BaseClassIF
      {
          private Integer id;
          private String ojbConcreteClass;
          private String value1;
  
          public BaseClass()
          {
              ojbConcreteClass = this.getClass().getName();
          }
  
          public Integer getId()
          {
              return id;
          }
  
          public void setId(Integer id)
          {
              this.id = id;
          }
  
          public String getOjbConcreteClass()
          {
              return ojbConcreteClass;
          }
  
          public void setOjbConcreteClass(String ojbConcreteClass)
          {
              this.ojbConcreteClass = ojbConcreteClass;
          }
  
          public String getValue1()
          {
              return value1;
          }
  
          public void setValue1(String value1)
          {
              this.value1 = value1;
          }
      }
  
      public static class ObjectA extends BaseClass
      {
          private int value2;
  
          public int getValue2()
          {
              return value2;
          }
  
          public void setValue2(int value2)
          {
              this.value2 = value2;
          }
      }
  
      public static class ObjectB extends ObjectA
      {
          private String value4;
  
          public String getValue4()
          {
              return value4;
          }
  
          public void setValue4(String value4)
          {
              this.value4 = value4;
          }
      }
  }
  
  
  
  1.117     +90 -2     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.116
  retrieving revision 1.117
  diff -u -r1.116 -r1.117
  --- repository_junit.xml	13 Jul 2004 11:37:57 -0000	1.116
  +++ repository_junit.xml	27 Jul 2004 23:38:50 -0000	1.117
  @@ -2473,10 +2473,91 @@
    </class-descriptor>
   
   
  +<!-- ********************************************************** -->
  +<!--        MultiMappedTest, extent and abstract class          -->
  +<!-- ********************************************************** -->
  +    <class-descriptor class="org.apache.ojb.broker.MultiMappedTest$BaseClassIF">
  +        <extent-class class-ref="org.apache.ojb.broker.MultiMappedTest$BaseClass" />
  +    </class-descriptor>
  +
  +    <class-descriptor class="org.apache.ojb.broker.MultiMappedTest$BaseClass">
  +        <extent-class class-ref="org.apache.ojb.broker.MultiMappedTest$ObjectA" />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.MultiMappedTest$ObjectA"
  +        table="MultiMappedTable"
  +    >
  +        <extent-class class-ref="org.apache.ojb.broker.MultiMappedTest$ObjectB" />
  +        <field-descriptor
  +            name="id"
  +            column="ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +        <field-descriptor
  +            name="ojbConcreteClass"
  +            column="ojbConcreteClass"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="value1"
  +            column="value1"
  +            jdbc-type="VARCHAR"
  +        />
  +        <field-descriptor
  +            name="value2"
  +            column="value2"
  +            jdbc-type="INTEGER"
  +        />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.MultiMappedTest$ObjectB"
  +        table="MultiMappedTable"
  +    >
  +        <field-descriptor
  +            name="id"
  +            column="ID"
  +            jdbc-type="INTEGER"
  +            primarykey="true"
  +            autoincrement="true"
  +        />
  +        <field-descriptor
  +            name="ojbConcreteClass"
  +            column="ojbConcreteClass"
  +            jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +            name="value1"
  +            column="value1"
  +            jdbc-type="VARCHAR"
  +        />
  +        <field-descriptor
  +            name="value2"
  +            column="value2"
  +            jdbc-type="INTEGER"
  +        />
  +        <field-descriptor
  +            name="value4"
  +            column="value4"
  +            jdbc-type="VARCHAR"
  +            conversion="org.apache.ojb.broker.MultiMappedTest$TestConversion"
  +        />
  +    </class-descriptor>
  +
  +
   
   <!-- ********************************************************** -->
   <!-- testing for many extents to different tables with same base class -->
   <!-- ********************************************************** -->
  +<class-descriptor class="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$BaseClassIF">
  +    <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$BaseClass"
/>
  +</class-descriptor>
  +
   <class-descriptor class="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$BaseClass">
       <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentA"
/>
       <extent-class class-ref="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$ExtentB"
/>
  @@ -2555,6 +2636,13 @@
          column="NAME"
          jdbc-type="VARCHAR"
        />
  +
  +     <field-descriptor
  +       name="dClassField"
  +       column="D_FIELD"
  +       jdbc-type="VARCHAR"
  +         conversion="org.apache.ojb.broker.MultipleTableExtentAwareQueryTest$TestConversion"
  +     />
   </class-descriptor>
   
   
  @@ -3254,7 +3342,7 @@
         <field-descriptor
            name="price"
            column="PRICE"
  -         jdbc-type="DECIMAL"
  +         jdbc-type="DOUBLE"
         />
         <field-descriptor
            name="unit"
  
  
  

---------------------------------------------------------------------
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