db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/schema ojbtest-schema.xml
Date Fri, 26 Aug 2005 19:03:03 GMT
brj         2005/08/26 12:03:03

  Modified:    src/test/org/apache/ojb/broker PBListenerTest.java
               src/schema ojbtest-schema.xml
  Log:
  Test for OJB-68
  
  Revision  Changes    Path
  1.5       +238 -0    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PBListenerTest.java	5 Dec 2004 19:55:10 -0000	1.4
  +++ PBListenerTest.java	26 Aug 2005 19:03:02 -0000	1.5
  @@ -1,9 +1,16 @@
   package org.apache.ojb.broker;
   
   import org.apache.commons.lang.builder.ToStringBuilder;
  +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;
   
   import java.io.Serializable;
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
   
   /**
    * This TestClass tests OJB facilities to work with persistence
  @@ -167,7 +174,74 @@
           }
       }
   
  +    /**
  +     * 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());
  +        }
  +    }
   
       //************************************************************************
       // test classes
  @@ -289,6 +363,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;
  @@ -296,6 +373,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
           {
  @@ -336,6 +424,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();
  +//                }
  +//            }
           }
   
   
  @@ -409,6 +508,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;
  @@ -429,10 +568,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;
  +        }
  +    }
   
   }
  
  
  
  1.97      +15 -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.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- ojbtest-schema.xml	8 May 2005 08:44:59 -0000	1.96
  +++ ojbtest-schema.xml	26 Aug 2005 19:03:02 -0000	1.97
  @@ -1112,10 +1112,23 @@
       <!-- 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>
  +
  +
       <!-- =================================================== -->
       <!-- PB 'readonly' attribute test                        -->
       <!-- =================================================== -->
  
  
  

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