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 DependentTests.java
Date Thu, 04 Mar 2004 22:42:38 GMT
olegnitz    2004/03/04 14:42:38

  Modified:    src/test/org/apache/ojb/otm AbstractPerson.java
                        DependentTests.java
  Log:
  New test from Joerg
  
  Revision  Changes    Path
  1.2       +11 -0     db-ojb/src/test/org/apache/ojb/otm/AbstractPerson.java
  
  Index: AbstractPerson.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/AbstractPerson.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractPerson.java	28 Feb 2004 21:38:38 -0000	1.1
  +++ AbstractPerson.java	4 Mar 2004 22:42:38 -0000	1.2
  @@ -7,6 +7,7 @@
   {
       private int id;
       protected Collection addresses = new ArrayList();
  +    protected String name;
   
       public int getId()
       {
  @@ -26,5 +27,15 @@
       public void setAddresses(Collection addresses)
       {
           this.addresses = addresses;
  +    }
  +
  +    public String getName()
  +    {
  +        return name;
  +    }
  +
  +    public void setName(String name)
  +    {
  +        this.name = name;
       }
   }
  
  
  
  1.5       +39 -15    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DependentTests.java	2 Mar 2004 01:23:40 -0000	1.4
  +++ DependentTests.java	4 Mar 2004 22:42:38 -0000	1.5
  @@ -142,7 +142,7 @@
   
       public void testDependent2() throws Exception
       {
  -        LegalPerson person = new LegalPerson();
  +        AbstractPerson person = new LegalPerson();
           Debitor debitor = new Debitor();
           Address2 address = new Address2();
           Criteria emptyCriteria = new Criteria();
  @@ -183,13 +183,13 @@
           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));
  +        assertNotNull("debitor does not exist", debitor);
  +        person = debitor.getAbstractPerson();
  +        assertNotNull("person does not exist", person);
  +        assertTrue("person has not the expected type", (person instanceof LegalPerson));
  +        assertEquals("address does not exist", person.getAddresses().size(), 1);
           address = (Address2) person.getAddresses().iterator().next();
  -        assertEquals("address is correct", address.getId(), addrId);
  +        assertEquals("addressid is not correct", address.getId(), addrId);
   
           // Delete dependent
           person.getAddresses().clear();
  @@ -200,7 +200,7 @@
           tx.begin();
           debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
           person = (LegalPerson) debitor.getAbstractPerson();
  -        assertTrue("address doesn't exist", (person.getAddresses().size() == 0));
  +        assertEquals("address was not deleted", person.getAddresses().size(), 0);
   
           // Create dependent
           person.getAddresses().add(address);
  @@ -211,12 +211,15 @@
           tx.begin();
           debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
           person = (LegalPerson) debitor.getAbstractPerson();
  -        assertTrue("address exists", (person.getAddresses().size() == 1));
  +        assertEquals("address does not exist", person.getAddresses().size(), 1);
           tx.commit();
   
           // Change dependent reference, should delete old dependant
  -        debitor.setAbstractPerson(new NaturalPerson());
  +        person = new NaturalPerson();
  +        person.setName("before");
  +        debitor.setAbstractPerson(person);
   
  +        _conn.invalidateAll();
           tx = _kit.getTransaction(_conn);
           tx.begin();
           _conn.makePersistent(debitor);
  @@ -225,12 +228,33 @@
           _conn.invalidateAll();
           tx = _kit.getTransaction(_conn);
           tx.begin();
  -        assertTrue("old person has been deleted", (_conn.getObjectByIdentity(personOid)
== null));
  +        assertTrue("old person has not 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));
  +        assertTrue("old address has not been deleted", !it.hasNext());
  +        person = debitor.getAbstractPerson();
  +        assertTrue("new person has unexpected type", (person instanceof NaturalPerson));
  +        assertTrue("person does not have correct name", "before".equals(person.getName()));
  +        tx.commit();
   
  +        person.setName("after");
  +        assertTrue("name of person was not saved", "after".equals(debitor.getAbstractPerson().getName()));
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        _conn.makePersistent(debitor);
  +        tx.commit();
  +        assertTrue("name of person was not saved: " + debitor.getAbstractPerson().getName(),
  +                   "after".equals(debitor.getAbstractPerson().getName()));
  +
  +        _conn.invalidateAll();
  +        tx = _kit.getTransaction(_conn);
  +        tx.begin();
  +        debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  +        person = debitor.getAbstractPerson();
  +        assertTrue("name of person was not saved: " + debitor.getAbstractPerson().getName(),
  +                   "after".equals(debitor.getAbstractPerson().getName()));
           // Cascade delete
           _conn.deletePersistent(debitor);
           tx.commit();
  @@ -239,10 +263,10 @@
           tx = _kit.getTransaction(_conn);
           tx.begin();
           debitor = (Debitor) _conn.getObjectByIdentity(debitorOid);
  -        assertTrue("debitor doesn't exist", (debitor == null));
  +        assertNull("debitor still exists", debitor);
           q = QueryFactory.newQuery(AbstractPerson.class, emptyCriteria);
           it = _conn.getIteratorByQuery(q);
  -        assertTrue("persons don't exist", !it.hasNext());
  +        assertTrue("persons still 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