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 CollectionsTest.java M2NTest.java
Date Sat, 04 Jun 2005 17:35:19 GMT
arminw      2005/06/04 10:35:19

  Modified:    src/test/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        CollectionsTest.java M2NTest.java
  Log:
  add new tests for new cascading delete feature based on the auto-delete metadata setting
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.13.2.10 +64 -1     db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java
  
  Index: CollectionsTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/CollectionsTest.java,v
  retrieving revision 1.13.2.9
  retrieving revision 1.13.2.10
  diff -u -r1.13.2.9 -r1.13.2.10
  --- CollectionsTest.java	31 Mar 2005 09:39:40 -0000	1.13.2.9
  +++ CollectionsTest.java	4 Jun 2005 17:35:19 -0000	1.13.2.10
  @@ -10,6 +10,7 @@
   
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryFactory;
  @@ -49,6 +50,68 @@
       }
   
   
  +    public void testStoreDeleteCascadeDelete() throws Exception
  +    {
  +        String prefix = "testStoreDeleteCascadeDelete_" + System.currentTimeMillis();
  +        String queryStr = "select gatherer from " + Gatherer.class.getName() + " where
gatId=$1";
  +
  +        ojbChangeReferenceSetting(Gatherer.class, "collectiblesA", true,
  +                CollectionDescriptor.CASCADE_NONE, CollectionDescriptor.CASCADE_OBJECT,
false);
  +
  +        // prepare test case
  +        Gatherer gat = new Gatherer(null, prefix + "_Gatherer");
  +        CollectibleA[] cols = prepareCollectibleA(gat, prefix);
  +        List colList = Arrays.asList(cols);
  +        // set List of CollectiblesA objects
  +        gat.setCollectiblesA(colList);
  +        TransactionExt tx = (TransactionExt)odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(gat);
  +        tx.commit();
  +
  +        // check if gatherer was stored
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create(queryStr);
  +        Integer gatId = gat.getGatId();
  +        assertNotNull(gatId);
  +        query.bind(gatId);
  +        Collection result = (Collection) query.execute();
  +        tx.commit();
  +        assertEquals("Wrong number of objects found", 1, result.size());
  +        Gatherer fetchedGat = (Gatherer) result.iterator().next();
  +
  +        List colsA = fetchedGat.getCollectiblesA();
  +        assertEquals("Wrong number of CollectiblesA", 3, colsA.size());
  +        // check if gatherer contains list of CollectibleBase
  +        tx.begin();
  +        //*************************************
  +        database.deletePersistent(fetchedGat);
  +        //*************************************
  +        tx.commit();
  +
  +        // check if the CollectibleBase was really deleted from DB
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select allCollectibleA from " + CollectibleA.class.getName() +
  +                " where name like $1");
  +        query.bind(prefix + "%");
  +        result = (Collection) query.execute();
  +        assertEquals("Wrong number of objects found", 0, result.size());
  +        tx.commit();
  +
  +        // check if the gatherer now contains a CollectibleBase list
  +        // reduced by the deleted
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create(queryStr);
  +        query.bind(gatId);
  +        result = (Collection) query.execute();
  +        assertEquals("Wrong number of objects found", 0, result.size());
  +        tx.commit();
  +    }
  +
       public void testStoreCollectionElementWithoutBackReference() throws Exception
       {
           // String queryColl = "select colls from " + CollectibleC.class.getName() + " where
name=$1";
  
  
  
  1.3.2.6   +61 -1     db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/M2NTest.java,v
  retrieving revision 1.3.2.5
  retrieving revision 1.3.2.6
  diff -u -r1.3.2.5 -r1.3.2.6
  --- M2NTest.java	9 May 2005 14:26:55 -0000	1.3.2.5
  +++ M2NTest.java	4 Jun 2005 17:35:19 -0000	1.3.2.6
  @@ -556,6 +556,66 @@
           tx.commit();
       }
   
  +    /**
  +     * Use auto-delete="object" to enable cascading delete.
  +     */ 
  +    public void testStoreDeleteCascade() throws Exception
  +    {
  +        String postfix = "doTestStoreDeleteCascade_" + System.currentTimeMillis();
  +
  +        changeMovieCollectionDescriptorTo(true, NONE, OBJECT, true);
  +        changeActorCollectionDescriptorTo(true, NONE, OBJECT, false);
  +
  +        Movie movie = buildMovieWithActors(postfix);
  +
  +        TransactionExt tx = (TransactionExt) odmg.newTransaction();
  +        tx.begin();
  +        database.makePersistent(movie);
  +        tx.commit();
  +
  +        OQLQuery queryMovie = movieQuery(postfix);
  +        Collection resultMovie = (Collection) queryMovie.execute();
  +        assertEquals(1, resultMovie.size());
  +        Movie newMovie = (Movie) resultMovie.iterator().next();
  +        assertNotNull(newMovie.getActors());
  +        assertEquals(3, newMovie.getActors().size());
  +
  +        OQLQuery queryActor = actorQuery(postfix);
  +        Collection resultActor = (Collection) queryActor.execute();
  +        assertEquals(5, resultActor.size());
  +
  +        OQLQuery queryRole = roleQuery(null, movie);
  +        Collection resultRole = (Collection) queryRole.execute();
  +        assertEquals(3, resultRole.size());
  +
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +        queryMovie = movieQuery(postfix);
  +        resultMovie = (Collection) queryMovie.execute();
  +        Movie m = (Movie) resultMovie.iterator().next();
  +        //**********************************************
  +        database.deletePersistent(m);
  +        //*********************************************
  +        tx.commit();
  +
  +        tx.begin();
  +        tx.getBroker().clearCache();
  +
  +        queryMovie = movieQuery(postfix);
  +        resultMovie = (Collection) queryMovie.execute();
  +        assertEquals(0, resultMovie.size());
  +
  +        queryActor = actorQuery(postfix);
  +        resultActor = (Collection) queryActor.execute();
  +        assertEquals(0, resultActor.size());
  +
  +        queryRole = roleQuery(null, movie);
  +        resultRole = (Collection) queryRole.execute();
  +        assertEquals(0, resultRole.size());
  +
  +        tx.commit();
  +    }
  +
       public void testRemoveAssociation() throws Exception
       {
           changeMovieCollectionDescriptorTo(true, NONE, NONE, false);
  
  
  

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