1
2
3
4 package org.melati.poem.dbms.test;
5
6 import org.melati.poem.dbms.DbmsFactory;
7
8
9
10
11
12
13 public class HsqldbTest extends DbmsSpec {
14
15 public HsqldbTest(String name) {
16 super(name);
17 }
18
19 protected void setUp() throws Exception {
20 super.setUp();
21 }
22
23 protected void tearDown() throws Exception {
24 super.tearDown();
25 }
26
27 protected void setObjectUnderTest() {
28 it = DbmsFactory.getDbms("org.melati.poem.dbms.Hsqldb");
29 }
30
31
32
33
34 public void testCreateTableSql() {
35 if (getDb().getDbms() == it)
36 assertEquals("CREATE CACHED TABLE " +
37 "\"USER\" (\"ID\" INT NOT NULL, " +
38 "\"NAME\" VARCHAR(60) NOT NULL, " +
39 "\"LOGIN\" VARCHAR(255) NOT NULL, " +
40 "\"PASSWORD\" VARCHAR(20) NOT NULL)",
41 it.createTableSql(getDb().getUserTable()));
42 }
43
44
45
46
47
48 public void testGetStringSqlDefinition() throws Exception {
49
50 assertEquals("LONGVARCHAR", it.getStringSqlDefinition(-1));
51 }
52
53
54
55
56
57 public void testGetLongSqlDefinition() {
58 assertEquals("BIGINT", it.getLongSqlDefinition());
59 }
60
61
62
63
64
65 public void testGetBinarySqlDefinition() throws Exception {
66 assertEquals("LONGVARBINARY", it.getBinarySqlDefinition(0));
67 }
68
69
70
71
72 public void testMelatiName() {
73 assertEquals("name", it.melatiName("name"));
74 assertEquals(null, it.melatiName(null));
75 assertEquals("~special", it.melatiName("~Special"));
76 assertEquals("unique", it.melatiName("MELATI_UNIQUE"));
77 assertEquals("constraint", it.melatiName("MELATI_CONSTRAINT"));
78 assertEquals("users", it.melatiName("users"));
79 }
80
81
82
83
84
85 public void testUnreservedName() {
86 assertEquals("NAME", it.unreservedName("name"));
87 }
88
89
90
91
92 public void testGetJdbcMetadataName() {
93 assertEquals("NAME",it.getJdbcMetadataName("name"));
94 }
95
96
97
98
99
100
101 public void testGetForeignKeyDefinition() {
102
103 assertEquals(" ADD FOREIGN KEY (\"USER\") REFERENCES \"USER\"(\"ID\")",
104 it.getForeignKeyDefinition("test", "user", "user", "id", "prevent"));
105 assertEquals(" ADD FOREIGN KEY (\"USER\") REFERENCES \"USER\"(\"ID\") ON DELETE SET NULL",
106 it.getForeignKeyDefinition("test", "user", "user", "id", "clear"));
107 assertEquals(" ADD FOREIGN KEY (\"USER\") REFERENCES \"USER\"(\"ID\") ON DELETE CASCADE",
108 it.getForeignKeyDefinition("test", "user", "user", "id", "delete"));
109
110
111 }
112
113
114
115
116
117 public void testGetPrimaryKeyDefinition() {
118 assertEquals(" ADD PRIMARY KEY (\"NAME\")", it.getPrimaryKeyDefinition("name"));
119 }
120
121
122
123
124
125 public void testCaseInsensitiveRegExpSQL() {
126 String expected = "a LIKE '%b%'";
127 String actual = it.caseInsensitiveRegExpSQL("a", "b");
128 assertEquals(expected, actual);
129 }
130
131 public void testCaseInsensitiveRegExpSQLQuoted() {
132 String expected = "a LIKE \'%b%\'";
133 String actual = it.caseInsensitiveRegExpSQL("a", "\"b\"");
134 assertEquals(expected, actual);
135 }
136
137 public void testCaseInsensitiveRegExpSQLBlank() {
138 String expected = " LIKE '%%'";
139 String actual = it.caseInsensitiveRegExpSQL("", "");
140 assertEquals(expected, actual);
141 }
142
143
144 }