db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm DependentTests.java
Date Tue, 02 Mar 2004 01:23:40 GMT
olegnitz    2004/03/01 17:23:40

  Modified:    src/test/org/apache/ojb/otm DependentTests.java
  Log:
  Test Joerg's fasion of updating object
  
  Revision  Changes    Path
  1.4       +46 -6     db-ojb/src/test/org/apache/ojb/otm/DependentTests.java
  
  Index: DependentTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/DependentTests.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DependentTests.java	28 Feb 2004 21:38:38 -0000	1.3
  +++ DependentTests.java	2 Mar 2004 01:23:40 -0000	1.4
  @@ -44,11 +44,28 @@
           Query q;
           Iterator it;
   
  +        Transaction tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        // prepare tables for the test - empty them
  +        q = QueryFactory.newQuery(AddressDesc.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        q = QueryFactory.newQuery(Person.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        q = QueryFactory.newQuery(Address.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        tx.commit();
  +
           person.setMainAddress(address1);
           person.addOtherAddress("work", address2);
           person.addOtherAddress("dream", address3);
   
  -        Transaction tx = _kit.getTransaction(_conn);
  +        tx = _kit.getTransaction(_conn);
           tx.begin();
           // Cascade create
           _conn.makePersistent(person);
  @@ -132,10 +149,27 @@
           Query q;
           Iterator it;
   
  +        Transaction tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        // prepare tables for the test - empty them
  +        q = QueryFactory.newQuery(Debitor.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        q = QueryFactory.newQuery(AbstractPerson.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        q = QueryFactory.newQuery(Address2.class, emptyCriteria);
  +        for (it = _conn.getIteratorByQuery(q); it.hasNext(); ) {
  +            _conn.deletePersistent(it.next());
  +        }
  +        tx.commit();
  +
           person.getAddresses().add(address);
           debitor.setAbstractPerson(person);
   
  -        Transaction tx = _kit.getTransaction(_conn);
  +        tx = _kit.getTransaction(_conn);
           tx.begin();
           // Cascade create
           _conn.makePersistent(debitor);
  @@ -178,15 +212,24 @@
           debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
           person = (LegalPerson) debitor.getAbstractPerson();
           assertTrue("address exists", (person.getAddresses().size() == 1));
  +        tx.commit();
   
           // Change dependent reference, should delete old dependant
           debitor.setAbstractPerson(new NaturalPerson());
  +
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        _conn.makePersistent(debitor);
           tx.commit();
   
           _conn.invalidateAll();
           tx = _kit.getTransaction(_conn);
           tx.begin();
           assertTrue("old person has been deleted", (_conn.getObjectByIdentity(personOid)
== null));
  +        q = QueryFactory.newQuery(Address2.class, emptyCriteria);
  +        it = _conn.getIteratorByQuery(q);
  +        assertTrue("old address has been deleted", !it.hasNext());
  +        assertTrue("new person has correct type", (debitor.getAbstractPerson() instanceof
NaturalPerson));
   
           // Cascade delete
           _conn.deletePersistent(debitor);
  @@ -197,12 +240,9 @@
           tx.begin();
           debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
           assertTrue("debitor doesn't exist", (debitor == null));
  -        q = QueryFactory.newQuery(LegalPerson.class, emptyCriteria);
  +        q = QueryFactory.newQuery(AbstractPerson.class, emptyCriteria);
           it = _conn.getIteratorByQuery(q);
           assertTrue("persons don't exist", !it.hasNext());
  -        q = QueryFactory.newQuery(Address2.class, emptyCriteria);
  -        it = _conn.getIteratorByQuery(q);
  -        assertTrue("addresses don't exist", !it.hasNext());
           tx.commit();
       }
   }
  
  
  

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