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 Mon, 22 Aug 2005 15:32:46 GMT
arminw      2005/08/22 08:32:46

  Modified:    src/schema Tag: OJB_1_0_RELEASE ojbtest-schema.xml
               src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        PBListenerTest.java
               src/test/org/apache/ojb Tag: OJB_1_0_RELEASE
                        repository_junit.xml
  Log:
  add test for OJB-68
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.80.2.25 +14 -2     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.80.2.24
  retrieving revision 1.80.2.25
  diff -u -r1.80.2.24 -r1.80.2.25
  --- ojbtest-schema.xml	21 Jun 2005 10:53:45 -0000	1.80.2.24
  +++ ojbtest-schema.xml	22 Aug 2005 15:32:45 -0000	1.80.2.25
  @@ -1106,7 +1106,19 @@
       <!-- PBListenerTest test                                 -->
       <!-- =================================================== -->
       <table name="PB_AWARE_OBJECT">
  -        <column name="OJB_ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +        <column name="FK_REF" type="INTEGER"/>
  +    </table>
  +
  +    <table name="PB_AWARE_REF">
  +        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +    </table>
  +
  +    <table name="PB_AWARE_COLL">
  +        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="FK_PB_AWARE" type="INTEGER"/>
           <column name="NAME" type="VARCHAR" size="150"/>
       </table>
   
  
  
  
  No                   revision
  No                   revision
  1.3.2.2   +244 -3    db-ojb/src/test/org/apache/ojb/broker/PBListenerTest.java
  
  Index: PBListenerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PBListenerTest.java,v
  retrieving revision 1.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- PBListenerTest.java	20 Apr 2005 22:40:16 -0000	1.3.2.1
  +++ PBListenerTest.java	22 Aug 2005 15:32:45 -0000	1.3.2.2
  @@ -2,8 +2,15 @@
   
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.junit.PBTestCase;
  +import org.apache.ojb.broker.query.Criteria;
  +import org.apache.ojb.broker.query.QueryByCriteria;
  +import org.apache.ojb.broker.query.QueryFactory;
   
   import java.io.Serializable;
  +import java.util.List;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
   
   /**
    * This TestClass tests OJB facilities to work with persistence
  @@ -23,6 +30,75 @@
       }
   
       /**
  +     * Test for OJB-68
  +     * tests the callbacks beforeStore() and afterStore().
  +     */
  +    public void testStoreAndQuery() throws Exception
  +    {
  +        String name = "testStoreAndQuery_" + System.currentTimeMillis();
  +
  +        PBAwareObject pba_1 = new PBAwareObject(name);
  +        pba_1.setRefObject(new RefObj(name));
  +        pba_1.addCollObject(new CollObj(name));
  +        pba_1.addCollObject(new CollObj(name));
  +        pba_1.addCollObject(new CollObj(name));
  +
  +        PBAwareObject pba_2 = new PBAwareObject(name);
  +        pba_2.setRefObject(new RefObj(name));
  +        pba_2.addCollObject(new CollObj(name));
  +        pba_2.addCollObject(new CollObj(name));
  +        pba_2.addCollObject(new CollObj(name));
  +
  +        PBAwareObject pba_3 = new PBAwareObject(name);
  +        pba_3.setRefObject(new RefObj(name));
  +        pba_3.addCollObject(new CollObj(name));
  +        pba_3.addCollObject(new CollObj(name));
  +        pba_3.addCollObject(new CollObj(name));
  +
  +        broker.beginTransaction();
  +        broker.store(pba_1);
  +        broker.store(pba_2);
  +        broker.store(pba_3);
  +        broker.commitTransaction();
  +
  +        Identity oid_1 = broker.serviceIdentity().buildIdentity(pba_1);
  +        Identity oid_2 = broker.serviceIdentity().buildIdentity(pba_2);
  +
  +        broker.clearCache();
  +
  +        PBAwareObject pba_1_new = (PBAwareObject) broker.getObjectByIdentity(oid_1);
  +        PBAwareObject pba_2_new = (PBAwareObject) broker.getObjectByIdentity(oid_2);
  +
  +        assertNotNull(pba_1_new);
  +        assertNotNull(pba_2_new);
  +        assertNotNull(pba_1_new.getRefObject());
  +        assertNotNull(pba_2_new.getRefObject());
  +        assertEquals(3, pba_1_new.getCollObjects().size());
  +        assertEquals(3, pba_2_new.getCollObjects().size());
  +        assertTrue(pba_1_new.isAfterLookupRefObjectPopulated());
  +        assertTrue(pba_1_new.isAfterLookupCollObjectsPopulated());
  +        assertTrue(pba_2_new.isAfterLookupRefObjectPopulated());
  +        assertTrue(pba_2_new.isAfterLookupCollObjectsPopulated());
  +
  +        broker.clearCache();
  +
  +        Criteria criteria = new Criteria();
  +        criteria.addEqualTo( "name", name);
  +        QueryByCriteria query = QueryFactory.newQuery(PBAwareObject.class, criteria);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(3, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            PBAwareObject pba =  (PBAwareObject) iterator.next();
  +            assertNotNull(pba);
  +            assertNotNull(pba.getRefObject());
  +            assertEquals(3, pba.getCollObjects().size());
  +            assertTrue(pba.isAfterLookupRefObjectPopulated());
  +            assertTrue(pba.isAfterLookupCollObjectsPopulated());
  +        }
  +    }
  +
  +    /**
        * tests the callbacks beforeStore() and afterStore().
        */
       public void testStoreCallbacks() throws Exception
  @@ -72,7 +148,7 @@
           broker.beginTransaction();
           broker.store(obj);
           broker.commitTransaction();
  -        
  +
           assertEquals(false, obj.getCalledBeforeDelete());
           assertEquals(false, obj.getCalledAfterDelete());
           broker.beginTransaction();
  @@ -133,7 +209,7 @@
       {
           // This test need its own broker instance
           PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        PBStateListenerObject listener = null;
  +        PBStateListenerObject listener;
           PBStateListenerObject listener_2 = null;
           try
           {
  @@ -167,7 +243,8 @@
           finally
           {
               pb.close();
  -            assertEquals("beforeClose listener call failed", 125970, listener_2.evaluateTest());
  +            if(listener_2 != null) assertEquals("beforeClose listener call failed", 125970,
listener_2.evaluateTest());
  +            else fail("Something wrong with test");
           }
       }
   
  @@ -293,6 +370,9 @@
       {
           private int id;
           private String name;
  +        private RefObj refObject;
  +        private List collObjects;
  +
           private boolean calledBeforeInsert = false;
           private boolean calledAfterInsert = false;
           private boolean calledBeforeDelete = false;
  @@ -300,6 +380,17 @@
           private boolean calledAfterLookup = false;
           private boolean calledAfterUpdate = false;
           private boolean calledBeforeUpdate = false;
  +        private boolean afterLookupRefObjectPopulated = false;
  +        private boolean afterLookupCollObjectsPopulated = false;
  +
  +        public PBAwareObject()
  +        {
  +        }
  +
  +        public PBAwareObject(String name)
  +        {
  +            this.name = name;
  +        }
   
           public void beforeUpdate(PersistenceBroker broker) throws PersistenceBrokerException
           {
  @@ -340,6 +431,17 @@
           {
               //System.out.println("afterLookup()");
               calledAfterLookup = true;
  +            if(refObject != null) afterLookupRefObjectPopulated = true;
  +            if(collObjects != null) afterLookupCollObjectsPopulated = true;
  +//            System.out.println("## " + refObject);
  +//            System.out.println("## " + collObjects);
  +//            if(refObject == null)
  +//            {
  +//                try{throw new Exception();}catch(Exception e)
  +//                {
  +//                e.printStackTrace();
  +//                }
  +//            }
           }
   
   
  @@ -413,6 +515,46 @@
               this.calledBeforeInsert = calledBeforeStore;
           }
   
  +        public boolean isCalledBeforeInsert()
  +        {
  +            return calledBeforeInsert;
  +        }
  +
  +        public void setCalledBeforeInsert(boolean calledBeforeInsert)
  +        {
  +            this.calledBeforeInsert = calledBeforeInsert;
  +        }
  +
  +        public boolean isCalledAfterInsert()
  +        {
  +            return calledAfterInsert;
  +        }
  +
  +        public void setCalledAfterInsert(boolean calledAfterInsert)
  +        {
  +            this.calledAfterInsert = calledAfterInsert;
  +        }
  +
  +        public boolean isAfterLookupRefObjectPopulated()
  +        {
  +            return afterLookupRefObjectPopulated;
  +        }
  +
  +        public void setAfterLookupRefObjectPopulated(boolean afterLookupRefObjectPopulated)
  +        {
  +            this.afterLookupRefObjectPopulated = afterLookupRefObjectPopulated;
  +        }
  +
  +        public boolean isAfterLookupCollObjectsPopulated()
  +        {
  +            return afterLookupCollObjectsPopulated;
  +        }
  +
  +        public void setAfterLookupCollObjectsPopulated(boolean afterLookupCollObjectsPopulated)
  +        {
  +            this.afterLookupCollObjectsPopulated = afterLookupCollObjectsPopulated;
  +        }
  +
           public String getName()
           {
               return name;
  @@ -433,10 +575,109 @@
               this.id = id;
           }
   
  +        public RefObj getRefObject()
  +        {
  +            return refObject;
  +        }
  +
  +        public void setRefObject(RefObj refObj)
  +        {
  +            this.refObject = refObj;
  +        }
  +
  +        public List getCollObjects()
  +        {
  +            return collObjects;
  +        }
  +
  +        public void addCollObject(CollObj obj)
  +        {
  +            if(collObjects == null)
  +            {
  +                collObjects = new ArrayList();
  +            }
  +            collObjects.add(obj);
  +        }
  +
  +        public void setCollObjects(List collObjects)
  +        {
  +            this.collObjects = collObjects;
  +        }
  +
           public String toString()
           {
               return ToStringBuilder.reflectionToString(this);
           }
       }
   
  +    public static class RefObj implements Serializable
  +    {
  +        private Integer id;
  +        private String name;
  +
  +        public RefObj()
  +        {
  +        }
  +
  +        public RefObj(Integer id, String name)
  +        {
  +            this.id = id;
  +            this.name = name;
  +        }
  +
  +        public RefObj(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public Integer getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Integer id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +    }
  +
  +    public static class CollObj extends RefObj
  +    {
  +        private Integer fkPBAwareObject;
  +
  +        public CollObj()
  +        {
  +        }
  +
  +        public CollObj(Integer id, String name)
  +        {
  +            super(id, name);
  +        }
  +
  +        public CollObj(String name)
  +        {
  +            super(name);
  +        }
  +
  +        public Integer getFkPBAwareObject()
  +        {
  +            return fkPBAwareObject;
  +        }
  +
  +        public void setFkPBAwareObject(Integer fkPBAwareObject)
  +        {
  +            this.fkPBAwareObject = fkPBAwareObject;
  +        }
  +    }
  +
   }
  
  
  
  No                   revision
  No                   revision
  1.112.2.16 +77 -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.112.2.15
  retrieving revision 1.112.2.16
  diff -u -r1.112.2.15 -r1.112.2.16
  --- repository_junit.xml	21 Jun 2005 10:53:45 -0000	1.112.2.15
  +++ repository_junit.xml	22 Aug 2005 15:32:46 -0000	1.112.2.16
  @@ -1314,7 +1314,7 @@
      >
         <field-descriptor
            name="id"
  -         column="OJB_ID"
  +         column="ID_"
            jdbc-type="INTEGER"
            primarykey="true"
            autoincrement="true"
  @@ -1325,6 +1325,81 @@
            column="NAME"
            jdbc-type="VARCHAR"
         />
  +
  +       <field-descriptor
  +         name="fkRef"
  +         column="FK_REF"
  +         jdbc-type="INTEGER"
  +         access="anonymous"
  +      />
  +
  +       <reference-descriptor
  +            name="refObject"
  +            class-ref="org.apache.ojb.broker.PBListenerTest$RefObj"
  +            auto-retrieve="true"
  +         auto-update="object"
  +         auto-delete="object"
  +         proxy="false"
  +         proxy-prefetching-limit="10"
  +      >
  +                <foreignkey field-ref="fkRef"/>
  +        </reference-descriptor>
  +
  +       <collection-descriptor
  +         name="collObjects"
  +         element-class-ref="org.apache.ojb.broker.PBListenerTest$CollObj"
  +         auto-retrieve="true"
  +         auto-update="object"
  +         auto-delete="object"
  +         proxy="false"
  +         proxy-prefetching-limit="10"
  +      >
  +         <inverse-foreignkey field-ref="fkPBAwareObject"/>
  +      </collection-descriptor>
  +   </class-descriptor>
  +
  +   <class-descriptor
  +   	  class="org.apache.ojb.broker.PBListenerTest$RefObj"
  +   	  table="PB_AWARE_REF"
  +   >
  +      <field-descriptor
  +         name="id"
  +         column="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.PBListenerTest$CollObj"
  +   	  table="PB_AWARE_COLL"
  +   >
  +      <field-descriptor
  +         name="id"
  +         column="ID_"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +      />
  +
  +       <field-descriptor
  +         name="fkPBAwareObject"
  +         column="FK_PB_AWARE"
  +         jdbc-type="INTEGER"
  +      />
  +
  +      <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +      />
      </class-descriptor>
   
   
  
  
  

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