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 AbstractPerson.java Address2.java Debitor.java LegalPerson.java NaturalPerson.java DependentTests.java
Date Sat, 28 Feb 2004 21:38:38 GMT
olegnitz    2004/02/28 13:38:38

  Modified:    src/test/org/apache/ojb/otm DependentTests.java
  Added:       src/test/org/apache/ojb/otm AbstractPerson.java
                        Address2.java Debitor.java LegalPerson.java
                        NaturalPerson.java
  Log:
  Added test by Joerg Heinicke <joerg.heinicke@gmx.de>
  
  Revision  Changes    Path
  1.3       +83 -0     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DependentTests.java	27 Jul 2003 10:20:09 -0000	1.2
  +++ DependentTests.java	28 Feb 2004 21:38:38 -0000	1.3
  @@ -122,4 +122,87 @@
           assertTrue("addresses don't exist", !it.hasNext());
           tx.commit();
       }
  +
  +    public void testDependent2() throws Exception
  +    {
  +        LegalPerson person = new LegalPerson();
  +        Debitor debitor = new Debitor();
  +        Address2 address = new Address2();
  +        Criteria emptyCriteria = new Criteria();
  +        Query q;
  +        Iterator it;
  +
  +        person.getAddresses().add(address);
  +        debitor.setAbstractPerson(person);
  +
  +        Transaction tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        // Cascade create
  +        _conn.makePersistent(debitor);
  +        tx.commit();
  +
  +        Identity debitorOid = _conn.getIdentity(debitor);
  +        Identity personOid = _conn.getIdentity(person);
  +        int addrId = address.getId();
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  +        assertTrue("debitor exists", (debitor != null));
  +        assertTrue("person exists", (debitor.getAbstractPerson() != null));
  +        assertTrue("person has correct type", (debitor.getAbstractPerson() instanceof LegalPerson));
  +        person = (LegalPerson) debitor.getAbstractPerson();
  +        assertTrue("address exists", (person.getAddresses().size() == 1));
  +        address = (Address2) person.getAddresses().iterator().next();
  +        assertEquals("address is correct", address.getId(), addrId);
  +
  +        // Delete dependent
  +        person.getAddresses().clear();
  +        tx.commit();
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  +        person = (LegalPerson) debitor.getAbstractPerson();
  +        assertTrue("address doesn't exist", (person.getAddresses().size() == 0));
  +
  +        // Create dependent
  +        person.getAddresses().add(address);
  +        tx.commit();
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  +        person = (LegalPerson) debitor.getAbstractPerson();
  +        assertTrue("address exists", (person.getAddresses().size() == 1));
  +
  +        // Change dependent reference, should delete old dependant
  +        debitor.setAbstractPerson(new NaturalPerson());
  +        tx.commit();
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        assertTrue("old person has been deleted", (_conn.getObjectByIdentity(personOid)
== null));
  +
  +        // Cascade delete
  +        _conn.deletePersistent(debitor);
  +        tx.commit();
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  +        assertTrue("debitor doesn't exist", (debitor == null));
  +        q = QueryFactory.newQuery(LegalPerson.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();
  +    }
   }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/AbstractPerson.java
  
  Index: AbstractPerson.java
  ===================================================================
  package org.apache.ojb.otm;
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  public abstract class AbstractPerson
  {
      private int id;
      protected Collection addresses = new ArrayList();
  
      public int getId()
      {
          return id;
      }
  
      public void setId(int id)
      {
          this.id = id;
      }
  
      public Collection getAddresses()
      {
          return addresses;
      }
  
      public void setAddresses(Collection addresses)
      {
          this.addresses = addresses;
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/Address2.java
  
  Index: Address2.java
  ===================================================================
  package org.apache.ojb.otm;
  
  public class Address2
  {
  
      private int id;
      private int personId;
      private Person person;
  
      public int getId()
      {
          return id;
      }
  
      public void setId(int id)
      {
          this.id = id;
      }
  
      public int getPersonId()
      {
          return personId;
      }
  
      public void setPersonId(int personId)
      {
          this.personId = personId;
      }
  
      public Person getPerson()
      {
          return person;
      }
  
      public void setPerson(Person person)
      {
          this.person = person;
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/Debitor.java
  
  Index: Debitor.java
  ===================================================================
  package org.apache.ojb.otm;
  
  public class Debitor
  {
      private int id;
      private AbstractPerson abstractPerson;
      private int personId;
  
      public int getId()
      {
          return id;
      }
  
      public void setId(int id)
      {
          this.id = id;
      }
  
      public AbstractPerson getAbstractPerson()
      {
          return abstractPerson;
      }
  
      public void setAbstractPerson(AbstractPerson abstractPerson)
      {
          this.abstractPerson = abstractPerson;
      }
  
      public int getPersonId()
      {
          return personId;
      }
  
      public void setPersonId(int personId)
      {
          this.personId = personId;
      }
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/LegalPerson.java
  
  Index: LegalPerson.java
  ===================================================================
  package org.apache.ojb.otm;
  
  public class LegalPerson extends AbstractPerson
  {
  }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/otm/NaturalPerson.java
  
  Index: NaturalPerson.java
  ===================================================================
  package org.apache.ojb.otm;
  
  public class NaturalPerson extends AbstractPerson
  {
  }
  
  
  

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