1
2
3
4 package org.melati.poem.test.throwing;
5
6 import java.sql.Connection;
7 import java.sql.ResultSet;
8
9 import org.melati.poem.AccessToken;
10 import org.melati.poem.Capability;
11 import org.melati.poem.Database;
12 import org.melati.poem.PoemDatabase;
13 import org.melati.poem.PoemThread;
14 import org.melati.poem.ReconnectionPoemException;
15 import org.melati.poem.SQLPoemException;
16 import org.melati.poem.SQLSeriousPoemException;
17 import org.melati.poem.TableInfo;
18 import org.melati.poem.UnexpectedExceptionPoemException;
19 import org.melati.poem.UnificationPoemException;
20 import org.melati.poem.User;
21 import org.melati.poem.dbms.test.sql.Thrower;
22
23
24
25
26
27
28 public class DatabaseTest extends org.melati.poem.test.DatabaseTest {
29
30
31
32
33
34 public DatabaseTest(String name) {
35 super(name);
36 }
37
38 protected void setUp() throws Exception {
39 super.setUp();
40 }
41
42 protected void tearDown() throws Exception {
43 super.tearDown();
44 db = null;
45 }
46
47 private static Database db;
48
49
50
51 private static Database getDb() {
52 db = new PoemDatabase();
53 db.connect("m2", "org.melati.poem.dbms.test.HsqldbThrower",
54 "jdbc:hsqldb:mem:m2",
55 "sa",
56 "",
57 8);
58 assertTrue(db.getClass().getName() == "org.melati.poem.PoemDatabase");
59 assertEquals(8, db.getFreeTransactionsCount());
60 return db;
61 }
62
63
64 public void testAddConstraints() {
65
66 }
67
68 public void testAddTableAndCommit() {
69
70 }
71
72
73
74
75
76 public void testAddTableAndCommitThrowing() {
77 db = getDb();
78 db.beginSession(AccessToken.root);
79 TableInfo info = (TableInfo)db.getTableInfoTable().newPersistent();
80 info.setName("addedtable");
81 info.setDisplayname("Junit created table");
82 info.setDisplayorder(13);
83 info.setSeqcached(new Boolean(false));
84 info.setCategory_unsafe(new Integer(1));
85 info.setCachelimit(0);
86 info.makePersistent();
87 PoemThread.commit();
88 Thrower.startThrowing(Connection.class, "getMetaData");
89 try {
90 db.addTableAndCommit(info, "id");
91 fail("Should have blown up");
92 } catch (SQLSeriousPoemException e) {
93 assertEquals("Connection bombed", e.innermostException().getMessage());
94 }
95 Thrower.stopThrowing(Connection.class, "getMetaData");
96 db.sqlUpdate("DROP TABLE " + db.getDbms().getQuotedName("addedtable"));
97 db.sqlUpdate("DROP TABLE " + db.getDbms().getQuotedName("columninfo"));
98 db.sqlUpdate("DROP TABLE " + db.getDbms().getQuotedName("tableinfo"));
99 PoemThread.commit();
100 db.endSession();
101 }
102
103 public void testAdministerCapability() {
104
105 }
106
107 public void testAdministratorUser() {
108
109 }
110
111 public void testBeginExclusiveLock() {
112
113 }
114
115 public void testBeginSession() {
116
117 }
118
119 public void testColumns() {
120
121 }
122
123 public void testConnect() {
124 try {
125 getDb().connect("m2", "org.melati.poem.dbms.test.HsqldbThrower",
126 "jdbc:hsqldb:mem:m2",
127 "sa", "", 8);
128 fail("Should have blown up");
129 } catch (ReconnectionPoemException e) {
130 e = null;
131 }
132 Thrower.startThrowing(ResultSet.class, "close");
133 try {
134 getDb();
135 fail("Should have blown up");
136 } catch (UnificationPoemException e) {
137 assertEquals("ResultSet bombed", e.innermostException().getMessage());
138 }
139 Thrower.stopThrowing(ResultSet.class, "close");
140 }
141
142
143
144
145 public void testConnect2() {
146 db = new PoemDatabase();
147 Thrower.startThrowingAfter(Connection.class,"getMetaData", 1);
148 try {
149 db.connect("m2", "org.melati.poem.dbms.test.HsqldbThrower",
150 "jdbc:hsqldb:mem:m2",
151 "sa",
152 "",
153 4);
154 fail("Should have blown up");
155 } catch (UnificationPoemException e) {
156 assertEquals("Connection bombed", e.innermostException().getMessage());
157 }
158 assertEquals(0, db.getFreeTransactionsCount());
159 db = null;
160 Thrower.stopThrowing(Connection.class, "getMetaData");
161 }
162
163
164
165
166 public void testConnectThrowing3() {
167 db = getDb();
168 db.disconnect();
169 Thrower.startThrowing(Connection.class, "getMetaData");
170 try {
171 db.connect("m2","org.melati.poem.dbms.test.HsqldbThrower",
172 "jdbc:hsqldb:mem:m2",
173 "sa",
174 "",
175 4);
176 fail("Should have blown up");
177 } catch (UnificationPoemException e) {
178 assertEquals("Connection bombed", e.innermostException().getMessage());
179 }
180 assertEquals(0, db.getFreeTransactionsCount());
181 db = null;
182 Thrower.stopThrowing(Connection.class, "getMetaData");
183 }
184
185 public void testDatabase() {
186
187 }
188
189 public void testDisconnect() {
190 db = getDb();
191 Thrower.startThrowing(Connection.class, "close");
192 try {
193 db.disconnect();
194 fail("Should have blown up");
195 } catch (SQLPoemException e) {
196 assertEquals("Connection bombed", e.innermostException().getMessage());
197 }
198 Thrower.stopThrowing(Connection.class, "close");
199 db.disconnect();
200 assertEquals(0, db.getFreeTransactionsCount());
201 db = null;
202 }
203
204
205 public void testDump() {
206
207 }
208
209 public void testDumpCacheAnalysis() {
210
211 }
212
213 public void testEndExclusiveLock() {
214
215 }
216
217 public void testEndSession() {
218
219 }
220
221 public void testGetCanAdminister() {
222
223 }
224
225 public void testGetCapabilityTable() {
226
227 }
228
229 public void testGetColumnInfoTable() {
230
231 }
232
233 public void testGetCommittedConnection() {
234
235 }
236
237 public void testGetDbms() {
238
239 }
240
241 public void testGetDisplayTables() {
242
243 }
244
245 public void testGetFreeTransactionsCount() {
246
247 }
248
249 public void testGetGroupCapabilityTable() {
250
251 }
252
253 public void testGetGroupMembershipTable() {
254
255 }
256
257 public void testGetGroupTable() {
258
259 }
260
261 public void testGetQueryCount() {
262
263 }
264
265 public void testGetSettingTable() {
266
267 }
268
269 public void testGetTable() {
270
271 }
272
273 public void testGetTableCategoryTable() {
274
275 }
276
277 public void testGetTableInfoTable() {
278
279 }
280
281 public void testGetTransactionsCount() {
282
283 }
284
285 public void testGetUserTable() {
286
287 }
288
289 public void testGivesCapabilitySQL() {
290
291 }
292
293 public void testGuestAccessToken() {
294
295 }
296
297 public void testGuestUser() {
298
299 }
300
301 public void testHasCapability() {
302
303 }
304
305
306
307
308 public void testHasCapabilityThrowing() {
309 db = getDb();
310 db.beginSession(AccessToken.root);
311 Thrower.startThrowing(ResultSet.class, "next");
312 try {
313 assertFalse(db.hasCapability(
314 db.guestUser(), db.administerCapability()));
315 fail("Should have bombed");
316 } catch (SQLSeriousPoemException e) {
317 assertEquals("ResultSet bombed", e.innermostException().getMessage());
318 }
319 Thrower.stopThrowing(ResultSet.class, "next");
320
321 Thrower.startThrowing(Connection.class, "createStatement");
322 try {
323 assertFalse(db.hasCapability(db.guestUser(),
324 db.administerCapability()));
325 fail("Should have bombed");
326 } catch (UnexpectedExceptionPoemException e) {
327 assertEquals("Connection bombed", e.innermostException().getMessage());
328 }
329 Thrower.stopThrowing(Connection.class, "createStatement");
330 db.endSession();
331 }
332
333
334 public void testInCommittedTransaction() {
335
336 }
337
338 public void testIncrementQueryCount() {
339
340 }
341
342 public void testInSession() {
343
344 }
345
346 public void testIsFree() {
347
348 }
349
350 public void testLogCommits() {
351
352 }
353
354 public void testLogSQL() {
355
356 }
357
358 public void testPoemTransaction() {
359
360 }
361
362 public void testQuotedName() {
363
364 }
365
366 public void testReferencesToPersistent() {
367
368 }
369
370 public void testReferencesToTable() {
371
372 }
373
374 public void testSetCanAdminister() {
375 super.testSetCanAdminister();
376 }
377
378 public void testSetCanAdministerString() {
379
380 }
381
382 public void testSetLogCommits() {
383
384 }
385
386 public void testSetLogSQL() {
387
388 }
389
390 public void testSetTransactionsMax() {
391
392 }
393
394 public void testSqlQuery() {
395
396 }
397
398 public void testSqlUpdate() {
399
400 }
401
402 public void testTables() {
403
404 }
405
406 public void testToString() {
407
408 }
409
410 public void testTransaction() {
411
412 }
413
414 public void testTransactionsMax() {
415
416 }
417
418 public void testTrimCache() {
419
420 }
421
422 public void testUncacheContents() {
423
424 }
425
426 }