1
2
3
4 package org.melati.poem.dbms.test;
5
6 import java.sql.SQLException;
7
8 import org.melati.poem.BigDecimalPoemType;
9 import org.melati.poem.BooleanPoemType;
10 import org.melati.poem.DatePoemType;
11 import org.melati.poem.DoublePoemType;
12 import org.melati.poem.IntegerPoemType;
13 import org.melati.poem.LongPoemType;
14 import org.melati.poem.StringPoemType;
15 import org.melati.poem.TimestampPoemType;
16 import org.melati.poem.dbms.DbmsFactory;
17 import org.melati.poem.dbms.MSAccess;
18
19
20
21
22
23
24 public class MSAccessTest extends DbmsSpec {
25
26
27
28
29
30 public MSAccessTest(String name) {
31 super(name);
32 }
33
34
35
36
37
38 protected void setUp() throws Exception {
39 super.setUp();
40 }
41
42
43
44
45
46 protected void tearDown() throws Exception {
47 super.tearDown();
48 }
49
50 protected void setObjectUnderTest() {
51 it = DbmsFactory.getDbms("org.melati.poem.dbms.MSAccess");
52 }
53
54
55
56
57
58 public void testCanDropColumns() throws Exception {
59 assertFalse(it.canDropColumns());
60 }
61
62
63
64
65
66 public void testGetStringSqlDefinition() throws Exception {
67 assertEquals("VARCHAR(250)", it.getStringSqlDefinition(-1));
68 assertEquals("VARCHAR(0)", it.getStringSqlDefinition(0));
69 }
70
71
72
73
74
75
76 public void testGetSqlDefinition() throws Exception {
77 assertEquals("BIT", it.getSqlDefinition("BOOLEAN"));
78 assertEquals("DOUBLE", it.getSqlDefinition("DOUBLE PRECISION"));
79 assertEquals("INTEGER", it.getSqlDefinition("INT8"));
80 assertEquals("NUMERIC", it.getSqlDefinition("Big Decimal"));
81 assertEquals("INTEGER", it.getSqlDefinition("INTEGER"));
82 }
83
84
85
86
87
88
89 public void testGetLongSqlDefinition() {
90 assertEquals("INTEGER", it.getLongSqlDefinition());
91 }
92
93
94
95
96
97 public void testGetBinarySqlDefinition() throws Exception {
98 assertEquals("BINARY(0)", it.getBinarySqlDefinition(0));
99 assertEquals("BINARY", it.getBinarySqlDefinition(-1));
100 }
101
102
103
104 public void testMelatiName() {
105 assertEquals("name", it.melatiName("name"));
106 assertNull(it.melatiName(null));
107 assertNull(it.melatiName("~MSAccess special"));
108 }
109
110
111
112
113
114
115 public void testGetFixedPtSqlDefinition() throws Exception {
116 assertEquals("NUMERIC", it.getFixedPtSqlDefinition(22, 2));
117 try {
118 it.getFixedPtSqlDefinition(-1, 2);
119 fail("Should have blown up");
120 } catch (SQLException e) {
121 e = null;
122 }
123 try {
124 it.getFixedPtSqlDefinition(22, -1);
125 fail("Should have blown up");
126 } catch (SQLException e) {
127 e = null;
128 }
129 }
130
131
132
133
134
135 public void testCanRepresent() {
136 assertNull(it.canRepresent(StringPoemType.nullableInstance, IntegerPoemType.nullableInstance));
137 assertNull(it.canRepresent(IntegerPoemType.nullableInstance,StringPoemType.nullableInstance));
138
139 assertNull(it.canRepresent(new BigDecimalPoemType(false),new BigDecimalPoemType(true)));
140 assertTrue(it.canRepresent(new BigDecimalPoemType(true),new BigDecimalPoemType(false))
141 instanceof BigDecimalPoemType);
142
143 assertNull(it.canRepresent(new StringPoemType(true, 255), new StringPoemType(true, -1)));
144
145 assertTrue(it.canRepresent(
146 new StringPoemType(true, MSAccess.msAccessTextHack), new StringPoemType(true, -1))
147 instanceof StringPoemType);
148 assertTrue(it.canRepresent(
149 new StringPoemType(true, MSAccess.msAccessMemoSize), new StringPoemType(true, -1))
150 instanceof StringPoemType);
151 assertTrue(it.canRepresent(
152 new StringPoemType(true, -1), new StringPoemType(true, -1))
153 instanceof StringPoemType);
154
155 assertTrue(it.canRepresent(
156 new TimestampPoemType(true), new DatePoemType(true))
157 instanceof DatePoemType);
158
159 assertTrue(it.canRepresent(
160 new BooleanPoemType(true), new BooleanPoemType(false))
161 instanceof BooleanPoemType);
162
163 assertNull(it.canRepresent(new DoublePoemType(false), new BigDecimalPoemType(true)));
164
165 assertTrue(it.canRepresent(
166 new DoublePoemType(true), new BigDecimalPoemType(false))
167 instanceof BigDecimalPoemType);
168
169 assertNull(it.canRepresent(new IntegerPoemType(false), new LongPoemType(true)));
170
171 assertTrue(it.canRepresent(
172 new IntegerPoemType(true), new LongPoemType(false))
173 instanceof LongPoemType);
174
175
176
177 }
178
179
180
181
182
183
184 public void testCaseInsensitiveRegExpSQL() {
185 String expected = "a LIKE '%b%'";
186 String actual = it.caseInsensitiveRegExpSQL("a", "b");
187 assertEquals(expected, actual);
188 }
189
190 public void testCaseInsensitiveRegExpSQLQuoted() {
191 String expected = "a LIKE '%b%'";
192 String actual = it.caseInsensitiveRegExpSQL("a", "\"b\"");
193 assertEquals(expected, actual);
194 }
195
196 public void testCaseInsensitiveRegExpSQLBlank() {
197 String expected = " LIKE '%%'";
198 String actual = it.caseInsensitiveRegExpSQL("", "");
199 assertEquals(expected, actual);
200 }
201
202
203
204
205
206 public void testSqlBooleanValueOfRaw() {
207 assertEquals("0", it.sqlBooleanValueOfRaw(Boolean.FALSE));
208 assertEquals("1", it.sqlBooleanValueOfRaw(Boolean.TRUE));
209 }
210
211
212
213
214
215 public void testSelectLimit() {
216 assertEquals("SELECT TOP 1 * FROM \"USER\"", it.selectLimit("* FROM \"USER\"", 1));
217 }
218
219
220
221
222
223
224
225
226 public void testGetForeignKeyDefinition() {
227 assertEquals(" ADD FOREIGN KEY (\"MELATI_USER\") REFERENCES \"MELATI_USER\"(\"id\") ON DELETE RESTRICT",
228 it.getForeignKeyDefinition("test", "user", "user", "id", "prevent"));
229 assertEquals(" ADD FOREIGN KEY (\"MELATI_USER\") REFERENCES \"MELATI_USER\"(\"id\") ON DELETE SET NULL",
230 it.getForeignKeyDefinition("test", "user", "user", "id", "clear"));
231 assertEquals(" ADD FOREIGN KEY (\"MELATI_USER\") REFERENCES \"MELATI_USER\"(\"id\") ON DELETE CASCADE",
232 it.getForeignKeyDefinition("test", "user", "user", "id", "delete"));
233 }
234
235
236
237 }