01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.db;
07:
08: import java.sql.Connection;
09: import java.sql.ResultSet;
10: import java.sql.SQLException;
11: import java.sql.Statement;
12:
13: import org.h2.test.TestBase;
14:
15: /**
16: * Test using an encrypted database.
17: */
18: public class TestEncryptedDb extends TestBase {
19:
20: public void test() throws Exception {
21: if (config.memory || config.cipher != null) {
22: return;
23: }
24: deleteDb("exclusive");
25: Connection conn = getConnection("exclusive;CIPHER=AES", "sa",
26: "123 123");
27: Statement stat = conn.createStatement();
28: stat.execute("CREATE TABLE TEST(ID INT)");
29: stat.execute("CHECKPOINT");
30: stat.execute("SET WRITE_DELAY 0");
31: stat.execute("INSERT INTO TEST VALUES(1)");
32: stat.execute("SHUTDOWN IMMEDIATELY");
33: try {
34: conn.close();
35: } catch (SQLException e) {
36: checkNotGeneralException(e);
37: }
38:
39: try {
40: conn = getConnection("exclusive;CIPHER=AES", "sa",
41: "1234 1234");
42: error();
43: } catch (SQLException e) {
44: checkNotGeneralException(e);
45: }
46:
47: conn = getConnection("exclusive;CIPHER=AES", "sa", "123 123");
48: stat = conn.createStatement();
49: ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
50: check(rs.next());
51: check(1, rs.getInt(1));
52: checkFalse(rs.next());
53:
54: conn.close();
55: }
56:
57: }
|