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/broker M2NTest.java
Date Wed, 07 Jul 2004 16:46:24 GMT
arminw      2004/07/07 09:46:24

  Modified:    src/test/org/apache/ojb/broker M2NTest.java
  Log:
  add new test, check adding of new entries in
  existing m:n relation
  
  Revision  Changes    Path
  1.8       +110 -1    db-ojb/src/test/org/apache/ojb/broker/M2NTest.java
  
  Index: M2NTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/M2NTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- M2NTest.java	22 Jun 2004 18:16:22 -0000	1.7
  +++ M2NTest.java	7 Jul 2004 16:46:24 -0000	1.8
  @@ -516,6 +516,115 @@
           Movie movie = col.get(0);
       }
   
  +    public void testAddNewEntriesTTTF()
  +    {
  +        changeMovieCollectionDescriptorTo(true, OBJECT, NONE, false);
  +        changeActorCollectionDescriptorTo(true, OBJECT, NONE, false);
  +        doTestStoreUpdateTTXX();
  +    }
  +
  +    public void testAddNewEntriesTTTT()
  +    {
  +        changeMovieCollectionDescriptorTo(true, OBJECT, NONE, true);
  +        // default proxy does not work for user defined collection 
  +        changeActorCollectionDescriptorTo(true, OBJECT, NONE, false);
  +        doTestStoreUpdateTTXX();
  +    }
  +
  +    public void doTestAddNewEntries()
  +    {
  +        String postfix = "" + System.currentTimeMillis();
  +
  +        /*
  +        Returns 1 movie object with 3 actor objects and one actor object with
  +        back-reference to movie object + 2 new movies
  +        */
  +        Movie movie = buildMovieWithActorsAndBackReferences(postfix);
  +        Actor a_1 = new Actor("testAddNewEntries_"+postfix);
  +        Actor a_2 = new Actor("testAddNewEntries_"+postfix);
  +        Actor a_3 = new Actor("testAddNewEntries_"+postfix);
  +        /*
  +        all in all we expect 3 movie, 6 actor, 3 role entries after first
  +        store.
  +        */
  +
  +        broker.beginTransaction();
  +        broker.store(movie);
  +        broker.store(a_1);
  +        broker.store(a_2);
  +        broker.store(a_3);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        Query queryMovie = movieQuery(postfix);
  +        Collection resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(3, resultMovie.size());
  +
  +        Query queryActor = actorQuery(postfix);
  +        Collection resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(6, resultActor.size());
  +
  +        Query queryRole = roleQuery(null, movie);
  +        Collection resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(3, resultRole.size());
  +
  +        broker.clearCache();
  +        Identity oid = new Identity(movie, broker);
  +        Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
  +        assertNotNull(readMovie);
  +        assertEquals(3, readMovie.getActors().size());
  +
  +        /*
  +        we add 2 existing actor an movie object, thus we expect
  +        3 movie, 6 actor, 5 role entries after store.
  +        And next lookup of movie we expect 5 dependend actor objects
  +        */
  +        movie.getActors().add(a_1);
  +        movie.getActors().add(a_2);
  +        broker.beginTransaction();
  +        broker.store(movie);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        queryMovie = movieQuery(postfix);
  +        resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(3, resultMovie.size());
  +
  +        queryActor = actorQuery(postfix);
  +        resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(6, resultActor.size());
  +
  +        queryRole = roleQuery(null, movie);
  +        resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(5, resultRole.size());
  +
  +        broker.clearCache();
  +        oid = new Identity(movie, broker);
  +        readMovie = (Movie) broker.getObjectByIdentity(oid);
  +        assertNotNull(readMovie);
  +        assertEquals(5, readMovie.getActors().size());
  +
  +        /*
  +        on delete we expect that all entries are deleted except the single
  +        actor which have no references to any movie object
  +        */
  +        broker.beginTransaction();
  +        broker.delete(movie);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(0, resultMovie.size());
  +
  +        resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(1, resultActor.size());
  +
  +        resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(0, resultRole.size());
  +    }
  +
       //=======================================================================
       // helper methods
       //=======================================================================
  
  
  

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