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 Sat, 03 Jan 2004 02:09:31 GMT
arminw      2004/01/02 18:09:31

  Modified:    src/test/org/apache/ojb/broker/metadata MetadataTest.java
               src/test/org/apache/ojb/broker MtoNMapping.java
  Log:
  add new PB-api/kernel test cases
  
  Revision  Changes    Path
  1.15      +11 -0     db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
  
  Index: MetadataTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MetadataTest.java	19 Dec 2003 16:34:32 -0000	1.14
  +++ MetadataTest.java	3 Jan 2004 02:09:31 -0000	1.15
  @@ -64,6 +64,17 @@
           }
       }
   
  +    public void testFindFirstConcreteClassDescriptor()
  +    {
  +        DescriptorRepository dr = MetadataManager.getInstance().getRepository();
  +        ClassDescriptor cld = dr.getDescriptorFor(Repository.SMInterface.class);
  +        ClassDescriptor firstConcrete = dr.findFirstConcreteClass(cld);
  +        assertFalse(firstConcrete.isInterface());
  +        assertFalse(firstConcrete.isAbstract());
  +        firstConcrete = dr.findFirstConcreteClass(cld);
  +        firstConcrete = dr.findFirstConcreteClass(cld);
  +    }
  +
       public void testDescriptorRepository_1()
       {
           MetadataManager mm = MetadataManager.getInstance();
  
  
  
  1.15      +129 -6    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MtoNMapping.java	22 Dec 2003 16:03:33 -0000	1.14
  +++ MtoNMapping.java	3 Jan 2004 02:09:31 -0000	1.15
  @@ -239,7 +239,7 @@
           Criteria crit;
           QueryByCriteria qry;
           Collection col1, col2;
  -        
  +
           broker.clearCache();
   
           crit = new Criteria();
  @@ -250,7 +250,7 @@
           assertNotNull(col1);
   
           broker.clearCache();
  -        
  +
           crit = new Criteria();
           crit.addLessThan("id",new Integer(6));
           qry = QueryFactory.newQuery(Project.class, crit);
  @@ -258,23 +258,23 @@
           qry.addPrefetchedRelationship("persons");
           col2 = broker.getCollectionByQuery(qry);
           assertNotNull(col2);
  -        
  +
           assertEquals("Same size",col1.size(), col2.size());
   
           Iterator it1 = col1.iterator();
           Iterator it2 = col2.iterator();
  -        
  +
           while (it1.hasNext() && it2.hasNext())
           {
               Project p1 = (Project)it1.next();
               Project p2 = (Project)it2.next();
  -            
  +
               assertEquals("Same Title", p1.getTitle(), p2.getTitle());
               assertEquals("Same Number of Persons", p1.getPersons().size(), p2.getPersons().size());
               assertEquals("Same toString", p1.toString(), p2.toString());
           }
       }
  -    
  +
   
       /** test loading of m:n unidirectionally mapped objects*/
       public void testMNLoadingUnidirectional() throws Exception
  @@ -384,6 +384,129 @@
           pers = (Person) broker.getObjectByQuery(query);
           assertEquals(count + 1 , pers.getProjects().size());
   
  +    }
  +
  +    /** Add a new persons with project and delete */
  +    public void testInsertWithIndirectionTable() throws Exception
  +    {
  +        String title = "testInsertAndDelete_2" + System.currentTimeMillis();
  +
  +        broker.beginTransaction();
  +        // create new project and store
  +        Project project = new Project();
  +        project.setTitle(title);
  +        broker.store(project);
  +
  +        // create two persons and assign project
  +        Person p1 = new Person();
  +        p1.setFirstname(title);
  +        List projects_1 = new ArrayList();
  +        projects_1.add(project);
  +        p1.setProjects(projects_1);
  +
  +        Person p2 = new Person();
  +        p2.setFirstname(title);
  +        List projects_2 = new ArrayList();
  +        projects_2.add(project);
  +        p2.setProjects(projects_2);
  +
  +        broker.store(p1);
  +        broker.store(p2);
  +        broker.commitTransaction();
  +
  +        /*
  +        Now I expect two entries in PERSON_PROJECT table
  +        with same project id, two new Person and one Project
  +        entries in PERSON/PROJECT table
  +        */
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("firstname", title);
  +        Query query = new QueryByCriteria(Person.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 2 person instances", 2, result.size());
  +
  +        crit = new Criteria();
  +        crit.addEqualTo("id", new Integer(project.getId()));
  +        query = new QueryByCriteria(Project.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 1 project instance", 1, result.size());
  +        Project newProject = (Project) result.iterator().next();
  +        assertNotNull(newProject.getRoles());
  +        assertEquals("We expect 2 Role objects", 2, newProject.getRoles().size());
  +
  +        // query for role objects representing PERSON_PROJECT entries
  +        crit = new Criteria();
  +        crit.addEqualTo("project_id", new Integer(project.getId()));
  +        query = new QueryByCriteria(Role.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 2 role instances", 2, result.size());
  +    }
  +
  +    /**
  +     * Add a new persons with project and delete. Same as
  +     * {@link #testInsertWithIndirectionTable} but we only store
  +     * the Person objects (no store call for the associated Project)
  +     */
  +    public void testInsertWithIndirectionTable_2() throws Exception
  +    {
  +        String title = "testInsertAndDelete_2" + System.currentTimeMillis();
  +
  +        // create new project
  +        Project project = new Project();
  +        project.setTitle(title);
  +
  +        // create two persons and assign project
  +        Person p1 = new Person();
  +        p1.setFirstname(title);
  +        List projects_1 = new ArrayList();
  +        projects_1.add(project);
  +        p1.setProjects(projects_1);
  +
  +        Person p2 = new Person();
  +        p2.setFirstname(title);
  +        List projects_2 = new ArrayList();
  +        projects_2.add(project);
  +        p2.setProjects(projects_2);
  +
  +        broker.beginTransaction();
  +        broker.store(p1);
  +        broker.store(p2);
  +        broker.commitTransaction();
  +
  +        /*
  +        Now I expect two entries in PERSON_PROJECT table
  +        with same project id, two new Person and one Project
  +        entries in PERSON/PROJECT table
  +        */
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("firstname", title);
  +        Query query = new QueryByCriteria(Person.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 2 person instances", 2, result.size());
  +
  +        crit = new Criteria();
  +        crit.addEqualTo("id", new Integer(project.getId()));
  +        query = new QueryByCriteria(Project.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 1 project instance", 1, result.size());
  +        Project newProject = (Project) result.iterator().next();
  +        assertNotNull(newProject.getRoles());
  +        assertEquals("We expect 2 Role objects", 2, newProject.getRoles().size());
  +
  +        // query for role objects representing PERSON_PROJECT entries
  +        crit = new Criteria();
  +        crit.addEqualTo("project_id", new Integer(project.getId()));
  +        query = new QueryByCriteria(Role.class, crit);
  +        result = broker.getCollectionByQuery(query);
  +        assertNotNull(result);
  +        assertEquals("We expect 2 role instances", 2, result.size());
       }
   
       /** test deleting objects from an m:n association*/
  
  
  

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