1 package org.melati.poem.test;
2
3 import java.sql.PreparedStatement;
4 import java.sql.ResultSet;
5
6 import org.melati.poem.DisplayLevelPoemType;
7 import org.melati.poem.NullTypeMismatchPoemException;
8 import org.melati.poem.PoemType;
9 import org.melati.poem.SQLPoemType;
10 import org.melati.poem.SQLSeriousPoemException;
11 import org.melati.poem.SQLType;
12 import org.melati.poem.TypeMismatchPoemException;
13
14
15
16
17
18
19 abstract public class SQLPoemTypeSpec<T> extends PoemTestCase {
20
21 protected PoemType<T> it = null;
22
23 public SQLPoemTypeSpec() {
24 super();
25 }
26
27 public SQLPoemTypeSpec(String name) {
28 super(name);
29 }
30
31 protected void setUp() throws Exception {
32 super.setUp();
33 setObjectUnderTest();
34 }
35
36 protected void tearDown() throws Exception {
37 super.tearDown();
38 }
39
40 abstract void setObjectUnderTest();
41
42
43
44
45
46 public void testSqlTypeCode() {
47
48 }
49
50
51
52
53
54 public void testSqlDefinition() {
55
56 }
57
58
59
60
61 public void testSqlDefaultValue() {
62
63 }
64
65
66
67
68
69 public void testSqlTypeDefinition() {
70
71 }
72
73
74
75
76 public void testQuotedRaw() {
77 assertEquals("'" +((SQLPoemType<T>)it).sqlDefaultValue(getDb().getDbms()) + "'",
78 ((SQLPoemType<T>)it).quotedRaw(
79 ((SQLPoemType<T>)it).rawOfString(
80 ((SQLPoemType<T>)it).sqlDefaultValue(getDb().getDbms()))));
81
82 }
83
84
85
86
87
88 public void testGetRaw() {
89 try {
90 ((SQLPoemType<T>)it).getRaw((ResultSet)null, 1);
91 fail("Should have blown up");
92 } catch (ClassCastException e) {
93 assertTrue(it instanceof NonSQLPoemType);
94 } catch (SQLSeriousPoemException e) {
95 assertTrue(it instanceof SqlExceptionPoemType);
96 e = null;
97 } catch (NullPointerException e2) {
98 e2 = null;
99 }
100
101 }
102
103
104
105
106
107 public void testSetRaw() {
108 try {
109 ((SQLPoemType<T>)it).setRaw((PreparedStatement)null, 1, null);
110 fail("Should have blown up");
111 } catch (ClassCastException e) {
112 assertTrue(it instanceof NonSQLPoemType);
113 } catch (NullPointerException e) {
114 e = null;
115 } catch (NullTypeMismatchPoemException e2) {
116 assertFalse(it.getNullable());
117 e2 = null;
118 }
119 try {
120 @SuppressWarnings("unchecked")
121 String sVal = ((SQLType<T>)it).sqlDefaultValue(getDb().getDbms());
122
123 Object value = it.rawOfString(sVal);
124 try {
125 ((SQLPoemType<T>)it).setRaw((PreparedStatement)null, 1, value);
126 fail("Should have blown up");
127 } catch (SQLSeriousPoemException e) {
128 assertTrue(it instanceof SqlExceptionPoemType);
129 e = null;
130 } catch (NullTypeMismatchPoemException e2) {
131 assertFalse(it.getNullable());
132 e2 = null;
133 } catch (NullPointerException e3) {
134 e3 = null;
135 }
136 } catch (ClassCastException e) {
137 assertTrue(it instanceof NonSQLPoemType);
138 }
139
140 }
141
142
143
144
145
146 public void testAssertValidRaw() {
147 if (it.getNullable())
148 it.assertValidRaw(null);
149 else
150 try {
151 it.assertValidRaw(null);
152 fail("Should have blown up");
153 } catch (NullTypeMismatchPoemException e) {
154 e = null;
155 }
156 try {
157 it.assertValidRaw(new Exception("Random class"));
158 fail("Should have blown up");
159 } catch (TypeMismatchPoemException e) {
160 e = null;
161 }
162
163 }
164
165
166
167
168 public void testPossibleRaws() {
169
170 }
171
172
173
174
175
176 public void testStringOfRaw() {
177
178 }
179
180
181
182
183
184 public void testRawOfString() {
185
186 }
187
188
189
190
191
192 public void testAssertValidCooked() {
193 if (it.getNullable())
194 it.assertValidCooked(null);
195 else
196 try {
197 it.assertValidCooked(null);
198 fail("Should have blown up");
199 } catch (NullTypeMismatchPoemException e) {
200 e = null;
201 }
202 try {
203 it.assertValidCooked(new Exception("Random class"));
204 fail("Should have blown up");
205 } catch (TypeMismatchPoemException e) {
206 e = null;
207 }
208 try {
209 it.assertValidCooked(
210 it.cookedOfRaw(
211 it.rawOfString(((SQLPoemType<T>)it).sqlDefaultValue(getDb().getDbms()))));
212 } catch (ClassCastException e){
213 assertTrue(it instanceof NonSQLPoemType);
214 }
215 }
216
217
218
219
220
221 public void testCookedOfRaw() {
222
223 }
224
225
226
227
228
229 public void testRawOfCooked() {
230 if (it.getNullable())
231 assertNull(it.rawOfCooked(null));
232 else
233 try {
234 it.rawOfCooked(null);
235 fail("Should have blown up");
236 } catch (NullTypeMismatchPoemException e) {
237 e = null;
238 }
239 }
240
241
242
243
244
245
246 public void testStringOfCooked() {
247
248 }
249
250
251
252
253 public void testGetNullable() {
254
255 }
256
257
258
259
260
261 public void testCanRepresent() {
262 DisplayLevelPoemType dl = new DisplayLevelPoemType();
263 assertNull(it.canRepresent(dl));
264 assertNull(dl.canRepresent(it));
265
266 }
267
268
269
270
271 public void testWithNullable() {
272
273 }
274
275
276
277
278
279 public void testSaveColumnInfo() {
280
281 }
282
283
284
285
286 public void testToDsdType() {
287 String itDsdType = it.getClass().getName().replaceFirst("PoemType","")
288 .replaceFirst("org.melati.poem.", "");
289 assertEquals(itDsdType, it.toDsdType());
290
291 }
292
293 }