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 Sat, 27 Nov 2004 02:17:48 GMT
arminw      2004/11/26 18:17:47

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        M2NTest.java
  Log:
  minor changes
  add alpha version (commented out) of 'LINK' mode tests
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.4   +160 -51   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.2.3
  retrieving revision 1.7.2.4
  diff -u -r1.7.2.3 -r1.7.2.4
  --- M2NTest.java	19 Nov 2004 19:03:22 -0000	1.7.2.3
  +++ M2NTest.java	27 Nov 2004 02:17:47 -0000	1.7.2.4
  @@ -51,6 +51,25 @@
           super.tearDown();
       }
   
  +    public void testAutoUpdateDeleteSettings()
  +    {
  +        changeActorCollectionDescriptorTo(false, false, false, false);
  +        CollectionDescriptor ord = broker.getClassDescriptor(Actor.class)
  +                .getCollectionDescriptorByName("movies");
  +        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingStore());
  +        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingDelete());
  +        assertEquals(false, ord.getCascadeStore());
  +        assertEquals(false, ord.getCascadeDelete());
  +
  +        changeActorCollectionDescriptorTo(false, true, true, false);
  +        ord = broker.getClassDescriptor(Actor.class)
  +                .getCollectionDescriptorByName("movies");
  +        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingStore());
  +        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingDelete());
  +        assertEquals(true, ord.getCascadeStore());
  +        assertEquals(true, ord.getCascadeDelete());
  +    }
  +
       public void testMassStoreUpdateAutomatic()
       {
   
  @@ -82,7 +101,7 @@
   
           watch.reset();
           watch.start();
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(movieCount + 1, resultMovie.size());
           watch.stop();
  @@ -92,7 +111,7 @@
   
           watch.reset();
           watch.start();
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(actorCount + 1, resultActor.size());
           watch.stop();
  @@ -217,7 +236,7 @@
   
           watch.reset();
           watch.start();
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(movieCount + 1, resultMovie.size());
           watch.stop();
  @@ -227,7 +246,7 @@
   
           watch.reset();
           watch.start();
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(actorCount + 1, resultActor.size());
           watch.stop();
  @@ -312,23 +331,109 @@
           System.out.println("");
       }
   
  -    public void testAutoUpdateDeleteSettings()
  +    //============================================================
  +    // auto-retrieve true / auto-update/auto-delete LINK
  +    //============================================================
  +    // test needs refactoring, LINK settings doesn't allow to store
  +    // an object graph
  +    public void XXXtestStoreAddUpdateDeleteTLLF()
  +    {
  +        changeMovieCollectionDescriptorTo(true, LINK, LINK, false);
  +        changeActorCollectionDescriptorTo(true, LINK, LINK, false);
  +        String postfix = "_testStoreTLLF_" + System.currentTimeMillis();
  +        Movie movie = buildMovieWithActorsAndBackReferences(postfix);
  +        doTestStoreAddUpdateDeleteTLLX(movie, postfix);
  +    }
  +
  +    public void XXXtestStoreAddUpdateDeleteTLLT()
       {
  -        changeActorCollectionDescriptorTo(false, false, false, false);
  -        CollectionDescriptor ord = broker.getClassDescriptor(Actor.class)
  -                .getCollectionDescriptorByName("movies");
  -        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingStore());
  -        assertEquals(CollectionDescriptor.CASCADE_LINK, ord.getCascadingDelete());
  -        assertEquals(false, ord.getCascadeStore());
  -        assertEquals(false, ord.getCascadeDelete());
  +        changeMovieCollectionDescriptorTo(true, LINK, LINK, true);
  +        changeActorCollectionDescriptorTo(true, LINK, LINK, false);
  +        String postfix = "_testStoreTLLF_" + System.currentTimeMillis();
  +        Movie movie = buildMovieWithActorsAndBackReferences(postfix);
  +        doTestStoreAddUpdateDeleteTLLX(movie, postfix);
  +    }
   
  -        changeActorCollectionDescriptorTo(false, true, true, false);
  -        ord = broker.getClassDescriptor(Actor.class)
  -                .getCollectionDescriptorByName("movies");
  -        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingStore());
  -        assertEquals(CollectionDescriptor.CASCADE_OBJECT, ord.getCascadingDelete());
  -        assertEquals(true, ord.getCascadeStore());
  -        assertEquals(true, ord.getCascadeDelete());
  +
  +    public void doTestStoreAddUpdateDeleteTLLX(Movie movie, String postfix)
  +    {
  +        broker.beginTransaction();
  +        broker.store(movie);
  +        broker.commitTransaction();
  +        Identity movieOID = broker.serviceIdentity().buildIdentity(movie);
  +
  +        /*
  +        auto-update setting is LINK, but it behaves same way as OBJECT
  +        */
  +        broker.clearCache();
  +        Query queryMovie = queryMovie(postfix);
  +        Collection resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(3, resultMovie.size());
  +
  +        Query queryActor = queryActor(postfix);
  +        Collection resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(3, resultActor.size());
  +
  +        // first created actor
  +        Actor actor = (Actor) movie.getActors().iterator().next();
  +        Query queryRole = queryRole(actor, movie);
  +        Collection resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(5, resultRole.size());
  +
  +        broker.clearCache();
  +        broker.beginTransaction();
  +        Movie newMovie = (Movie) broker.getObjectByIdentity(movieOID);
  +        newMovie.setTitle("updated_title_" + postfix);
  +        Iterator it = newMovie.getActors().iterator();
  +        while(it.hasNext())
  +        {
  +            Actor a = (Actor) it.next();
  +            a.setName("updated_name_" + postfix);
  +        }
  +        ArrayList list = new ArrayList(newMovie.getActors());
  +        list.add(new Actor("updated_name_" + postfix));
  +        newMovie.setActors(list);
  +        broker.store(newMovie);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        queryMovie = queryMovie(postfix);
  +        resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(3, resultMovie.size());
  +
  +        queryActor = queryActor(postfix);
  +        resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(4, resultActor.size());
  +
  +        // first created actor
  +        actor = (Actor) movie.getActors().iterator().next();
  +        queryRole = queryRole(actor, movie);
  +        resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(6, resultRole.size());
  +
  +        newMovie = (Movie) broker.getObjectByIdentity(movieOID);
  +        assertEquals("updated_title_"+postfix, newMovie.getTitle());
  +        it = newMovie.getActors().iterator();
  +        while(it.hasNext())
  +        {
  +            Actor a = (Actor) it.next();
  +            assertEquals("updated_name_" + postfix, a.getName());
  +        }
  +
  +        // now we delete the movie object
  +        broker.beginTransaction();
  +        broker.delete(newMovie);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        resultMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(2, resultMovie.size());
  +
  +        resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(4, resultActor.size());
  +
  +        resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(2, resultRole.size());
       }
   
       //============================================================
  @@ -399,16 +504,16 @@
           all auto-xxx settings are false, so only the movie object should be
           stored - no other inserts!
           */
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           // auto-update is false, thus we don't expect an Actor object
           assertEquals(0, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           // auto-update is false, thus we don't expect Role objects
           assertEquals(0, resultRole.size());
  @@ -502,9 +607,6 @@
           assertEquals(0, resultRole.size());
       }
   
  -
  -
  -
       //============================================================
       // auto-retrieve true / auto-update/auto-delete false
       //============================================================
  @@ -543,16 +645,16 @@
           auto-update settings is false, so only the movie object should be
           stored - no other inserts!
           */
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           // auto-update is false, thus we don't expect an Actor object
           assertEquals(0, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           // auto-update is false, thus we don't expect Role objects
           assertEquals(0, resultRole.size());
  @@ -669,15 +771,15 @@
           broker.store(movie);
           broker.commitTransaction();
   
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(3, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(3, resultRole.size());
   
  @@ -708,15 +810,15 @@
           broker.store(movie);
           broker.commitTransaction();
   
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(3, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(3, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(3, resultRole.size());
   
  @@ -750,15 +852,15 @@
           broker.store(movie);
           broker.commitTransaction();
   
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(1, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(3, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(3, resultRole.size());
   
  @@ -800,15 +902,15 @@
           broker.commitTransaction();
   
           broker.clearCache();
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(3, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(1, resultActor.size());
   
  -        Query queryRole = roleQuery(actor, null);
  +        Query queryRole = queryRole(actor, null);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(3, resultRole.size());
   
  @@ -862,15 +964,15 @@
   
           broker.clearCache();
   
  -        Query queryMovie = movieQuery(postfix);
  +        Query queryMovie = queryMovie(postfix);
           Collection resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(3, resultMovie.size());
   
  -        Query queryActor = actorQuery(postfix);
  +        Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(6, resultActor.size());
   
  -        Query queryRole = roleQuery(null, movie);
  +        Query queryRole = queryRole(null, movie);
           Collection resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(3, resultRole.size());
   
  @@ -893,15 +995,15 @@
   
           broker.clearCache();
   
  -        queryMovie = movieQuery(postfix);
  +        queryMovie = queryMovie(postfix);
           resultMovie = broker.getCollectionByQuery(queryMovie);
           assertEquals(3, resultMovie.size());
   
  -        queryActor = actorQuery(postfix);
  +        queryActor = queryActor(postfix);
           resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(6, resultActor.size());
   
  -        queryRole = roleQuery(null, movie);
  +        queryRole = queryRole(null, movie);
           resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(5, resultRole.size());
   
  @@ -933,7 +1035,7 @@
       //=======================================================================
       // helper methods
       //=======================================================================
  -    Query movieQuery(String postfix)
  +    Query queryMovie(String postfix)
       {
           Criteria c = new Criteria();
           c.addLike("idStr", "%" + postfix + "%");
  @@ -941,7 +1043,7 @@
           return q;
       }
   
  -    Query actorQuery(String postfix)
  +    Query queryActor(String postfix)
       {
           Criteria c = new Criteria();
           c.addLike("name", "%" + postfix + "%");
  @@ -949,11 +1051,18 @@
           return q;
       }
   
  -    Query roleQuery(Actor actor, Movie movie)
  +    Query queryRole(Actor actor, Movie movie)
       {
           Criteria c = new Criteria();
           if(actor != null) c.addEqualTo("actorId", actor.getId());
  -        if(movie != null)
  +        if(movie != null && actor != null)
  +        {
  +            Criteria c2 = new Criteria();
  +            c2.addEqualTo("movieIntId", movie.getIdInt());
  +            c2.addEqualTo("movieStrId", movie.getIdStr());
  +            c.addOrCriteria(c2);
  +        }
  +        else if(movie != null)
           {
               c.addEqualTo("movieIntId", movie.getIdInt());
               c.addEqualTo("movieStrId", movie.getIdStr());
  
  
  

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