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 Sat, 08 Mar 2003 11:37:50 GMT
arminw      2003/03/08 03:37:50

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/schema ojbtest-schema.xml
  Added:       src/test/org/apache/ojb/broker ReferenceTest.java
  Log:
  add new reference test
  
  Revision  Changes    Path
  1.51      +149 -0    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.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- repository_junit.xml	5 Mar 2003 23:52:08 -0000	1.50
  +++ repository_junit.xml	8 Mar 2003 11:37:49 -0000	1.51
  @@ -3262,4 +3262,153 @@
       </class-descriptor>
   
   
  +
  +<!-- ************************************************* -->
  +<!--      Reference test with extents                  -->
  +<!-- ************************************************* -->
  +
  +    <class-descriptor class="org.apache.ojb.broker.ReferenceTest$ReferenceIF">
  +        <extent-class class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceA" />
  +        <extent-class class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceB" />
  +    </class-descriptor>
  +
  +    <!--
  +    first reference no extent, no proxy
  +    second reference is extent, no proxy
  +    third reference is extent, is proxy
  +    -->
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$Repository"
  +        table="REF_REPOSITORY">
  +
  +        <field-descriptor
  +         name="repId"
  +         column="REP_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="refId"
  +         column="REF_FK"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
  +         name="refAId"
  +         column="REFA_FK"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <field-descriptor
  +         name="refBId"
  +         column="REFB_FK"
  +         jdbc-type="INTEGER"
  +        />
  +
  +        <reference-descriptor
  +            name="ref"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$Reference"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refId"/>
  +        </reference-descriptor>
  +
  +        <reference-descriptor
  +            name="refA"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceA"
  +            proxy="false"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refAId"/>
  +        </reference-descriptor>
  +
  +        <reference-descriptor
  +            name="refB"
  +            class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceB"
  +            proxy="true"
  +            auto-retrieve="true"
  +            auto-update="true"
  +            auto-delete="true">
  +                <foreignkey field-ref="refBId"/>
  +        </reference-descriptor>
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$Reference"
  +        table="REF_REFERENCE">
  +
  +        <extent-class class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceA" />
  +        <extent-class class-ref="org.apache.ojb.broker.ReferenceTest$ReferenceB" />
  +
  +        <field-descriptor
  +         name="refId"
  +         column="REF_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$ReferenceA"
  +        table="REF_REFERENCE">
  +
  +        <field-descriptor
  +         name="refId"
  +         column="REF_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +         name="refNameA"
  +         column="REF_NAME_A"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +    <class-descriptor
  +        class="org.apache.ojb.broker.ReferenceTest$ReferenceB"
  +        table="REF_REFERENCE">
  +
  +        <field-descriptor
  +         name="refId"
  +         column="REF_ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +
  +        <field-descriptor
  +         name="refNameB"
  +         column="REF_NAME_B"
  +         jdbc-type="VARCHAR"
  +        />
  +    </class-descriptor>
  +
  +
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.query.QueryFactory;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.query.Criteria;
  
  import java.util.Collection;
  import java.util.Iterator;
  
  /**
   * Test case for checking the management of references.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: ReferenceTest.java,v 1.1 2003/03/08 11:37:50 arminw Exp $
   */
  public class ReferenceTest extends TestCase
  {
      private PersistenceBroker broker;
  
      public static void main(String[] args)
      {
          String[] arr = {ReferenceTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (06.12.2000 21:58:53)
       */
      public void setUp() throws PBFactoryException
      {
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (06.12.2000 21:59:14)
       */
      public void tearDown()
      {
          try
          {
              broker.close();
          }
          catch (PersistenceBrokerException e)
          {
          }
      }
  
      public void testReferenceStore()
      {
          String referenceNamePrefix = ""+System.currentTimeMillis();
          Repository[] repository = prepareRepository(referenceNamePrefix);
  
          broker.beginTransaction();
          broker.store(repository[0]);
          broker.store(repository[1]);
          broker.store(repository[2]);
          broker.commitTransaction();
  
          assertNotNull(repository[0].getRef());
          assertNotNull(repository[0].getRefA());
          assertNotNull(repository[0].getRefB());
      }
  
      public void testReferenceGetByIdentity()
      {
          String referenceNamePrefix = ""+System.currentTimeMillis();
          Repository[] repository = prepareRepository(referenceNamePrefix);
  
          broker.beginTransaction();
          broker.store(repository[0]);
          broker.store(repository[1]);
          broker.store(repository[2]);
          broker.commitTransaction();
  
          assertNotNull(repository[0].getRef());
          assertNotNull(repository[0].getRefA());
          assertNotNull(repository[0].getRefB());
  
          Identity oid_ref = new Identity(repository[0].getRef(), broker);
          Identity oid_refA = new Identity(repository[0].getRefA(), broker);
          Identity oid_refB = new Identity(repository[0].getRefB(), broker);
  
          Object result;
          result = broker.getObjectByIdentity(oid_ref);
          assertTrue(result instanceof Reference);
          result = broker.getObjectByIdentity(oid_refA);
          assertTrue(result instanceof ReferenceA);
          result = broker.getObjectByIdentity(oid_refB);
          assertTrue(result instanceof ReferenceB);
      }
  
      public void testQueryReferences()
      {
          String referenceNamePrefix = ""+System.currentTimeMillis();
          Repository[] repository = prepareRepository(referenceNamePrefix);
  
          broker.beginTransaction();
          broker.store(repository[0]);
          broker.store(repository[1]);
          broker.store(repository[2]);
          broker.commitTransaction();
  
          Criteria criteria = new Criteria();
          criteria.addLike("name", referenceNamePrefix+"%");
          Query query = QueryFactory.newQuery(ReferenceIF.class, criteria);
          Collection result = broker.getCollectionByQuery(query);
  
          assertEquals("Wrong number of References", 9, result.size());
          int ref_count = 0;
          int refA_count = 0;
          int refB_count = 0;
          Iterator it = result.iterator();
          Object obj;
          while(it.hasNext())
          {
              obj = it.next();
              if(obj instanceof ReferenceA) refA_count++;
              else if(obj instanceof ReferenceB) refB_count++;
              else if(obj instanceof Reference) ref_count++;
          }
          assertEquals("Wrong number of RefernceA", 3, refA_count);
          assertEquals("Wrong number of RefernceB", 3, refB_count);
          assertEquals("Wrong number of Refernce", 3, ref_count);
      }
  
      public void testDeleteReferences()
      {
          String referenceNamePrefix = ""+System.currentTimeMillis();
          Repository[] repository = prepareRepository(referenceNamePrefix);
  
          broker.beginTransaction();
          broker.store(repository[0]);
          broker.store(repository[1]);
          broker.store(repository[2]);
          broker.commitTransaction();
  
          Criteria criteria = new Criteria();
          criteria.addLike("name", referenceNamePrefix+"%");
          Query query = QueryFactory.newQuery(ReferenceIF.class, criteria);
          Collection result = broker.getCollectionByQuery(query);
  
          assertEquals("Wrong number of References", 9, result.size());
  
          broker.beginTransaction();
          broker.delete(repository[0]);
          broker.delete(repository[1]);
          broker.delete(repository[2]);
          broker.commitTransaction();
  
          result = broker.getCollectionByQuery(query);
          assertEquals("Wrong number of References", 0, result.size());
      }
  
      private Repository[] prepareRepository(String referenceNamePrefix)
      {
          Reference[] ref = new Reference[]{
              new Reference(referenceNamePrefix + "ref_1"),
              new Reference(referenceNamePrefix + "ref_2"),
              new Reference(referenceNamePrefix + "ref_3")};
          ReferenceA[] refA = new ReferenceA[]{
              new ReferenceA(referenceNamePrefix + "refA_1", "a1"),
              new ReferenceA(referenceNamePrefix + "refA_2", "a2"),
              new ReferenceA(referenceNamePrefix + "refA_3", "a3")};
          ReferenceB[] refB = new ReferenceB[]{
              new ReferenceB(referenceNamePrefix + "refB_1", "b1"),
              new ReferenceB(referenceNamePrefix + "refB_2", "b2"),
              new ReferenceB(referenceNamePrefix + "refB_3", "b3")};
  
          Repository repository = new Repository();
          repository.setRef(ref[0]);
          repository.setRefA(refA[0]);
          repository.setRefB(refB[0]);
  
          Repository repository2 = new Repository();
          repository2.setRef(ref[1]);
          repository2.setRefA(refA[1]);
          repository2.setRefB(refB[1]);
  
          Repository repository3 = new Repository();
          repository3.setRef(ref[2]);
          repository3.setRefA(refA[2]);
          repository3.setRefB(refB[2]);
  
          return new Repository[]{repository, repository2, repository3};
      }
  
  
  
  
  
  //***************************************************************************
  // Inner classes used by the test case
  //***************************************************************************
  
      public static class Repository
      {
          private Integer repId;
  
          private Integer refId;
          private Integer refAId;
          private Integer refBId;
  
          private Reference ref;
          private ReferenceA refA;
          private ReferenceB refB;
  
          public Repository()
          {
          }
  
          public Reference getRef()
          {
              return ref;
          }
  
          public void setRef(Reference ref)
          {
              this.ref = ref;
          }
  
          public ReferenceA getRefA()
          {
              return refA;
          }
  
          public void setRefA(ReferenceA refA)
          {
              this.refA = refA;
          }
  
          public ReferenceB getRefB()
          {
              return refB;
          }
  
          public void setRefB(ReferenceB refB)
          {
              this.refB = refB;
          }
  
          public Integer getRepId()
          {
              return repId;
          }
  
          public void setRepId(Integer repId)
          {
              this.repId = repId;
          }
      }
  
      public static interface ReferenceIF
      {
          Integer getRefId();
  
          void setRefId(Integer refId);
  
          String getName();
  
          void setName(String name);
      }
  
      public static interface ReferenceAIF
      {
          String getRefNameA();
  
          void setRefNameA(String name);
      }
  
      public static interface ReferenceBIF
      {
          String getRefNameB();
  
          void setRefNameB(String name);
      }
  
      public static class Reference implements ReferenceIF
      {
          private Integer refId;
          private String name;
  
          public Reference()
          {
          }
  
          public Reference(String name)
          {
              this.name = name;
          }
  
          public Integer getRefId()
          {
              return refId;
          }
  
          public void setRefId(Integer refId)
          {
              this.refId = refId;
          }
  
          public String getName()
          {
              return name;
          }
  
          public void setName(String name)
          {
              this.name = name;
          }
      }
  
      public static class ReferenceA extends Reference implements ReferenceAIF
      {
          private String refNameA;
  
          public ReferenceA()
          {
              super();
          }
  
          public ReferenceA(String name, String refNameA)
          {
              super(name);
              this.refNameA = refNameA;
          }
  
          public String getRefNameA()
          {
              return refNameA;
          }
  
          public void setRefNameA(String refName)
          {
              this.refNameA = refName;
          }
      }
  
      public static class ReferenceB extends Reference implements ReferenceBIF
      {
          private String refNameB;
  
          public ReferenceB()
          {
              super();
          }
  
          public ReferenceB(String name, String refNameB)
          {
              super(name);
              this.refNameB = refNameB;
          }
  
          public String getRefNameB()
          {
              return refNameB;
          }
  
          public void setRefNameB(String refName)
          {
              this.refNameB = refName;
          }
      }
  }
  
  
  
  1.27      +17 -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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ojbtest-schema.xml	6 Mar 2003 13:44:01 -0000	1.26
  +++ ojbtest-schema.xml	8 Mar 2003 11:37:50 -0000	1.27
  @@ -587,4 +587,21 @@
           <column name="NAME" type="VARCHAR" size="100"/>
       </table>
   
  +    <!-- =================================================== -->
  +    <!-- Refernece test table                                -->
  +    <!-- =================================================== -->
  +    <table name="REF_REPOSITORY">
  +        <column name="REP_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="REF_FK" type="INTEGER"/>
  +        <column name="REFA_FK" type="INTEGER"/>
  +        <column name="REFB_FK" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="100"/>
  +    </table>
  +
  +    <table name="REF_REFERENCE">
  +        <column name="REF_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="100"/>
  +        <column name="REF_NAME_A" type="VARCHAR" size="100"/>
  +        <column name="REF_NAME_B" type="VARCHAR" size="100"/>
  +    </table>
   </database>
  
  
  

Mime
View raw message