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/odmg DListTest.java
Date Thu, 07 Apr 2005 15:03:46 GMT
arminw      2005/04/07 08:03:46

  Modified:    src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        DListTest.java
  Log:
  fix sorting problem
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.19.2.2  +39 -14    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.19.2.1
  retrieving revision 1.19.2.2
  diff -u -r1.19.2.1 -r1.19.2.2
  --- DListTest.java	3 Apr 2005 01:48:10 -0000	1.19.2.1
  +++ DListTest.java	7 Apr 2005 15:03:46 -0000	1.19.2.2
  @@ -3,6 +3,9 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.Collections;
  +import java.util.Comparator;
   
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.HashCodeBuilder;
  @@ -264,8 +267,8 @@
           final String name = "testAdding_" + System.currentTimeMillis();
   
           // get DList and fill with objects
  -        DList list = odmg.newDList();
  -        Transaction tx = odmg.newTransaction();
  +        List list = odmg.newDList();
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
           tx.begin();
           for (int i = 0; i < 5; i++)
           {
  @@ -276,7 +279,7 @@
           database.bind(list, name);
           tx.commit();
   
  -        tx = odmg.newTransaction();
  +        tx = (TransactionExt) odmg.newTransaction();
           tx.begin();
           Object obj = database.lookup(name);
           tx.commit();
  @@ -291,23 +294,45 @@
           }
           assertEquals(5, list.size());
   
  -        tx = odmg.newTransaction();
  +        tx = (TransactionExt) odmg.newTransaction();
           tx.begin();
  -        ((TransactionExt) odmg.currentTransaction()).getBroker().clearCache();
  -        DList lookedUp = (DList) database.lookup(name);
  +        tx.getBroker().clearCache();
  +
  +        List lookedUp = (List) database.lookup(name);
           tx.commit();
           assertNotNull("binded DList not found", lookedUp);
   
  -        //System.out.println("sequence of items in lookedup list:");
  -        iter = lookedUp.iterator();
  -        Iterator iter1 = list.iterator();
  -        while (iter.hasNext())
  +        // DList doesn't support #set(...) method, so 
  +        list = new ArrayList(list);
  +        lookedUp = new ArrayList(lookedUp);
  +
  +        Collections.sort(list, new Comparator(){
  +            public int compare(Object o1, Object o2)
  +            {
  +                DObject d1 = (DObject) o1;
  +                DObject d2 = (DObject) o2;
  +                return d1.getId().compareTo(d2.getId());
  +            }
  +        });
  +
  +        Collections.sort(lookedUp, new Comparator(){
  +            public int compare(Object o1, Object o2)
  +            {
  +                DObject d1 = (DObject) o1;
  +                DObject d2 = (DObject) o2;
  +                return d1.getId().compareTo(d2.getId());
  +            }
  +        });
  +
  +        assertEquals(list.size(), lookedUp.size());
  +
  +        for(int i = 0; i < lookedUp.size(); i++)
           {
  -            DObject a = (DObject) iter.next();
  -            DObject b = (DObject) iter1.next();
  +            DObject a = (DObject) lookedUp.get(i);
  +            DObject aa = (DObject) list.get(i);
               assertNotNull(a);
  -            assertNotNull(b);
  -            assertEquals(a.getId(), b.getId());
  +            assertNotNull(aa);
  +            assertEquals(a.getId(), aa.getId());
           }
       }
   
  
  
  

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