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 Thu, 04 Mar 2004 23:46:38 GMT
arminw      2004/03/04 15:46:38

  Modified:    src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker MtoNMapping.java
  Log:
  - update test case to check m:n behaviour
  
  Revision  Changes    Path
  1.107     +2 -1      db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- repository_junit.xml	19 Feb 2004 01:39:40 -0000	1.106
  +++ repository_junit.xml	4 Mar 2004 23:46:38 -0000	1.107
  @@ -2491,6 +2491,7 @@
     	/>
        <collection-descriptor
            name="favoriteFood"
  +         collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
            element-class-ref="org.apache.ojb.broker.InterfaceFood"
            auto-retrieve="true"
            auto-update="true"
  
  
  
  1.22      +28 -19    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- MtoNMapping.java	29 Jan 2004 12:30:55 -0000	1.21
  +++ MtoNMapping.java	4 Mar 2004 23:46:38 -0000	1.22
  @@ -150,17 +150,17 @@
       public void testPolymorphMToNDelete()
       {
           long timestamp = System.currentTimeMillis();
  -        Gourmet james = new Gourmet("james");
  +        Gourmet james = new Gourmet("james_" + timestamp);
           Identity jamesId = new Identity(james, broker);
  -        Gourmet doris = new Gourmet("doris");
  +        Gourmet doris = new Gourmet("doris_" + timestamp);
           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");
  +        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");
   
  -        Salad radiccio = new Salad("Radiccio", 7, "red");
  -        Salad lolloverde = new Salad("Lollo verde", 7, "green");
  +        Salad radiccio = new Salad("Radiccio_" + timestamp, 7, "red");
  +        Salad lolloverde = new Salad("Lollo verde_" + timestamp, 7, "green");
   
           james.addFavoriteFood(tuna);
           james.addFavoriteFood(radiccio);
  @@ -173,6 +173,7 @@
           broker.beginTransaction();
           broker.store(james);
           broker.store(doris);
  +
           broker.commitTransaction();
   
           broker.clearCache();
  @@ -185,6 +186,13 @@
           favFood = loadedDoris.getFavoriteFood();
           assertEquals(4, favFood.size());
   
  +        Criteria c = new Criteria();
  +        c.addLike("name", "%"+timestamp);
  +        Query q = QueryFactory.newQuery(InterfaceFood.class, c);
  +        Collection result = broker.getCollectionByQuery(q);
  +        int foodBeforeRemove = result.size();
  +        assertEquals("Wrong number of InterfaceFood objects", 5, foodBeforeRemove);
  +
   
           List foodList = loadedDoris.getFavoriteFood();
           foodList.remove(0);
  @@ -198,6 +206,8 @@
           // query main object
           loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
           assertEquals(3, loadedDoris.getFavoriteFood().size());
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals("n-side object shouldn't be removed", foodBeforeRemove, result.size());
       }
   
       /** test loading of m:n mapped object nets*/
  @@ -209,10 +219,12 @@
           p.setId(1);
           Query q = QueryFactory.newQuery(p);
           p = (Person) broker.getObjectByQuery(q);
  +        assertNotNull(p);
           Collection projects = p.getProjects();
  -        projects.size();
  -        Project[] projectArray = (Project[]) projects.toArray(new Project[0]); // load
it
           assertNotNull(projects);
  +        assertTrue(projects.size() > 0);
  +
  +        projects.toArray(new Project[0]); // load it
   
           Criteria c = null;
           q = QueryFactory.newQuery(Project.class, c);
  @@ -273,11 +285,9 @@
           Query q = QueryFactory.newQuery(p);
           p = (PersonUnidirectional) broker.getObjectByQuery(q);
           Collection projects = p.getProjects();
  -        projects.size();
  -        ProjectUnidirectional[] projectArray =
  -                (ProjectUnidirectional[]) projects.toArray(new ProjectUnidirectional[0]);
  -        // load it
           assertNotNull(projects);
  +        assertTrue(projects.size() > 0);
  +        projects.toArray(new ProjectUnidirectional[0]); // load it
       }
   
       /** test a manually build association via the association class Role*/
  @@ -300,7 +310,7 @@
           Iterator iter = col.iterator();
           while (iter.hasNext())
           {
  -            Project proj = (Project) iter.next();
  +            iter.next();
               //System.out.println(proj.getRoles());
           }
       }
  @@ -314,7 +324,8 @@
           p = (Person) broker.getObjectByQuery(q);
           assertNotNull("We should found a 'person' for id 1 - check db script", p);
           Collection projects = p.getProjects();
  -        Project[] projectArray = (Project[]) projects.toArray(new Project[0]); // load
it
  +        assertNotNull(projects);
  +        projects.toArray(new Project[0]); // load it
           assertNotNull("Person should have some projects - check db script", projects);
           int count = projects.size();
   
  @@ -645,7 +656,7 @@
           assertNotNull(projects);
           int count = projects.size();
   
  -        Project proj = (Project) projectArray[0];
  +        Project proj = projectArray[0];
   
           Criteria crit = new Criteria();
           crit.addEqualTo("person_id", new Integer(pers.getId()));
  @@ -679,9 +690,7 @@
           p = (PersonUnidirectional) broker.getObjectByQuery(q);
           Collection projects = p.getProjects();
           Collection originalProjects;
  -        ProjectUnidirectional[] projectArray =
  -                (ProjectUnidirectional[]) projects.toArray(new ProjectUnidirectional[0]);
  -        // load it
  +        projects.toArray(new ProjectUnidirectional[0]); // load it
           originalProjects = new Vector();
           originalProjects.addAll(projects);
   
  
  
  

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