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 Thu, 03 Nov 2005 12:16:32 GMT
arminw      2005/11/03 04:16:31

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        M2NTest.java
  Log:
  fix problem with commons StopWatch class, add new test, extend tests, minor improvements
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.8   +106 -38   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.7
  retrieving revision 1.7.2.8
  diff -u -r1.7.2.7 -r1.7.2.8
  --- M2NTest.java	8 Aug 2005 13:18:48 -0000	1.7.2.7
  +++ M2NTest.java	3 Nov 2005 12:16:31 -0000	1.7.2.8
  @@ -51,6 +51,28 @@
           super.tearDown();
       }
   
  +    public void testSimpleStore()
  +    {
  +        changeMovieCollectionDescriptorTo(true, OBJECT, OBJECT, false);
  +        changeActorCollectionDescriptorTo(true, OBJECT, OBJECT, false);
  +        String postfix = "testSimple_" + System.currentTimeMillis();
  +        Movie m = new MovieImpl(postfix, postfix, null);
  +        Actor a = new Actor(postfix);
  +
  +        broker.beginTransaction();
  +        broker.store(m);
  +        broker.store(a);
  +
  +        m.addActor(a);
  +        broker.store(m);
  +        broker.commitTransaction();
  +
  +        broker.retrieveAllReferences(a);
  +
  +        assertNotNull(a.getMovies());
  +        assertEquals(1, a.getMovies().size());
  +    }
  +
       /**
        * Test deprecated auto Settings
        */
  @@ -141,7 +163,7 @@
           //*****************************
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           movie = (Movie) broker.getObjectByIdentity(oid);
   
           resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -171,7 +193,7 @@
           //*****************************
   
           broker.clearCache();
  -        oid = new Identity(actor, broker);
  +        oid = broker.serviceIdentity().buildIdentity(actor);
           actor = (Actor) broker.getObjectByIdentity(oid);
   
           resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -278,7 +300,7 @@
           //*****************************
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           movie = (Movie) broker.getObjectByIdentity(oid);
   
           resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -308,7 +330,7 @@
           //*****************************
   
           broker.clearCache();
  -        oid = new Identity(actor, broker);
  +        oid = broker.serviceIdentity().buildIdentity(actor);
           actor = (Actor) broker.getObjectByIdentity(oid);
   
           resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -552,7 +574,7 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           // auto-retrieve false
  @@ -650,8 +672,8 @@
           stored - no other inserts!
           */
           Query queryMovie = queryMovie(postfix);
  -        Collection resultMovie = broker.getCollectionByQuery(queryMovie);
  -        assertEquals(1, resultMovie.size());
  +        Collection collMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(1, collMovie.size());
   
           Query queryActor = queryActor(postfix);
           Collection resultActor = broker.getCollectionByQuery(queryActor);
  @@ -684,8 +706,8 @@
           /*
           now we expect all stored objects
           */
  -        resultMovie = broker.getCollectionByQuery(queryMovie);
  -        assertEquals(1, resultMovie.size());
  +        collMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(1, collMovie.size());
   
           resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(3, resultActor.size());
  @@ -694,13 +716,39 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           // auto-retrieve true
           assertTrue(readMovie.getActors() != null);
           assertEquals(3, readMovie.getActors().size());
   
  +        // Now we want to add new objects
  +        Actor a1 = new Actor(postfix);
  +        Actor a2 = new Actor(postfix);
  +        readMovie.addActor(a1);
  +        readMovie.addActor(a2);
  +        broker.beginTransaction();
  +        broker.store(a1);
  +        broker.store(a2);
  +        broker.serviceBrokerHelper().unlink(readMovie, "actors");
  +        broker.serviceBrokerHelper().link(readMovie, "actors", true);
  +        broker.commitTransaction();
  +
  +        collMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(1, collMovie.size());
  +        resultActor = broker.getCollectionByQuery(queryActor);
  +        assertEquals(5, resultActor.size());
  +        resultRole = broker.getCollectionByQuery(queryRole);
  +        assertEquals(5, resultRole.size());
  +        broker.clearCache();
  +        oid = broker.serviceIdentity().buildIdentity(movie);
  +        readMovie = (Movie) broker.getObjectByIdentity(oid);
  +        assertNotNull(readMovie);
  +        // auto-retrieve true
  +        assertTrue(readMovie.getActors() != null);
  +        assertEquals(5, readMovie.getActors().size());
  +
           // We try to delete all objects
           // first do unlink the m:n references
           broker.beginTransaction();
  @@ -713,30 +761,32 @@
   
           broker.clearCache();
           // TODO: replace this with query below (when prefetching bug was solved)
  -        Movie movieLookup = (Movie) broker.getObjectByIdentity(new Identity(movie, broker));
  -        assertNotNull(movieLookup);
  -        //resultMovie = broker.getCollectionByQuery(queryMovie);
  -        //assertEquals(1, resultMovie.size());
  +        //Movie movieLookup = (Movie) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(movie));
  +        //assertNotNull(movieLookup);
  +        collMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(1, collMovie.size());
  +        readMovie = (Movie) collMovie.iterator().next();
  +        assertEquals(0, readMovie.getActors().size());
   
           resultActor = broker.getCollectionByQuery(queryActor);
  -        assertEquals(3, resultActor.size());
  +        assertEquals(5, resultActor.size());
   
           resultRole = broker.getCollectionByQuery(queryRole);
           assertEquals(0, resultRole.size());
   
           // now we delete the n- and m-side objects
           broker.beginTransaction();
  -        Iterator iter = movie.getActors().iterator();
  +        Iterator iter = resultActor.iterator();
           while(iter.hasNext())
           {
               broker.delete(iter.next());
           }
  -        broker.delete(movie);
  +        broker.delete(readMovie);
           broker.commitTransaction();
   
  -        broker.clearCache();
  -        resultMovie = broker.getCollectionByQuery(queryMovie);
  -        assertEquals(0, resultMovie.size());
  +        // broker.clearCache();
  +        collMovie = broker.getCollectionByQuery(queryMovie);
  +        assertEquals(0, collMovie.size());
   
           resultActor = broker.getCollectionByQuery(queryActor);
           assertEquals(0, resultActor.size());
  @@ -789,7 +839,7 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           assertEquals(3, readMovie.getActors().size());
  @@ -830,7 +880,7 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           assertEquals(3, readMovie.getActors().size());
  @@ -881,7 +931,7 @@
           //*****************************
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           movie = (Movie) broker.getObjectByIdentity(oid);
   
           resultMovie = broker.getCollectionByQuery(queryMovie);
  @@ -923,7 +973,7 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(actor, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(actor);
           Actor loadedActor = (Actor) broker.getObjectByIdentity(oid);
           assertNotNull(loadedActor);
           MovieManageableCollection col = loadedActor.getMovies();
  @@ -958,6 +1008,7 @@
           Actor a_1 = new Actor("testAddNewEntries_"+postfix);
           Actor a_2 = new Actor("testAddNewEntries_"+postfix);
           Actor a_3 = new Actor("testAddNewEntries_"+postfix);
  +        Actor a_4 = new Actor("testAddNewEntries_"+postfix);
           /*
           all in all we expect 3 movie, 6 actor, 3 role entries after first
           store.
  @@ -985,7 +1036,7 @@
           assertEquals(3, resultRole.size());
   
           broker.clearCache();
  -        Identity oid = new Identity(movie, broker);
  +        Identity oid = broker.serviceIdentity().buildIdentity(movie);
           Movie readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
           assertEquals(3, readMovie.getActors().size());
  @@ -998,6 +1049,8 @@
           */
           movie.getActors().add(a_1);
           movie.getActors().add(a_2);
  +        // add new actor object
  +        movie.getActors().add(a_4);
           broker.beginTransaction();
           broker.store(movie);
           broker.commitTransaction();
  @@ -1010,17 +1063,17 @@
   
           queryActor = queryActor(postfix);
           resultActor = broker.getCollectionByQuery(queryActor);
  -        assertEquals(6, resultActor.size());
  +        assertEquals(7, resultActor.size());
   
           queryRole = queryRole(null, movie);
           resultRole = broker.getCollectionByQuery(queryRole);
  -        assertEquals(5, resultRole.size());
  +        assertEquals(6, resultRole.size());
   
           broker.clearCache();
  -        oid = new Identity(movie, broker);
  +        oid = broker.serviceIdentity().buildIdentity(movie);
           readMovie = (Movie) broker.getObjectByIdentity(oid);
           assertNotNull(readMovie);
  -        assertEquals(5, readMovie.getActors().size());
  +        assertEquals(6, readMovie.getActors().size());
   
           /*
           on delete we expect that all entries are deleted except the single
  @@ -1048,16 +1101,14 @@
       {
           Criteria c = new Criteria();
           c.addLike("idStr", "%" + postfix + "%");
  -        Query q = QueryFactory.newQuery(Movie.class, c);
  -        return q;
  +        return QueryFactory.newQuery(Movie.class, c);
       }
   
       Query queryActor(String postfix)
       {
           Criteria c = new Criteria();
           c.addLike("name", "%" + postfix + "%");
  -        Query q = QueryFactory.newQuery(Actor.class, c);
  -        return q;
  +        return QueryFactory.newQuery(Actor.class, c);
       }
   
       Query queryRole(Actor actor, Movie movie)
  @@ -1076,8 +1127,7 @@
               c.addEqualTo("movieIntId", movie.getIdInt());
               c.addEqualTo("movieStrId", movie.getIdStr());
           }
  -        Query q = QueryFactory.newQuery(Role.class, c);
  -        return q;
  +        return QueryFactory.newQuery(Role.class, c);
       }
   
       Query roleQueryActorOrMovieMatch(Actor actor, Movie movie)
  @@ -1098,8 +1148,7 @@
           {
               c_2 = c_1;
           }
  -        Query q = QueryFactory.newQuery(Role.class, c_2);
  -        return q;
  +        return QueryFactory.newQuery(Role.class, c_2);
       }
   
       /**
  @@ -1333,6 +1382,15 @@
               this.movies = movies;
           }
   
  +        public void addMovie(Movie m)
  +        {
  +            if(movies == null)
  +            {
  +                movies = new MovieManageableCollection();
  +            }
  +            movies.add(m);
  +        }
  +
           public Integer getId()
           {
               return id;
  @@ -1373,6 +1431,7 @@
       {
           public Collection getActors();
           public void setActors(Collection actors);
  +        public void addActor(Actor a);
   
           public Collection getActors2();
           public void setActors2(Collection actors);
  @@ -1424,6 +1483,15 @@
               this.actors = actors;
           }
   
  +        public void addActor(Actor a)
  +        {
  +            if(actors == null)
  +            {
  +                actors = new ArrayList();
  +            }
  +            actors.add(a);
  +        }
  +
           public Collection getActors2()
           {
               return actors2;
  
  
  

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