1
2
3
4
5
6
7 package test.org.asyrinx.joey.gen.model.rdb;
8
9 import java.lang.reflect.InvocationTargetException;
10 import java.util.Map;
11
12 import org.apache.commons.beanutils.BeanUtils;
13 import org.asyrinx.joey.gen.model.rdb.Column;
14 import org.asyrinx.joey.gen.model.rdb.Index;
15 import org.asyrinx.joey.gen.model.rdb.IndexEntry;
16 import org.asyrinx.joey.gen.model.rdb.Table;
17
18 import junit.framework.TestCase;
19
20 /***
21 * @author akima
22 */
23 public class IndexTest extends TestCase {
24
25 public static void main(String[] args) {
26 junit.swingui.TestRunner.run(IndexTest.class);
27 }
28
29
30
31
32 protected void setUp() throws Exception {
33 table = new Table();
34 table.setName("sample_table");
35 final Column col1 = new Column();
36 final Column col2 = new Column();
37 final Column col3 = new Column();
38 final Column col4 = new Column();
39 col1.setName("COL_1");
40 col2.setName("COL_2");
41 col3.setName("COL_3");
42 col4.setName("COL_4");
43 table.getColumns().add(col1);
44 table.getColumns().add(col2);
45 table.getColumns().add(col3);
46 table.getColumns().add(col4);
47
48 final Index index1 = new Index();
49 index1.setName("index_1");
50 table.getIndexes().add(index1);
51 final IndexEntry entry1 = new IndexEntry("COL_3");
52 final IndexEntry entry2 = new IndexEntry("COL_4");
53 index1.add(entry1);
54 index1.add(entry2);
55 }
56
57 private Table table = null;
58
59 public void testGetColumn() {
60 final Index index1 = table.getIndexes().getIndex("index_1");
61 final IndexEntry entry1 = index1.getEntry("COL_3");
62 final IndexEntry entry2 = index1.getEntry("COL_4");
63 final Column col3 = table.getColumns().getColumn("COL_3");
64 final Column col4 = table.getColumns().getColumn("COL_4");
65 assertEquals(entry1, index1.getEntry("COL_3"));
66 assertEquals(entry2, index1.getEntry("COL_4"));
67 assertEquals(col3, index1.getEntry("COL_3").getColumn());
68 assertEquals(col4, index1.getEntry("COL_4").getColumn());
69 }
70
71 public void testBeanUtils() {
72 try {
73 Map properties = BeanUtils.describe(new IndexEntry());
74 } catch (Exception e) {
75 e.printStackTrace();
76 fail();
77 return;
78 }
79 }
80
81 public void testIndex() {
82 table = new Table();
83 table.setName("sample_table");
84 final Column col1 = new Column(table, "COL_1", "INTEGER");
85 final Column col2 = new Column(table, "COL_2", "INTEGER");
86 final Column col3 = new Column(table, "COL_3", "INTEGER");
87 final Column col4 = new Column(table, "COL_4", "INTEGER");
88
89 final Index index1 = new Index(table, "index_1");
90 final IndexEntry entry1 = new IndexEntry(index1, "COL_3");
91 final IndexEntry entry2 = new IndexEntry(index1, "COL_4");
92
93 assertEquals(col3, entry1.getColumn());
94 assertEquals(col4, entry2.getColumn());
95 }
96
97 }