1
2
3
4 package org.melati.poem.dbms.test;
5
6 import org.melati.poem.*;
7 import org.melati.poem.dbms.DbmsFactory;
8 import org.melati.poem.dbms.Mckoi;
9
10
11
12
13
14
15 public class MckoiTest extends DbmsSpec {
16
17
18
19
20
21
22 public MckoiTest(String name) {
23 super(name);
24 }
25
26
27
28
29
30
31 protected void setUp() throws Exception {
32 super.setUp();
33 }
34
35
36
37
38
39
40 protected void tearDown() throws Exception {
41 super.tearDown();
42 }
43
44 protected void setObjectUnderTest() {
45 it = DbmsFactory.getDbms("org.melati.poem.dbms.Mckoi");
46 }
47
48
49
50
51
52
53 public void testGetSqlDefinition() throws Exception {
54 assertEquals("BOOLEAN", it.getSqlDefinition("BOOLEAN"));
55 assertEquals("DOUBLE PRECISION", it.getSqlDefinition("DOUBLE PRECISION"));
56 assertEquals("INT8", it.getSqlDefinition("INT8"));
57 assertEquals("INTEGER", it.getSqlDefinition("INT"));
58 assertEquals("Big Decimal", it.getSqlDefinition("Big Decimal"));
59 assertEquals("STRING", it.getSqlDefinition("STRING"));
60 }
61
62
63
64
65
66 public void testGetStringSqlDefinition() throws Exception {
67 assertEquals("VARCHAR(0)", it.getStringSqlDefinition(0));
68 assertEquals("TEXT", it.getStringSqlDefinition(-1));
69 }
70
71
72
73
74
75 public void testGetBinarySqlDefinition() throws Exception {
76 assertEquals("LONGVARBINARY", it.getBinarySqlDefinition(0));
77 }
78
79
80
81
82
83 public void testCanRepresent() {
84 assertNull(it.canRepresent(StringPoemType.nullableInstance, IntegerPoemType.nullableInstance));
85 assertNull(it.canRepresent(IntegerPoemType.nullableInstance,StringPoemType.nullableInstance));
86
87 assertNull(it.canRepresent(new BigDecimalPoemType(false),new BigDecimalPoemType(true)));
88 assertTrue(it.canRepresent(new BigDecimalPoemType(true),new BigDecimalPoemType(false))
89 instanceof BigDecimalPoemType);
90
91 assertNull(it.canRepresent(new StringPoemType(true, 255), new StringPoemType(true, -1)));
92
93 assertTrue(it.canRepresent(
94 new StringPoemType(true, Mckoi.mckoiTextHack), new StringPoemType(true, -1))
95 instanceof StringPoemType);
96 assertTrue(it.canRepresent(
97 new StringPoemType(true, -1), new StringPoemType(true, -1))
98 instanceof StringPoemType);
99
100 assertNull(it.canRepresent(new TimestampPoemType(true), new DatePoemType(true)));
101
102 assertTrue(it.canRepresent(
103 new BooleanPoemType(true), new BooleanPoemType(false))
104 instanceof BooleanPoemType);
105
106 assertNull(it.canRepresent(new DoublePoemType(false), new BigDecimalPoemType(true)));
107
108 assertNull(it.canRepresent(new DoublePoemType(true), new BigDecimalPoemType(false)));
109
110 assertNull(it.canRepresent(new IntegerPoemType(false), new LongPoemType(true)));
111
112 assertNull(it.canRepresent(new IntegerPoemType(true), new LongPoemType(false)));
113
114
115
116 assertNull(it.canRepresent(new BinaryPoemType(false,10), new BinaryPoemType(true,10)));
117 assertNull(it.canRepresent(new BinaryPoemType(true,10), new BinaryPoemType(true,11)));
118 assertTrue(it.canRepresent(
119 new BinaryPoemType(true,Mckoi.mckoiBinaryHack),
120 new BinaryPoemType(true,-1)) instanceof BinaryPoemType);
121 assertTrue(it.canRepresent(
122 new BinaryPoemType(true,Mckoi.mckoiBinaryHack),
123 new BinaryPoemType(true,10)) instanceof BinaryPoemType);
124
125 }
126
127
128
129
130
131
132
133
134 public void testGetForeignKeyDefinition() {
135 assertEquals(
136 " ADD FOREIGN KEY (user) REFERENCES user(id) ON DELETE CASCADE", it
137 .getForeignKeyDefinition("test", "user", "user", "id",
138 "delete"));
139 }
140
141
142
143
144 public void testGetPrimaryKeyDefinition() {
145 assertEquals(" ADD PRIMARY KEY (name)", it.getPrimaryKeyDefinition("name"));
146 }
147
148
149
150
151
152
153 public void testGivesCapabilitySQL() {
154 String actual = it.givesCapabilitySQL(new Integer(42), "hello");
155 String expected = "SELECT " + it.getQuotedName("groupmembership") + ".* "
156 + "FROM " + it.getQuotedName("groupmembership") + " LEFT JOIN "
157 + it.getQuotedName("groupcapability") + " ON "
158 + it.getQuotedName("groupmembership") + "."
159 + it.getQuotedName("group") + " = "
160 + it.getQuotedName("groupcapability") + "."
161 + it.getQuotedName("group") + " WHERE " + it.getQuotedName("user")
162 + " = 42" + " " + "AND " + it.getQuotedName("groupcapability")
163 + "." + it.getQuotedName("group") + " IS NOT NULL " + "AND "
164 + it.getQuotedName("capability") + " = hello";
165
166 assertEquals(expected, actual);
167
168 }
169
170
171
172 public void testCreateTableSql() {
173 if (getDb().getDbms() == it)
174 assertEquals("CREATE TABLE \"user\" (\"id\" INTEGER NOT NULL, \"name\" VARCHAR(60) NOT NULL, \"login\" VARCHAR(255) NOT NULL, \"password\" VARCHAR(20) NOT NULL)",
175 it.createTableSql(getDb().getUserTable()));
176 }
177
178 }