db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker InheritanceMultipleTableTest.java
Date Sun, 18 Sep 2005 12:01:12 GMT
brj         2005/09/18 05:01:12

  Modified:    src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java
  Log:
  additional testcases for ojb-63
  
  Revision  Changes    Path
  1.18      +109 -33   db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
  
  Index: InheritanceMultipleTableTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- InheritanceMultipleTableTest.java	8 Sep 2005 16:31:10 -0000	1.17
  +++ InheritanceMultipleTableTest.java	18 Sep 2005 12:01:12 -0000	1.18
  @@ -50,10 +50,11 @@
           }
   
           long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
  -        String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  +        String name = "testQueryInheritancedObjects_" + timestamp;
           // store company with Employee/Executive/Manager
  -        Company company = prepareTestDataWithCompany(id_2, name);
  +        Company company = prepareTestDataWithCompany(name);
  +        Long id_2 = company.getId();
  +        
           // add Shareholder too
           Shareholder shareholder = new Shareholder(id_2, name);
           shareholder.setShare(77);
  @@ -73,20 +74,20 @@
           Query query = QueryFactory.newQuery(Employee.class, crit);
           Collection result = broker.getCollectionByQuery(query);
           assertEquals(7, result.size());
  -        int empolyeeCount = 0;
  +        int employeeCount = 0;
           int executiveCount = 0;
           int managerCount = 0;
           int shareholderCount = 0;
           for(Iterator iterator = result.iterator(); iterator.hasNext();)
           {
               Object obj =  iterator.next();
  -            if(obj instanceof Employee) ++empolyeeCount;
  +            if(obj instanceof Employee) ++employeeCount;
               if(obj instanceof Executive) ++executiveCount;
               if(obj instanceof Manager) ++managerCount;
               if(obj instanceof Shareholder) ++shareholderCount;
           }
  -        assertEquals(7, empolyeeCount);
  -        assertEquals(5, executiveCount);
  +        assertEquals(7, employeeCount);
  +        assertEquals(6, executiveCount);
           assertEquals(4, managerCount);
           assertEquals(1, shareholderCount);
   
  @@ -98,19 +99,19 @@
           query = QueryFactory.newQuery(Manager.class, crit);
           result = broker.getCollectionByQuery(query);
           assertEquals(4, result.size());
  -        empolyeeCount = 0;
  +        employeeCount = 0;
           executiveCount = 0;
           managerCount = 0;
           shareholderCount = 0;
           for(Iterator iterator = result.iterator(); iterator.hasNext();)
           {
               Object obj =  iterator.next();
  -            if(obj instanceof Employee) ++empolyeeCount;
  +            if(obj instanceof Employee) ++employeeCount;
               if(obj instanceof Executive) ++executiveCount;
               if(obj instanceof Manager) ++managerCount;
               if(obj instanceof Shareholder) ++shareholderCount;
           }
  -        assertEquals(4, empolyeeCount);
  +        assertEquals(4, employeeCount);
           assertEquals(4, executiveCount);
           assertEquals(4, managerCount);
           assertEquals(1, shareholderCount);
  @@ -123,24 +124,82 @@
           query = QueryFactory.newQuery(Shareholder.class, crit);
           result = broker.getCollectionByQuery(query);
           assertEquals(1, result.size());
  -        empolyeeCount = 0;
  +        employeeCount = 0;
           executiveCount = 0;
           managerCount = 0;
           shareholderCount = 0;
           for(Iterator iterator = result.iterator(); iterator.hasNext();)
           {
               Object obj =  iterator.next();
  -            if(obj instanceof Employee) ++empolyeeCount;
  +            if(obj instanceof Employee) ++employeeCount;
               if(obj instanceof Executive) ++executiveCount;
               if(obj instanceof Manager) ++managerCount;
               if(obj instanceof Shareholder) ++shareholderCount;
           }
  -        assertEquals(1, empolyeeCount);
  +        assertEquals(1, employeeCount);
           assertEquals(1, executiveCount);
           assertEquals(1, managerCount);
           assertEquals(1, shareholderCount);
       }
   
  +    public void testQueryInheritancedObjectsById()
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String name = "testQueryInheritancedObjectsByPk_" + timestamp;
  +        Long id_2 = new Long(timestamp);
  +
  +        List insertedObjs = prepareForQueryTests(id_2, name); 
  +
  +        // add Shareholder 
  +        Shareholder shareholder = new Shareholder(id_2, name);
  +        shareholder.setShare(77);
  +        shareholder.setDepartment("none");
  +        AddressIF ad = new Address(name);
  +        shareholder.setAddress(ad);
  +
  +        broker.beginTransaction();
  +        broker.store(shareholder);
  +        broker.commitTransaction();
  +           
  +        broker.clearCache();
  +
  +        Employee emp1;
  +        Identity ident;
  +        Employee retrievedEmp;
  +
  +        // retrieve Manager by pk
  +        emp1 = (Employee) insertedObjs.get(0);
  +        ident = broker.serviceIdentity().buildIdentity(emp1);
  +        retrievedEmp = (Employee) broker.getObjectByIdentity(ident);
  +        assertNotNull(retrievedEmp);
  +        assertSame(Manager.class, retrievedEmp.getClass());
  +        assertEquals(emp1, retrievedEmp);
  +
  +        // retrieve Executive by pk
  +        emp1 = (Employee) insertedObjs.get(3);
  +        ident = broker.serviceIdentity().buildIdentity(emp1);
  +        retrievedEmp = (Employee) broker.getObjectByIdentity(ident);
  +        assertNotNull(retrievedEmp);
  +        assertSame(Executive.class, retrievedEmp.getClass());
  +        assertEquals(emp1, retrievedEmp);
  +        
  +        // retrieve Employee by pk
  +        emp1 = (Employee) insertedObjs.get(5);
  +        ident = broker.serviceIdentity().buildIdentity(emp1);
  +        retrievedEmp = (Employee) broker.getObjectByIdentity(ident);
  +        assertNotNull(retrievedEmp);
  +        assertSame(Employee.class, retrievedEmp.getClass());
  +        assertEquals(emp1, retrievedEmp);
  +
  +        // retrieve Shareholder by pk
  +        emp1 = shareholder;
  +        ident = broker.serviceIdentity().buildIdentity(emp1);
  +        retrievedEmp = (Employee) broker.getObjectByIdentity(ident);
  +        assertNotNull(retrievedEmp);
  +        assertSame(Shareholder.class, retrievedEmp.getClass());
  +        assertEquals(emp1, retrievedEmp);
  +    }
  +
       public void testJavaInheritance()
       {
           ojbSkipKnownIssueProblem("Declared inheritance (without java inheritance)" +
  @@ -182,9 +241,9 @@
           }
   
           long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
           String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  -        Company company = prepareTestDataWithCompany(id_2, name);
  +        Company company = prepareTestDataWithCompany(name);
  +        Long id_2 = company.getId();
   
           broker.clearCache();
           Criteria crit = new Criteria();
  @@ -221,12 +280,6 @@
               }
           }
           assertEquals(6, countEmployee);
  -        /*
  -        bug:
  -        expect that the real classes will be populated
  -        currently this does not happen, only objects of
  -        type Employee will be returned.
  -        */
           assertEquals(5, countExecutive);
           assertEquals(3, countManager);
       }
  @@ -428,7 +481,6 @@
           assertNull(new_m);
       }
   
  -
       public void testStoreUpdateQuerySerialized_2()
       {
           long timestamp = System.currentTimeMillis();
  @@ -670,8 +722,10 @@
           assertEquals("Expect the same number of objects as before update", 3, result.size());
       }
   
  -    private void prepareForQueryTests(Long id_2, String name)
  +    private List prepareForQueryTests(Long id_2, String name)
       {
  +        List result = new ArrayList();
  +        
           Manager m_1 = new Manager(id_2, name + "_manager_1");
           Manager m_2 = new Manager(id_2, name + "_manager_2");
           Manager m_3 = new Manager(id_2, name + "_manager_3");
  @@ -686,6 +740,13 @@
           Address a_2 = new Address("cockroaches valley");
           em.setAddress(a_2);
   
  +        result.add(m_1);
  +        result.add(m_2);
  +        result.add(m_3);
  +        result.add(ex_1);
  +        result.add(ex_2);
  +        result.add(em);
  +        
           broker.beginTransaction();
           broker.store(m_1);
           broker.store(m_2);
  @@ -694,9 +755,13 @@
           broker.store(ex_2);
           broker.store(em);
           broker.commitTransaction();
  +        
  +        return result;
       }
   
  -	private Company prepareTestDataWithCompany(Long id_2, String name) {
  +	private Company prepareTestDataWithCompany(String name)
  +    {
  +        Long id_2 = null;
   		Manager m_1 = new Manager(id_2, name + "_manager_1");
           Manager m_2 = new Manager(id_2, name + "_manager_2");
           Manager m_3 = new Manager(id_2, name + "_manager_3");
  @@ -714,6 +779,9 @@
           employees.add(em);
   
           ArrayList executives = new ArrayList();
  +        executives.add(m_1);
  +        executives.add(m_2);
  +        executives.add(m_3);
           executives.add(ex_1);
           executives.add(ex_2);
   
  @@ -864,9 +932,9 @@
     public void testQuery_ReferenceOuterJoin()
       {
           long timestamp = System.currentTimeMillis();
  -        Long id_2 = new Long(timestamp);
           String name = "testQuery_ReferenceOuterJoin_" + timestamp;
  -        Company comp = prepareTestDataWithCompany(id_2, name);
  +        Company company = prepareTestDataWithCompany(name);
  +        Long id_2 = company.getId();
   
           // Store a dummy company
           Company dummyComp = new Company(null, name + "_dummy", Collections.EMPTY_LIST,
Collections.EMPTY_LIST);
  @@ -896,8 +964,8 @@
           query.addOrderByAscending("id");
           query.setPathOuterJoin("executives");
   
  -        SqlGenerator sqlg = broker.serviceSqlGenerator();
  -        String sql = sqlg.getPreparedSelectStatement(query, broker.getClassDescriptor(Company.class));
  +//        SqlGenerator sqlg = broker.serviceSqlGenerator();
  +//        String sql = sqlg.getPreparedSelectStatement(query, broker.getClassDescriptor(Company.class));
   
           result = broker.getCollectionByQuery(query);
           assertEquals(2, result.size());								// should retrieve both companies
  @@ -1111,8 +1179,13 @@
        * In class {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor} the
        * support is comment out (but only works for simple objects without references).
        */
  -    public void YYYtestWithoutJavaInheritance_1()
  +    public void testWithoutJavaInheritance_1()
       {
  +        if (ojbSkipKnownIssueProblem("Declarative Inheritance not supported"))
  +        {
  +            return;
  +        }
  +
           String name = "testWithoutJavaInheritance_1" + System.currentTimeMillis();
           Dog dog = new Dog(name, 35, 4);
           broker.beginTransaction();
  @@ -1154,8 +1227,13 @@
        * In class {@link org.apache.ojb.broker.metadata.SuperReferenceDescriptor} the
        * support is comment out (but only works for simple objects without references).
        */
  -    public void YYYtestWithoutJavaInheritance_2()
  +    public void testWithoutJavaInheritance_2()
       {
  +        if (ojbSkipKnownIssueProblem("Declarative Inheritance not supported"))
  +        {
  +            return;
  +        }
  +
           String name = "testWithoutJavaInheritance_2" + System.currentTimeMillis();
           Dog dog = new Dog(name, 35, 4);
           Animal parent = new Animal(name + "_parent", 55);
  @@ -1198,8 +1276,6 @@
           broker.commitTransaction();
       }
   
  -
  -
       //************************************************************
       // inner classes used for test
       //************************************************************
  
  
  

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