db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpoes...@apache.org
Subject cvs commit: db-torque/src/generator/src/test/org/apache/torque/engine/database/model tabletest-schema.xml TableTest.java
Date Sat, 04 Oct 2003 10:11:33 GMT
mpoeschl    2003/10/04 03:11:33

  Modified:    src/generator/src/test/org/apache/torque/engine/database/model
                        tabletest-schema.xml TableTest.java
  Log:
  add tests for pk and fk handling
  
  Revision  Changes    Path
  1.2       +31 -0     db-torque/src/generator/src/test/org/apache/torque/engine/database/model/tabletest-schema.xml
  
  Index: tabletest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/tabletest-schema.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tabletest-schema.xml	1 Aug 2003 07:52:09 -0000	1.1
  +++ tabletest-schema.xml	4 Oct 2003 10:11:33 -0000	1.2
  @@ -12,6 +12,37 @@
       <column name="table_a_id" required="true" primaryKey="true" type="INTEGER" />
       <column name="col_a" type="CHAR" size="5" />
     </table>
  +
  +  <table name="singlepk">
  +    <column name="singlepk_id" required="true" primaryKey="true" type="INTEGER" />
  +    <column name="col_a" type="CHAR" size="5" />
  +  </table>
  +
  +  <table name="multipk">
  +    <column name="multipk_a" required="true" primaryKey="true" type="INTEGER" />
  +    <column name="multipk_b" required="true" primaryKey="true" type="INTEGER" />
  +    <column name="col_a" type="CHAR" size="5" />
  +  </table>
  +
  +  <table name="singlefk">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER" />
  +    <column name="singlepk_id" required="true" type="INTEGER" />
  +    <column name="col_a" type="CHAR" size="5" />
  +    <foreign-key foreignTable="singlepk">
  +      <reference local="singlepk_id" foreign="singlepk_id"/>
  +    </foreign-key>
  +  </table>
  +  
  +  <table name="multifk">
  +    <column name="id" required="true" primaryKey="true" type="INTEGER" />
  +    <column name="multipk_a" required="true" type="INTEGER" />
  +    <column name="multipk_b" required="true" type="INTEGER" />
  +    <column name="col_a" type="CHAR" size="5" />
  +    <foreign-key foreignTable="multipk">
  +      <reference local="multipk_a" foreign="multipk_a"/>
  +      <reference local="multipk_b" foreign="multipk_b"/>
  +    </foreign-key>
  +  </table>
     
   </database>
   
  
  
  
  1.3       +51 -6     db-torque/src/generator/src/test/org/apache/torque/engine/database/model/TableTest.java
  
  Index: TableTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/TableTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TableTest.java	27 Sep 2003 11:13:48 -0000	1.2
  +++ TableTest.java	4 Oct 2003 10:11:33 -0000	1.3
  @@ -54,6 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.List;
  +
   import junit.framework.TestCase;
   
   import org.apache.torque.engine.database.transform.XmlToAppData;
  @@ -77,6 +79,9 @@
       protected void setUp() throws Exception
       {
           super.setUp();
  +        xmlToAppData = new XmlToAppData("mysql", "defaultpackage");
  +        appData = xmlToAppData.parseFile(
  +            "src/test/org/apache/torque/engine/database/model/tabletest-schema.xml");
       }
   
       protected void tearDown() throws Exception
  @@ -88,17 +93,57 @@
       /**
        * test if the tables get the package name from the properties file
        */
  -    public void testIdMethodHandling()
  -            throws Exception
  +    public void testIdMethodHandling() throws Exception
       {
  -        xmlToAppData = new XmlToAppData("mysql", "defaultpackage");
  -        appData = xmlToAppData.parseFile(
  -            "src/test/org/apache/torque/engine/database/model/tabletest-schema.xml");
           Database db = appData.getDatabase("iddb");
           assertEquals(IDMethod.ID_BROKER, db.getDefaultIdMethod());
           Table table = db.getTable("table_idbroker");
           assertEquals(IDMethod.ID_BROKER, table.getIdMethod());
   		Table table2 = db.getTable("table_native");
   		assertEquals(IDMethod.NATIVE, table2.getIdMethod());
  +    }
  +    
  +    public void testSinglePk() throws Exception
  +    {
  +        Database db = appData.getDatabase("iddb");
  +        Table table = db.getTable("singlepk");
  +        List pks = table.getPrimaryKey();
  +        assertTrue(pks.size() == 1);
  +        Column col = (Column) pks.get(0);
  +        assertEquals(col.getName(), "singlepk_id");        
  +    }
  +    
  +    public void testMultiPk() throws Exception
  +    {
  +        Database db = appData.getDatabase("iddb");
  +        Table table = db.getTable("multipk");
  +        List pks = table.getPrimaryKey();
  +        assertTrue(pks.size() == 2);
  +        Column cola = (Column) pks.get(0);
  +        assertEquals(cola.getName(), "multipk_a");        
  +        Column colb = (Column) pks.get(1);
  +        assertEquals(colb.getName(), "multipk_b");        
  +    }
  + 
  +    public void testSingleFk() throws Exception
  +    {
  +        Database db = appData.getDatabase("iddb");
  +        Table table = db.getTable("singlefk");
  +        ForeignKey[] fks = table.getForeignKeys();
  +        assertTrue(fks.length == 1);
  +        ForeignKey fk = fks[0];
  +        assertEquals(fk.getForeignTableName(), "singlepk");
  +        assertTrue(fk.getForeignColumns().size() == 1);
  +    }
  +
  +    public void testMultiFk() throws Exception
  +    {
  +        Database db = appData.getDatabase("iddb");
  +        Table table = db.getTable("multifk");
  +        ForeignKey[] fks = table.getForeignKeys();
  +        assertTrue(fks.length == 1);
  +        ForeignKey fk = fks[0];
  +        assertEquals(fk.getForeignTableName(), "multipk");
  +        assertTrue(fk.getForeignColumns().size() == 2);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message