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 Sat, 30 Aug 2003 23:07:43 GMT
arminw      2003/08/30 16:07:43

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker MultipleDBTest.java
               src/test/org/apache/ojb/odmg DListTest.java
               src/test/org/apache/ojb repository_junit.xml
  Log:
  update test cases
  
  Revision  Changes    Path
  1.49      +6 -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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- ojbtest-schema.xml	22 Aug 2003 22:01:30 -0000	1.48
  +++ ojbtest-schema.xml	30 Aug 2003 23:07:43 -0000	1.49
  @@ -395,6 +395,12 @@
       </unique>
     </table>
   
  +     <table name="ODMG_DLIST">
  +        <column name="ID" required="true" primaryKey="true" type="INTEGER"/>
  +        <column name="NAME" required="true" type="VARCHAR" size="100"/>
  +        <column name="RND_NAME" required="true" type="VARCHAR" size="100"/>
  +  </table>
  +
   
     <!-- ======================================================== -->
     <!--                                                          -->
  
  
  
  1.14      +2 -4      db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java
  
  Index: MultipleDBTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MultipleDBTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MultipleDBTest.java	22 Jul 2003 22:59:46 -0000	1.13
  +++ MultipleDBTest.java	30 Aug 2003 23:07:43 -0000	1.14
  @@ -2,9 +2,8 @@
   
   import junit.framework.Assert;
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.util.logging.LoggingHelper;
  -import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.Criteria;
  +import org.apache.ojb.broker.query.QueryByCriteria;
   
   import java.sql.Connection;
   
  @@ -103,7 +102,7 @@
               secPB = PersistenceBrokerFactory.createPersistenceBroker(secKey);
   
               Assert.assertNotNull("Cannot lookup default PB", defPB);
  -            Assert.assertNotNull("Cannot lookup PB for PBKey: " + LoggingHelper.traceObject(secKey),
secPB);
  +            Assert.assertNotNull("Cannot lookup PB for PBKey: " + secKey, secPB);
               Assert.assertEquals("Different repository files for second db",
                       secPB.getPBKey().getAlias(), secKey.getAlias());
           }
  @@ -401,7 +400,6 @@
       /**
        * factory method that createa an PerformanceArticle
        * @return the created PerformanceArticle object
  -     * @param id the primary key value for the new object
        */
       private PerformanceArticle createArticle()
       {
  
  
  
  1.17      +109 -48   db-ojb/src/test/org/apache/ojb/odmg/DListTest.java
  
  Index: DListTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/DListTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DListTest.java	6 Aug 2003 00:20:13 -0000	1.16
  +++ DListTest.java	30 Aug 2003 23:07:43 -0000	1.17
  @@ -2,6 +2,7 @@
   
   import junit.framework.TestCase;
   import org.apache.ojb.broker.TestHelper;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   import org.odmg.DBag;
   import org.odmg.DList;
   import org.odmg.DSet;
  @@ -19,11 +20,10 @@
   {
       public static void main(String[] args)
       {
  -        String[] arr = {CLASS.getName()};
  +        String[] arr = {DListTest.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  -    private static Class CLASS = DListTest.class;
       private String databaseName;
   
       public DListTest(String name)
  @@ -32,16 +32,13 @@
           super(name);
       }
   
  -    protected Article createArticle(Implementation implementation) throws Exception
  +    protected DListObject createObject(String name) throws Exception
       {
  +        DListObject obj = new DListObject();
  +        obj.setName(name);
  +        obj.setRandomName("rnd_"+((int)(Math.random()*1000)));
   
  -        Article a = new Article();
  -        a.setArticleName("New Funny Article " + a.getArticleId());
  -        a.setStock(234);
  -        a.setProductGroupId(7);
  -
  -        return a;
  -
  +        return obj;
       }
   
       public void setUp()
  @@ -57,7 +54,7 @@
       public void testAdding() throws Exception
       {
           // create a unique name:
  -        String name = "testAdding_" + System.currentTimeMillis();
  +        final String name = "testAdding_" + System.currentTimeMillis();
   
           // get facade instance
           Implementation odmg = OJB.getInstance();
  @@ -70,7 +67,6 @@
           DList list = odmg.newDList();
           db.bind(list, name);
           tx.commit();
  -
           tx = odmg.newTransaction();
           tx.begin();
           Object obj = db.lookup(name);
  @@ -81,7 +77,7 @@
           tx.begin();
           for (int i = 0; i < 5; i++)
           {
  -            Article a = createArticle(odmg);
  +            DListObject a = createObject(name);
               list.add(a);
           }
           tx.commit();
  @@ -89,7 +85,7 @@
           Iterator iter = list.iterator();
           while (iter.hasNext())
           {
  -            Article a = (Article) iter.next();
  +            DListObject a = (DListObject) iter.next();
               assertNotNull(a);
           }
   
  @@ -105,11 +101,11 @@
           Iterator iter1 = list.iterator();
           while (iter.hasNext())
           {
  -            Article a = (Article) iter.next();
  -            Article b = (Article) iter1.next();
  +            DListObject a = (DListObject) iter.next();
  +            DListObject b = (DListObject) iter1.next();
               assertNotNull(a);
               assertNotNull(b);
  -            assertEquals(a.getArticleId(), b.getArticleId());
  +            assertEquals(a.getId(), b.getId());
   
               //System.out.print(a.getArticleId() + ", ");
           }
  @@ -140,7 +136,7 @@
   
           for (int i = 0; i < 5; i++)
           {
  -            Article a = createArticle(odmg);
  +            DListObject a = createObject(name);
               list.add(a);
           }
           assertEquals(5, list.size());
  @@ -189,19 +185,13 @@
           tx.begin();
           for (int i = 0; i < 5; i++)
           {
  -            Article a = createArticle(odmg);
  +            DListObject a = createObject(name);
               list.add(a);
           }
   
  -        Article a = createArticle(odmg);
  -        list.add(2, a);
  -        // printDList(list);
  -        a = createArticle(odmg);
  -        list.add(0, a);
  -        // printDList(list);
  -        a = createArticle(odmg);
  -        list.add(7, a);
  -        // printDList(list);
  +        list.add(2, createObject(name+"_pos2"));
  +        list.add(0, createObject(name+"_pos0"));
  +        list.add(7, createObject(name+"_pos7"));
           tx.commit();
   
           tx.begin();
  @@ -212,9 +202,10 @@
   
           //System.out.println("sequence of items in list:");
           Iterator iter = list.iterator();
  +        DListObject a;
           while (iter.hasNext())
           {
  -            a = (Article) iter.next();
  +            a = (DListObject) iter.next();
               assertNotNull(a);
               //System.out.print(a.getArticleId() + ", ");
           }
  @@ -230,13 +221,14 @@
           iter = lookedUp.iterator();
           while (iter.hasNext())
           {
  -            a = (Article) iter.next();
  +            a = (DListObject) iter.next();
           }
           tx.commit();
       }
   
       public void testDBag() throws Exception
       {
  +        String name = "testDBag_" + System.currentTimeMillis();
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
  @@ -246,12 +238,12 @@
           tx.begin();
           DBag bag1 = odmg.newDBag();
           DBag bag2 = odmg.newDBag();
  -        Article a, b, c, d, e;
  -        a = createArticle(odmg);
  -        b = createArticle(odmg);
  -        c = createArticle(odmg);
  -        d = createArticle(odmg);
  -        e = createArticle(odmg);
  +        DListObject a, b, c, d, e;
  +        a = createObject(name);
  +        b = createObject(name);
  +        c = createObject(name);
  +        d = createObject(name);
  +        e = createObject(name);
           bag1.add(a);
           bag1.add(b);
           bag1.add(c);
  @@ -270,8 +262,9 @@
   
       public void testDSet() throws Exception
       {
  -        String name_1 = "set_1_" + System.currentTimeMillis();
  -        String name_2 = "set_2_" + System.currentTimeMillis();
  +        String name = "testDSet_" + System.currentTimeMillis();
  +        String set_1 = "set_1_" + System.currentTimeMillis();
  +        String set_2 = "set_2_" + System.currentTimeMillis();
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
  @@ -280,14 +273,16 @@
           Transaction tx = odmg.newTransaction();
           tx.begin();
   
  +        DListObject a, b, c, d, e;
  +        a = createObject(name);
  +        b = createObject(name);
  +        c = createObject(name);
  +        d = createObject(name);
  +        e = createObject(name);
  +
           DSet set1 = odmg.newDSet();
           DSet set2 = odmg.newDSet();
  -        Article a, b, c, d, e;
  -        a = createArticle(odmg);
  -        b = createArticle(odmg);
  -        c = createArticle(odmg);
  -        d = createArticle(odmg);
  -        e = createArticle(odmg);
  +
           set1.add(a);
           set1.add(b);
           set1.add(c);
  @@ -297,16 +292,16 @@
           set2.add(d);
           set2.add(e);
   
  -        db.bind(set1, name_1);
  -        db.bind(set2, name_2);
  +        db.bind(set1, set_1);
  +        db.bind(set2, set_2);
           tx.commit();
   
           // low lookup both sets
           tx = odmg.newTransaction();
           tx.begin();
           ((HasBroker) tx).getBroker().clearCache();
  -        DSet set1a = (DSet) db.lookup(name_1);
  -        DSet set2a = (DSet) db.lookup(name_2);
  +        DSet set1a = (DSet) db.lookup(set_1);
  +        DSet set2a = (DSet) db.lookup(set_2);
   
           // check looked up sets
           assertTrue(set1a.containsAll(set1));
  @@ -331,5 +326,71 @@
           assertTrue(!set1.properSubsetOf(set2));
   
           tx.commit();
  +    }
  +
  +    public static class DListObject
  +    {
  +        Integer id;
  +        String name;
  +        String randomName;
  +
  +        public DListObject()
  +        {
  +        }
  +
  +        public boolean equals(Object obj)
  +        {
  +            if(obj instanceof DListObject)
  +            {
  +                String all = id + name+ randomName;
  +                DListObject target = ((DListObject)obj);
  +                return all != null
  +                        ? all.equals(target.getId()+target.getName()+target.getRandomName())
  +                        : target.getId()+target.getName()+target.getRandomName() == null;
  +            }
  +            else
  +            {
  +                return false;
  +            }
  +        }
  +
  +        public String toString()
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this);
  +            buf.append("id", id);
  +            buf.append("name", name);
  +            buf.append("randonName", randomName);
  +            return buf.toString();
  +        }
  +
  +        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 String getRandomName()
  +        {
  +            return randomName;
  +        }
  +
  +        public void setRandomName(String randomName)
  +        {
  +            this.randomName = randomName;
  +        }
       }
   }
  
  
  
  1.89      +24 -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.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- repository_junit.xml	22 Aug 2003 22:01:30 -0000	1.88
  +++ repository_junit.xml	30 Aug 2003 23:07:43 -0000	1.89
  @@ -2740,6 +2740,29 @@
       </class-descriptor>
   
   
  +    <class-descriptor
  +   	  class="org.apache.ojb.odmg.DListTest$DListObject"
  +   	  table="ODMG_DLIST"
  +    >
  +        <field-descriptor
  +         name="id"
  +         column="ID"
  +         jdbc-type="INTEGER"
  +         primarykey="true"
  +         autoincrement="true"
  +        />
  +        <field-descriptor
  +         name="name"
  +         column="NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +        <field-descriptor
  +         name="randomName"
  +         column="RND_NAME"
  +         jdbc-type="VARCHAR"
  +        />
  +   </class-descriptor>
  +
   <!-- ************************************************* -->
   <!--      User posted test case                        -->
   <!-- ************************************************* -->
  @@ -3499,8 +3522,7 @@
           />
       </class-descriptor>
   
  -
  -
  +    
   <!-- ************************************************* -->
   <!--      Reference test with extents                  -->
   <!-- ************************************************* -->
  
  
  

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