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 PersonWithArrayTest.java UserTestCases.java
Date Mon, 15 Nov 2004 17:55:15 GMT
arminw      2004/11/15 09:55:15

  Modified:    src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        PersonWithArrayTest.java UserTestCases.java
  Log:
  remove try catch block in test
  add use tx demarcation in test
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.1   +18 -5     db-ojb/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java
  
  Index: PersonWithArrayTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/PersonWithArrayTest.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- PersonWithArrayTest.java	22 Jun 2004 18:16:22 -0000	1.6
  +++ PersonWithArrayTest.java	15 Nov 2004 17:55:15 -0000	1.6.2.1
  @@ -5,12 +5,13 @@
   
   package org.apache.ojb.odmg;
   
  +import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.Collection;
   
   import org.apache.ojb.junit.ODMGTestCase;
  -import org.apache.ojb.odmg.shared.PersonImpl;
   import org.apache.ojb.odmg.shared.Person;
  +import org.apache.ojb.odmg.shared.PersonImpl;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  @@ -207,10 +208,11 @@
           String firstnameFather = "Father" + postfix;
           String firstnameChild_1 = "Child_One" + postfix;
           String firstnameChild_2 = "Child_Two" + postfix;
  +        String lastname = "testStoreThreePersons_3" + postfix;
   
  -        Person father = createPerson(firstnameFather, "testStoreThreePersons_3", null,
null);
  -        Person child_1 = createPerson(firstnameChild_1, "testStoreThreePersons_3", null,
null);
  -        Person child_2 = createPerson(firstnameChild_2, "testStoreThreePersons_3", null,
null);
  +        Person father = createPerson(firstnameFather, lastname, null, null);
  +        Person child_1 = createPerson(firstnameChild_1, lastname, null, null);
  +        Person child_2 = createPerson(firstnameChild_2, lastname, null, null);
   
           Person[] children = new Person[]{child_1, child_2};
           father.setChildren(children);
  @@ -234,14 +236,25 @@
           father.setChildren(null);
           father.setFirstname(null);
   
  +        tx = odmg.newTransaction();
           tx.begin();
           // make sure all objects are retrieved freshly in subsequent transactions
           ((TransactionImpl) tx).getBroker().clearCache();
  +
           OQLQuery qry = odmg.newOQLQuery();
  +        qry.create("select a from " + PersonImpl.class.getName() + " where lastname=$1");
  +        qry.bind(lastname);
  +        Collection result = (Collection) qry.execute();
  +        assertEquals(3, new ArrayList(result).size());
  +
  +
  +        qry = odmg.newOQLQuery();
           qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1");
           qry.bind(firstnameFather);
  -        Collection result = (Collection) qry.execute();
  +        result = (Collection) qry.execute();
  +        tx.commit();
   
  +        tx.begin();
           assertEquals("Exactly one element in result set", 1, result.size());
           Person returnedFather = (Person) result.iterator().next();
           // should retrieve new instance, cause we clear the cache
  
  
  
  1.13.2.1  +17 -21    db-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java
  
  Index: UserTestCases.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/UserTestCases.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -r1.13 -r1.13.2.1
  --- UserTestCases.java	22 Jun 2004 18:16:23 -0000	1.13
  +++ UserTestCases.java	15 Nov 2004 17:55:15 -0000	1.13.2.1
  @@ -3,19 +3,18 @@
   import java.util.List;
   
   import junit.framework.TestCase;
  -
  -import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
  -import org.apache.ojb.odmg.shared.PersonImpl;
   import org.apache.ojb.odmg.shared.Person;
  +import org.apache.ojb.odmg.shared.PersonImpl;
   import org.apache.ojb.odmg.shared.Site;
   import org.odmg.Database;
   import org.odmg.Implementation;
  +import org.odmg.ODMGException;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
  -import org.odmg.ODMGException;
   import org.odmg.TransactionNotInProgressException;
   
   
  @@ -240,10 +239,8 @@
       /**
          * store an object and then retrieve it by id.
          */
  -      public void testStoreRetrieveSameTxn()
  +      public void testStoreRetrieveSameTxn() throws Exception
         {
  -        try
  -        {
             Implementation odmg = OJB.getInstance();
             Database db = odmg.newDatabase();
             //open database
  @@ -255,26 +252,25 @@
             {
               fail("ODMGException: " + ex.getMessage());
             }
  -
  +          String name = "testStoreRetrieveSameTxn_" + System.currentTimeMillis();
             Person mum = new PersonImpl();
  -          TransactionImpl txn = (TransactionImpl)odmg.newTransaction();
  +          mum.setFirstname(name);
  +
  +          TransactionExt txn = (TransactionExt)odmg.newTransaction();
             txn.begin();
             txn.lock(mum, Transaction.WRITE);
  -          System.out.println("locked for write: " + mum);
  -          Identity mumId = new Identity(mum, txn.getBroker());
  +          // System.out.println("locked for write: " + mum);
             txn.commit();
  -          txn.begin();
   
  -          Person mum2 = (Person)txn.getObjectByIdentity(mumId);
  -          System.out.println("retrieved: " + mum2);
  +          txn.begin();
  +          txn.getBroker().clearCache();
  +          Identity mumId = new Identity(mum, txn.getBroker());
  +          Person mum2 = (Person)txn.getBroker().getObjectByIdentity(mumId);
  +          // System.out.println("retrieved: " + mum2);
             txn.commit();
             db.close();
  -        }
  -        catch (Exception exc)
  -        {
  -          exc.printStackTrace();
  -          fail("caught unexpected exception: " + exc.toString());
  -        }
  +          assertNotNull(mum2);
  +          assertEquals(name, mum2.getFirstname());
         }
   
       public void testRetrieveNonExistent()
  
  
  

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