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 repository_junit.xml
Date Mon, 15 Nov 2004 17:30:46 GMT
arminw      2004/11/15 09:30:46

  Modified:    src/schema ojbtest-schema.xml
               src/test/org/apache/ojb/broker
                        InheritanceMultipleTableTest.java
               src/test/org/apache/ojb repository_junit.xml
  Log:
  add new test
  
  Revision  Changes    Path
  1.88      +8 -3      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- ojbtest-schema.xml	26 Oct 2004 15:27:40 -0000	1.87
  +++ ojbtest-schema.xml	15 Nov 2004 17:30:46 -0000	1.88
  @@ -1192,6 +1192,11 @@
       <!-- =================================================== -->
       <!-- Mapping Classes on Multiple Joined Tables test      -->
       <!-- =================================================== -->
  +    <table name="INHERITANCE_MULTI_COMPANY">
  +        <column name="OBJ_ID" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
  +        <column name="NAME" type="VARCHAR" size="150"/>
  +    </table>
  +
       <table name="INHERITANCE_MULTI_EMPLOYEE">
           <column name="OBJ_ID" required="true" primaryKey="true" type="INTEGER"/>
           <column name="OBJ_ID_2" required="true" primaryKey="true" type="DECIMAL" size="15,0"/>
  @@ -1474,7 +1479,7 @@
   	</table>
   	
   	<!-- ************ Object Factory tests * END -->
  -	
  -	
  +
  +
   
   </database>
  
  
  
  1.11      +126 -6    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- InheritanceMultipleTableTest.java	20 Sep 2004 14:30:58 -0000	1.10
  +++ InheritanceMultipleTableTest.java	15 Nov 2004 17:30:46 -0000	1.11
  @@ -17,9 +17,9 @@
   import org.apache.ojb.junit.PBTestCase;
   
   /**
  - * This test check inheritance using multiple tables. The test objects use
  - * a composite PK. One autoincrement PK field - Integer. One non-autoincrement PK field
  - * with manually set PK- Long.
  + * These tests check inheritance using multiple tables via 1:1 reference and "super" keyword
in
  + * reference descriptor. The test objects use a composite PK.
  + * One autoincrement PK field - Integer. One non-autoincrement PK field with manually set
PK- Long.
    *
    * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
    * @version $Id$
  @@ -38,6 +38,78 @@
           broker.serviceConnectionManager().setBatchMode(true);
       }
   
  +    public void testInheritancedObjectsInCollectionReferences()
  +    {
  +//        if(ojbSkipKnownIssueProblem("References of classes (1:1, 1:n) mapped to multiple
joined tables only" +
  +//                " return base class type instances"))
  +//        {
  +//            return;
  +//        }
  +
  +        long timestamp = System.currentTimeMillis();
  +        Long id_2 = new Long(timestamp);
  +        String name = "testInheritancedObjectsInCollectionReferences_" + timestamp;
  +        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");
  +        m_3.setDepartment("none");
  +        Executive ex_1 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Executive ex_2 = new Executive(id_2, name + "_executive", "department_1", null);
  +        Employee em = new Employee(id_2, name + "_employee");
  +
  +        ArrayList employees = new ArrayList();
  +        employees.add(m_1);
  +        employees.add(m_2);
  +        employees.add(m_3);
  +        employees.add(ex_1);
  +        employees.add(ex_2);
  +        employees.add(em);
  +
  +        Company company = new Company(id_2, name, employees);
  +        broker.beginTransaction();
  +        broker.store(company);
  +        broker.commitTransaction();
  +
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("id", id_2);
  +        Query query = QueryFactory.newQuery(Company.class, crit);
  +        Collection result = broker.getCollectionByQuery(query);
  +        assertEquals(1, result.size());
  +        Company newCompany = (Company) result.iterator().next();
  +        List newEmployees = newCompany.getEmployees();
  +        assertNotNull(newEmployees);
  +        assertEquals(employees.size(), newEmployees.size());
  +        int countEmployee = 0;
  +        int countExecutive = 0;
  +        int countManager = 0;
  +        for(int i = 0; i < newEmployees.size(); i++)
  +        {
  +            Object o =  newEmployees.get(i);
  +            if(o instanceof Employee)
  +            {
  +                ++countEmployee;
  +            }
  +            if(o instanceof Executive)
  +            {
  +                ++countExecutive;
  +            }
  +            if(o instanceof Manager)
  +            {
  +                ++countManager;
  +            }
  +        }
  +        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);
  +    }
  +
       public void testUpdate()
       {
           long timestamp = System.currentTimeMillis();
  @@ -217,8 +289,8 @@
           Manager target_1 = new Manager(new Long(1), "testObjectExistence");
           Manager target_2 = new Manager(new Long(System.currentTimeMillis()), "testObjectExistence");
   
  -        Identity oid_1 = new Identity(target_1, broker);
  -        Identity oid_2 = new Identity(target_2, broker);
  +        Identity oid_1 = broker.serviceIdentity().buildIdentity(target_1);
  +        Identity oid_2 = broker.serviceIdentity().buildIdentity(target_2);
   
           ClassDescriptor cld = broker.getClassDescriptor(Manager.class);
   
  @@ -795,5 +867,53 @@
           public String getStreet();
   
           public void setStreet(String street);
  +    }
  +
  +    public static class Company
  +    {
  +        private Long id;
  +        private String name;
  +        private List  employees;
  +
  +        public Company()
  +        {
  +        }
  +
  +        public Company(Long id, String name, List employees)
  +        {
  +            this.id = id;
  +            this.name = name;
  +            this.employees = employees;
  +        }
  +
  +        public Long getId()
  +        {
  +            return id;
  +        }
  +
  +        public void setId(Long id)
  +        {
  +            this.id = id;
  +        }
  +
  +        public String getName()
  +        {
  +            return name;
  +        }
  +
  +        public void setName(String name)
  +        {
  +            this.name = name;
  +        }
  +
  +        public List getEmployees()
  +        {
  +            return employees;
  +        }
  +
  +        public void setEmployees(List employees)
  +        {
  +            this.employees = employees;
  +        }
       }
   }
  
  
  
  1.125     +33 -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.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- repository_junit.xml	26 Oct 2004 15:27:41 -0000	1.124
  +++ repository_junit.xml	15 Nov 2004 17:30:46 -0000	1.125
  @@ -208,6 +208,7 @@
            collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection"
            auto-retrieve="true"
            auto-update="true"
  +          auto-delete="true"
         >
            <inverse-foreignkey field-ref="productGroupId"/>
         </collection-descriptor>
  @@ -1928,6 +1929,37 @@
   <!-- =================================================== -->
   <!-- Mapping Classes on Multiple Joined Tables test      -->
   <!-- =================================================== -->
  +<class-descriptor
  +	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Company"
  +	table="INHERITANCE_MULTI_COMPANY"
  + >
  +    <field-descriptor
  +        name="id"
  +        column="OBJ_ID"
  +        jdbc-type="BIGINT"
  +        primarykey="true"
  +        autoincrement="true"
  +    />
  +
  +    <field-descriptor
  +        name="name"
  +        column="NAME"
  +        jdbc-type="VARCHAR"
  +    />
  +
  +    <collection-descriptor
  +        name="employees"
  +        element-class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Employee"
  +        proxy="false"
  +        auto-retrieve="true"
  +        auto-update="object"
  +        auto-delete="object"
  +    >
  +        <!-- only for testing we use the second PK in base class Employee as FK  -->
  +        <inverse-foreignkey field-ref="id_2"/>
  +    </collection-descriptor>
  +</class-descriptor>
  +
   <class-descriptor
   	class="org.apache.ojb.broker.InheritanceMultipleTableTest$Employee"
   	table="INHERITANCE_MULTI_EMPLOYEE"
  
  
  

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