1 package org.melati.poem.dbms.test;
2
3 import java.sql.Connection;
4 import java.sql.SQLException;
5
6 import org.melati.poem.BigDecimalPoemType;
7 import org.melati.poem.DoublePoemType;
8 import org.melati.poem.IntegerPoemType;
9 import org.melati.poem.LongPoemType;
10 import org.melati.poem.PoemThread;
11 import org.melati.poem.StringPoemType;
12 import org.melati.poem.dbms.Dbms;
13 import org.melati.poem.test.PoemTestCase;
14
15
16
17
18
19
20
21
22 public abstract class DbmsSpec extends PoemTestCase {
23
24 protected Dbms it = null;
25
26
27
28
29
30 public DbmsSpec(String name) {
31 super(name);
32 }
33
34
35
36
37
38 protected void setUp() throws Exception {
39
40 setObjectUnderTest();
41 }
42
43
44
45
46
47 protected void tearDown() throws Exception {
48
49 it.unloadDriver();
50 }
51
52 protected abstract void setObjectUnderTest();
53
54
55
56
57
58
59
60 public void testGetConnection() throws Exception {
61 Connection c = PoemThread.transaction().getDatabase().getCommittedConnection();
62
63 if (c.getClass().getName().indexOf("postgresql") == -1) {
64
65 assertTrue(c.getTransactionIsolation() + " is not >= " + Connection.TRANSACTION_READ_COMMITTED +
66 " for database " + PoemThread.transaction().getDatabase() +
67 " using " + PoemThread.transaction().getDatabase().getDbms() +
68 " for connection " + c.getClass().getName(),
69 c.getTransactionIsolation() >= Connection.TRANSACTION_READ_COMMITTED);
70 }
71 }
72
73
74
75
76 public void testGetSchema() {
77 assertNull(it.getSchema());
78 }
79
80
81
82
83
84 public void testShutdown() {
85
86 }
87
88
89
90
91
92 public void testGetQuotedName() {
93
94 }
95
96
97
98
99
100 public void testGetQuotedValue() {
101
102 }
103
104
105
106
107
108 public void testGetJdbcMetadataName() {
109 assertEquals("name",it.getJdbcMetadataName("name"));
110 }
111
112
113
114
115
116 public void testPreparedStatementPlaceholder() {
117 assertEquals("?", it.preparedStatementPlaceholder(new IntegerPoemType(true)));
118 assertEquals("?", it.preparedStatementPlaceholder(new LongPoemType(true)));
119 assertEquals("?", it.preparedStatementPlaceholder(new DoublePoemType(true)));
120 assertEquals("?", it.preparedStatementPlaceholder(new StringPoemType(true, -1)));
121 }
122
123
124
125
126 public void testCreateTableSql() {
127 if (getDb().getDbms() == it)
128 assertEquals("CREATE TABLE \"MELATI_USER\" (\"id\" INT NOT NULL, \"name\" VARCHAR(60) NOT NULL, \"login\" VARCHAR(255) NOT NULL, \"password\" VARCHAR(20) NOT NULL)", it.createTableSql(getDb().getUserTable()));
129 }
130
131
132
133
134 public void testCreateTableOptionsSql() {
135 assertEquals("", it.createTableOptionsSql());
136 }
137
138
139
140
141
142
143 public void testGetSqlDefinition() throws Exception {
144 assertEquals("BOOLEAN", it.getSqlDefinition("BOOLEAN"));
145 assertEquals("DOUBLE PRECISION", it.getSqlDefinition("DOUBLE PRECISION"));
146 assertEquals("INT8", it.getSqlDefinition("INT8"));
147 assertEquals("INT", it.getSqlDefinition("INT"));
148 assertEquals("Big Decimal", it.getSqlDefinition("Big Decimal"));
149 assertEquals("STRING", it.getSqlDefinition("STRING"));
150 }
151
152
153
154
155 public void testGetStringSqlDefinition() throws Exception {
156 assertEquals("VARCHAR(0)", it.getStringSqlDefinition(0));
157 try {
158 it.getStringSqlDefinition(-1);
159 fail("Should have blown up");
160 } catch (SQLException e) {
161 e = null;
162 }
163 }
164
165
166
167
168
169 public void testGetLongSqlDefinition() {
170 assertEquals("INT8", it.getLongSqlDefinition());
171 }
172
173
174
175
176
177 public void testSqlBooleanValueOfRaw() {
178 assertEquals("false", it.sqlBooleanValueOfRaw(Boolean.FALSE));
179 assertEquals("true", it.sqlBooleanValueOfRaw(Boolean.TRUE));
180 }
181
182
183
184
185
186 public void testGetBinarySqlDefinition() throws Exception {
187 assertEquals("LONGVARBINARY(0)", it.getBinarySqlDefinition(0));
188 try {
189 it.getBinarySqlDefinition(-1);
190 fail("Should have blown up");
191 } catch (SQLException e) {
192 e = null;
193 }
194 }
195
196
197
198
199
200
201 public void testGetFixedPtSqlDefinition() throws Exception {
202 assertEquals("DECIMAL(2,22)", it.getFixedPtSqlDefinition(22, 2));
203 try {
204 it.getFixedPtSqlDefinition(-1, 2);
205 fail("Should have blown up");
206 } catch (SQLException e) {
207 e = null;
208 }
209 try {
210 it.getFixedPtSqlDefinition(22, -1);
211 fail("Should have blown up");
212 } catch (SQLException e) {
213 e = null;
214 }
215 }
216
217
218
219
220
221 public void testCanRepresent() {
222 assertNull(it.canRepresent(StringPoemType.nullableInstance, IntegerPoemType.nullableInstance));
223 assertNull(it.canRepresent(IntegerPoemType.nullableInstance,StringPoemType.nullableInstance));
224
225 assertNull(it.canRepresent(new BigDecimalPoemType(false),new BigDecimalPoemType(true)));
226 assertTrue(it.canRepresent(new BigDecimalPoemType(true),new BigDecimalPoemType(false))
227 instanceof BigDecimalPoemType);
228
229 assertNull(it.canRepresent(new StringPoemType(true, 250), new StringPoemType(true, -1)));
230
231 }
232
233
234
235
236
237 public void testDefaultPoemTypeOfColumnMetaData() {
238
239 }
240
241
242
243
244
245 public void testCanDropColumns() throws Exception {
246 assertTrue(it.canDropColumns());
247 }
248
249
250
251
252
253 public void testExceptionForUpdateTableStringBooleanSQLException() {
254
255 }
256
257
258
259
260
261 public void testExceptionForUpdateTablePreparedStatementBooleanSQLException() {
262
263 }
264
265
266
267
268
269 public void testUnreservedName() {
270 assertEquals("name", it.unreservedName("name"));
271 }
272
273
274
275
276 public void testMelatiName() {
277 assertEquals("name", it.melatiName("name"));
278 assertEquals(null, it.melatiName(null));
279 assertEquals("~Special", it.melatiName("~Special"));
280 }
281
282
283
284
285
286
287 public void testGetIndexLength() throws Exception {
288 assertEquals("", it.getIndexLength(null));
289 }
290
291
292
293
294
295
296 public void testCanBeIndexed() throws Exception {
297
298 }
299
300
301
302
303
304 public void testGivesCapabilitySQL() {
305 String actual = it.givesCapabilitySQL(new Integer(42),"hello");
306 String expected = "SELECT * FROM " + it.getQuotedName("groupMembership") +
307 " WHERE " + it.getQuotedName("user") + " = 42 AND " +
308 "EXISTS ( SELECT " + it.getQuotedName("groupCapability") +
309 "." + it.getQuotedName("group") +
310 " FROM " + it.getQuotedName("groupCapability") +
311 " WHERE " +
312 it.getQuotedName("groupCapability") + "." + it.getQuotedName("group") +
313 " = " +
314 it.getQuotedName("groupMembership") + "." +
315 it.getQuotedName("group") + " AND " +
316 it.getQuotedName("capability") + " = hello)";
317 assertEquals(expected,actual);
318
319 }
320
321
322
323
324
325 public void testCaseInsensitiveRegExpSQL() {
326 String expected = "a ILIKE '%b%'";
327 String actual = it.caseInsensitiveRegExpSQL("a", "b");
328 assertEquals(expected, actual);
329 }
330
331
332
333
334
335 public void testCaseInsensitiveRegExpSQLQuoted() {
336 String expected = "a ILIKE '%b%'";
337 String actual = it.caseInsensitiveRegExpSQL("a", "\"b\"");
338 assertEquals(expected, actual);
339 }
340
341
342
343
344
345 public void testCaseInsensitiveRegExpSQLBlank() {
346 String expected = " ILIKE '%%'";
347 String actual = it.caseInsensitiveRegExpSQL("", "");
348 assertEquals(expected, actual);
349 }
350
351
352
353
354
355 public void testToString() {
356
357 }
358
359
360
361
362
363
364
365 public void testGetForeignKeyDefinition() {
366 assertEquals(" ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE RESTRICT",
367 it.getForeignKeyDefinition("test", "user", "user", "id", "prevent"));
368 assertEquals(" ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE SET NULL",
369 it.getForeignKeyDefinition("test", "user", "user", "id", "clear"));
370 assertEquals(" ADD FOREIGN KEY (\"user\") REFERENCES \"user\"(\"id\") ON DELETE CASCADE",
371 it.getForeignKeyDefinition("test", "user", "user", "id", "delete"));
372 }
373
374
375
376
377
378 public void testGetPrimaryKeyDefinition() {
379 assertEquals(" ADD PRIMARY KEY (\"name\")", it.getPrimaryKeyDefinition("name"));
380 }
381
382
383
384
385
386 public void testAlterColumnNotNullableSQL() {
387
388 }
389
390
391
392
393
394 public void testSelectLimit() {
395 assertEquals("SELECT * FROM \"USER\" LIMIT 1", it.selectLimit("* FROM \"USER\"", 1));
396 }
397
398
399
400
401
402 public void testBooleanTrueExtression() {
403
404 }
405
406 }