1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/08/16 4:14:06
6    */
7   package test.org.asyrinx.joey.gen.command.rdb;
8   
9   import junit.framework.TestCase;
10  
11  import org.asyrinx.joey.gen.command.rdb.CheckFkColumnType;
12  import org.asyrinx.joey.gen.model.command.ValidationError;
13  import org.asyrinx.joey.gen.model.rdb.Column;
14  import org.asyrinx.joey.gen.model.rdb.Database;
15  import org.asyrinx.joey.gen.model.rdb.ForeignKey;
16  import org.asyrinx.joey.gen.model.rdb.ForeignKeyEntry;
17  import org.asyrinx.joey.gen.model.rdb.Table;
18  
19  /***
20   * @author akima
21   */
22  public class CheckFkColumnTypeTest extends TestCase {
23  
24      public static void main(String[] args) {
25          junit.swingui.TestRunner.run(CheckFkColumnTypeTest.class);
26      }
27  
28      public void testNoraml() {
29          final Database database = new Database();
30          final Table table1 = new Table(database, "table1");
31          final Column column1_1 = new Column(table1, "col1-1", "BIGINT");
32          final Column column1_2 = new Column(table1, "col1-2", "INTEGER");
33          final Column column1_3 = new Column(table1, "col1-3", "VARCHAR", "20");
34          //
35          final Table table2 = new Table(database, "table2");
36          final Column column2_1 = new Column(table2, "col2-1", "INTEGER");
37          final Column column2_2 = new Column(table2, "col2-2", "DATE");
38          final Column column2_3 = new Column(table2, "col2-3", "VARCHAR", "30");
39          final ForeignKey foreignKey2_1 = new ForeignKey(table2, "table1");
40          final ForeignKeyEntry entry2_1_1 = new ForeignKeyEntry(foreignKey2_1, "col2-1", "col1-1");
41          final ForeignKey foreignKey2_2 = new ForeignKey(table2, "table1");
42          final ForeignKeyEntry entry2_2_1 = new ForeignKeyEntry(foreignKey2_1, "col2-3", "col1-3");
43          //
44          try {
45              new CheckFkColumnType().execute(database);
46              fail();
47          } catch (ValidationError e) {
48              assertEquals(entry2_1_1, e.getElement());
49          } catch (Throwable e) {
50              e.printStackTrace();
51              fail();
52          }
53          //
54          column2_1.setType("BIGINT");
55          try {
56              new CheckFkColumnType().execute(database);
57              fail();
58          } catch (ValidationError e) {
59              assertEquals(entry2_2_1, e.getElement());
60          } catch (Throwable e) {
61              e.printStackTrace();
62              fail();
63          }
64          column2_3.setSize("20");
65          try {
66              new CheckFkColumnType().execute(database);
67          } catch (Throwable e) {
68              e.printStackTrace();
69              fail();
70          }
71      }
72  
73  }