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