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 MtoNMapping.java
Date Wed, 02 Apr 2003 21:07:11 GMT
arminw      2003/04/02 13:07:11

  Modified:    src/test/org/apache/ojb/odmg ManyToManyTest.java
               src/test/org/apache/ojb/broker MtoNMapping.java
  Log:
  add new test cases check behaviour
  of list/collection update
  
  Revision  Changes    Path
  1.7       +151 -0    db-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java
  
  Index: ManyToManyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ManyToManyTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ManyToManyTest.java	21 Jan 2003 08:49:32 -0000	1.6
  +++ ManyToManyTest.java	2 Apr 2003 21:07:11 -0000	1.7
  @@ -244,4 +244,155 @@
           assertEquals(2, fishs.size());
       }
   
  +    /**
  +     * main object gourment has list of food objects, this
  +     * test check if we add one food object to the list
  +     * and lock the main object, do get an updated list
  +     */
  +    public void testMtoNPolymorphUpdate() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Fish tuna = new Fish("tuna_" + timestamp, 242, "salt");
  +        Fish trout = new Fish("trout_" + timestamp, 52, "fresh water");
  +        Fish goldfish = new Fish("goldfish_" + timestamp, 10, "brackish water");
  +
  +        ODMGGourmet paula = new ODMGGourmet("a_testMtoNTogether"+ timestamp);
  +        ODMGGourmet candy = new ODMGGourmet("b_testMtoNTogether"+ timestamp);
  +        ODMGGourmet james = new ODMGGourmet("c_testMtoNTogether"+ timestamp);
  +        ODMGGourmet doris = new ODMGGourmet("d_testMtoNTogether"+ timestamp);
  +
  +        paula.addFavoriteFood(trout);
  +        candy.addFavoriteFood(tuna);
  +        james.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(trout);
  +
  +        /*
  +        we expect one created 'gourment' per store
  +        */
  +        assertEquals(1, store(odmg, db, paula));
  +        assertEquals(1, store(odmg, db, candy));
  +        assertEquals(1, store(odmg, db, james));
  +        assertEquals(1, store(odmg, db, doris));
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select fishs from " + Fish.class.getName() +
  +                " where (name=$1 or name=$2)");
  +        query.bind(tuna.getName());
  +        query.bind(trout.getName());
  +        List fishs = (List) query.execute();
  +        /*
  +        we expect 2 created 'fish'
  +        */
  +        assertEquals(2, fishs.size());
  +
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select gourmets from " + ODMGGourmet.class.getName() +
  +                " where name=$1");
  +        query.bind(doris.getName());
  +        List result = (List) query.execute();
  +        assertEquals("We should found a gourmet", 1, result.size());
  +        ODMGGourmet gourmet = (ODMGGourmet)result.get(0);
  +
  +        /*
  +        now we lock main object and add a new reference object
  +        */
  +        tx.lock(gourmet, Transaction.WRITE);
  +        gourmet.addFavoriteFood(goldfish);
  +        tx.commit();
  +
  +        query = odmg.newOQLQuery();
  +        query.create("select fishs from " + Fish.class.getName() +
  +                " where (name=$1 or name=$2 or name=$3)");
  +        query.bind(tuna.getName());
  +        query.bind(trout.getName());
  +        query.bind(goldfish.getName());
  +
  +        tx = odmg.newTransaction();
  +        tx.begin();
  +        fishs = (List) query.execute();
  +        tx.commit();
  +        assertEquals("seems referenced object was not added (if found <3) ",3, fishs.size());
  +    }
  +
  +    /**
  +     * main object gourment has list of food objects, this
  +     * test check if we delete one food object from the list
  +     * and lock the main object, do get an updated list
  +     */
  +    public void testMtoNPolymorphDelete() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Fish tuna = new Fish("tuna_" + timestamp, 242, "salt");
  +        Fish trout = new Fish("trout_" + timestamp, 52, "fresh water");
  +        Fish goldfish = new Fish("goldfish_" + timestamp, 10, "brackish water");
  +
  +        ODMGGourmet paula = new ODMGGourmet("a_testMtoNTogether"+ timestamp);
  +        ODMGGourmet candy = new ODMGGourmet("b_testMtoNTogether"+ timestamp);
  +        ODMGGourmet james = new ODMGGourmet("c_testMtoNTogether"+ timestamp);
  +        ODMGGourmet doris = new ODMGGourmet("d_testMtoNTogether"+ timestamp);
  +
  +        paula.addFavoriteFood(trout);
  +        candy.addFavoriteFood(tuna);
  +        james.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(trout);
  +        doris.addFavoriteFood(goldfish);
  +
  +        /*
  +        we expect one created 'gourment' per store
  +        */
  +        assertEquals(1, store(odmg, db, paula));
  +        assertEquals(1, store(odmg, db, candy));
  +        assertEquals(1, store(odmg, db, james));
  +        assertEquals(1, store(odmg, db, doris));
  +
  +        OQLQuery query = odmg.newOQLQuery();
  +        query.create("select fishs from " + Fish.class.getName() +
  +                " where (name=$1 or name=$2 or name=$3)");
  +        query.bind(tuna.getName());
  +        query.bind(trout.getName());
  +        query.bind(goldfish.getName());
  +
  +        List fishs = (List) query.execute();
  +        /*
  +        we expect 3 created 'fish'
  +        */
  +        assertEquals(3, fishs.size());
  +
  +        Transaction tx = odmg.newTransaction();
  +        tx.begin();
  +        query = odmg.newOQLQuery();
  +        query.create("select gourmets from " + ODMGGourmet.class.getName() +
  +                " where name=$1");
  +        query.bind(doris.getName());
  +        List result = (List) query.execute();
  +        assertEquals("We should found a gourmet_doris", 1, result.size());
  +        ODMGGourmet gourmet_doris = (ODMGGourmet)result.get(0);
  +        assertEquals(3, gourmet_doris.getFavoriteFood().size());
  +
  +        /*
  +        now we lock main object and add remove a reference object
  +        */
  +        List foodList = gourmet_doris.getFavoriteFood();
  +        foodList.remove(0);
  +        tx.lock(gourmet_doris, Transaction.WRITE);
  +        gourmet_doris.setFavoriteFood(foodList);
  +        tx.commit();
  +
  +        query = odmg.newOQLQuery();
  +        query.create("select gourmets from " + ODMGGourmet.class.getName() +
  +                " where name=$1");
  +        query.bind(doris.getName());
  +
  +        tx = odmg.newTransaction();
  +        tx.begin();
  +        result = (List) query.execute();
  +        assertEquals("We should found a gourmet_doris", 1, result.size());
  +        gourmet_doris = (ODMGGourmet)result.get(0);
  +        tx.commit();
  +        assertEquals(2, fishs.size());
  +    }
   }
  
  
  
  1.10      +105 -0    db-ojb/src/test/org/apache/ojb/broker/MtoNMapping.java
  
  Index: MtoNMapping.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/MtoNMapping.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MtoNMapping.java	9 Jan 2003 17:21:14 -0000	1.9
  +++ MtoNMapping.java	2 Apr 2003 21:07:11 -0000	1.10
  @@ -55,6 +55,111 @@
           assertEquals(3, favFood.size());
       }
   
  +    public void testPolymorphMToNUpdate()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Gourmet james = new Gourmet("james");
  +        Identity jamesId = new Identity(james, broker);
  +        Gourmet doris = new Gourmet("doris");
  +        Identity dorisId = new Identity(doris, broker);
  +
  +        Fish tuna = new Fish("tuna", 242, "salt");
  +        Fish trout = new Fish("trout", 52, "fresh water");
  +        Fish goldfish = new Fish("goldfish_"+timestamp, 10, "brackish water");
  +
  +        Salad radiccio = new Salad("Radiccio", 7, "red");
  +        Salad lolloverde = new Salad("Lollo verde", 7, "green");
  +
  +        james.addFavoriteFood(tuna);
  +        james.addFavoriteFood(radiccio);
  +
  +        doris.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(trout);
  +        doris.addFavoriteFood(lolloverde);
  +
  +        broker.beginTransaction();
  +        broker.store(james);
  +        broker.store(doris);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        Gourmet loadedJames = (Gourmet) broker.getObjectByIdentity(jamesId);
  +        List favFood = loadedJames.getFavoriteFood();
  +        assertEquals(2, favFood.size());
  +
  +        Gourmet loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
  +        favFood = loadedDoris.getFavoriteFood();
  +        assertEquals(3, favFood.size());
  +
  +        /*
  +        add new reference object
  +        */
  +        loadedDoris.addFavoriteFood(goldfish);
  +        // update main object
  +        broker.beginTransaction();
  +        broker.store(loadedDoris);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        // query main object
  +        loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
  +        assertEquals(4, loadedDoris.getFavoriteFood().size());
  +    }
  +
  +    public void testPolymorphMToNDelete()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        Gourmet james = new Gourmet("james");
  +        Identity jamesId = new Identity(james, broker);
  +        Gourmet doris = new Gourmet("doris");
  +        Identity dorisId = new Identity(doris, broker);
  +
  +        Fish tuna = new Fish("tuna", 242, "salt");
  +        Fish trout = new Fish("trout", 52, "fresh water");
  +        Fish goldfish = new Fish("goldfish_"+timestamp, 10, "brackish water");
  +
  +        Salad radiccio = new Salad("Radiccio", 7, "red");
  +        Salad lolloverde = new Salad("Lollo verde", 7, "green");
  +
  +        james.addFavoriteFood(tuna);
  +        james.addFavoriteFood(radiccio);
  +
  +        doris.addFavoriteFood(tuna);
  +        doris.addFavoriteFood(trout);
  +        doris.addFavoriteFood(lolloverde);
  +        doris.addFavoriteFood(goldfish);
  +
  +        broker.beginTransaction();
  +        broker.store(james);
  +        broker.store(doris);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +
  +        Gourmet loadedJames = (Gourmet) broker.getObjectByIdentity(jamesId);
  +        List favFood = loadedJames.getFavoriteFood();
  +        assertEquals(2, favFood.size());
  +
  +        Gourmet loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
  +        favFood = loadedDoris.getFavoriteFood();
  +        assertEquals(4, favFood.size());
  +
  +
  +        List foodList = loadedDoris.getFavoriteFood();
  +        foodList.remove(0);
  +        loadedDoris.setFavoriteFood(foodList);
  +        // update main object
  +        broker.beginTransaction();
  +        broker.store(loadedDoris);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        // query main object
  +        loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
  +        assertEquals(3, loadedDoris.getFavoriteFood().size());
  +    }
  +
       public static void main(String[] args)
       {
           String[] arr = {CLASS.getName()};
  
  
  

Mime
View raw message