root / tags / v1_1_Build_1005 / libraries / libGDBMS / src / test / java / com / hardcode / gdbms / engine / values / ComplexValueTest.java @ 12355
History | View | Annotate | Download (17.2 KB)
1 |
package com.hardcode.gdbms.engine.values; |
---|---|
2 |
|
3 |
|
4 |
import java.sql.Types; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
public class ComplexValueTest extends TestCase { |
9 |
private static String stringTest1 = "<key1>value1</key1>\n<key2>value2</key2>\n<key3>value3</key3>\n"; |
10 |
private static String stringTest2 = "<key1>value1</key1>\n<key2>value2</key2>\n<key3>value3</key3>\n<sub1>\n <skey1>svalue1</skey1>\n <skey2>svalue2</skey2>\n</sub1>"; |
11 |
private static String stringTest3 = "<key1>value1</key1>\n<key2>value2</key2>\n<key3>value3</key3>\n<sub1>\n <skey1>svalue1</skey1>\n <skey2>svalue2</skey2>\n <sub2>\n </sub2>\n <sub3>\n <sub4>\n <s4key>s4value</s4key>\n </sub4>\n </sub3>\n</sub1>"; |
12 |
private static String stringTest7 = "<key1 _type=\"IntValue\">1</key1>\n<key2 _type=\"DoubleValue\">2.2</key2>\n<key3 _type=\"BooleanValue\">true</key3>\n<key4 _type=\"IntValue\">4</key4>\n"; |
13 |
private static String stringTest8 = "<key1 _type=\"IntValue\">1</key1>\n<key2 _type=\"DoubleValue\">2.2</key2>\n<key3 _type=\"BooleanValue\">true</key3>\n<key4 _type=\"IntValue\">4</key4>\n<sub1>\n <skey1 _type=\"BooleanValue\">false</skey1>\n</sub1>\n"; |
14 |
|
15 |
private boolean equals(String str1,String str2) { |
16 |
str1 = str1.replaceAll("^\\s*",""); |
17 |
str1 = str1.replaceAll(">\\n\\s*",">"); |
18 |
|
19 |
str2 = str2.replaceAll("^\\s*",""); |
20 |
str2 = str2.replaceAll(">\\n\\s*",">"); |
21 |
return str1.equals(str2);
|
22 |
} |
23 |
public void test1() { |
24 |
ComplexValue value = ValueFactory.createComplexValue(stringTest1); |
25 |
assertNotNull(value); |
26 |
|
27 |
assertTrue("keyset.size()",value.keySet().size() == 3); |
28 |
|
29 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
30 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
31 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
32 |
|
33 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue); |
34 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue); |
35 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue); |
36 |
|
37 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
38 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
39 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
40 |
|
41 |
assertTrue("toString() == original",equals(stringTest1,value.toString()));
|
42 |
} |
43 |
|
44 |
public void test2() { |
45 |
ComplexValue value = ValueFactory.createComplexValue(stringTest2); |
46 |
assertNotNull(value); |
47 |
|
48 |
assertTrue("keyset.size()",value.keySet().size() == 4); |
49 |
|
50 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
51 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
52 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
53 |
assertTrue("containstKey('sub1')",value.containsKey("sub1")); |
54 |
|
55 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue); |
56 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue); |
57 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue); |
58 |
assertTrue("get('sub1') instanceof ComplexValue",value.get("sub1") instanceof ComplexValue); |
59 |
|
60 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
61 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
62 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
63 |
|
64 |
ComplexValue sub1 = (ComplexValue)value.get("sub1");
|
65 |
assertNotNull(sub1); |
66 |
assertTrue("sub1.keyset.size()",sub1.keySet().size() == 2); |
67 |
assertTrue("sub1.containstKey('skey1')",sub1.containsKey("skey1")); |
68 |
assertTrue("sub1.containstKey('skey2')",sub1.containsKey("skey2")); |
69 |
|
70 |
assertTrue("sub1.get('skey1') instanceof StringValue",sub1.get("skey1") instanceof StringValue); |
71 |
assertTrue("sub1.get('skey2') instanceof StringValue",sub1.get("skey2") instanceof StringValue); |
72 |
|
73 |
assertTrue("sub1.get('skey1').toString()",sub1.get("skey1").toString().equals("svalue1")); |
74 |
assertTrue("sub1.get('skey2').toString()",sub1.get("skey2").toString().equals("svalue2")); |
75 |
|
76 |
|
77 |
assertTrue("toString() == original",equals(stringTest2,value.toString()));
|
78 |
} |
79 |
|
80 |
public void test3() { |
81 |
ComplexValue value = ValueFactory.createComplexValue(stringTest3); |
82 |
assertNotNull(value); |
83 |
|
84 |
assertTrue("keyset.size()",value.keySet().size() == 4); |
85 |
|
86 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
87 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
88 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
89 |
assertTrue("containstKey('sub1')",value.containsKey("sub1")); |
90 |
assertFalse("not containstKey('kk')",value.containsKey("kk")); |
91 |
|
92 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue); |
93 |
assertFalse("get('key1') not instanceof ComplexValue",value.get("key1") instanceof ComplexValue); |
94 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue); |
95 |
assertFalse("get('key2') not instanceof ComplexValue",value.get("key2") instanceof ComplexValue); |
96 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue); |
97 |
assertTrue("get('sub1') instanceof ComplexValue",value.get("sub1") instanceof ComplexValue); |
98 |
|
99 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
100 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
101 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
102 |
|
103 |
ComplexValue sub1 = (ComplexValue)value.get("sub1");
|
104 |
assertNotNull(sub1); |
105 |
assertTrue("sub1.keyset.size()",sub1.keySet().size() == 4); |
106 |
assertTrue("sub1.containstKey('skey1')",sub1.containsKey("skey1")); |
107 |
assertTrue("sub1.containstKey('skey2')",sub1.containsKey("skey2")); |
108 |
assertTrue("sub1.containstKey('sub2')",sub1.containsKey("sub2")); |
109 |
assertTrue("sub1.containstKey('sub3')",sub1.containsKey("sub3")); |
110 |
|
111 |
assertTrue("sub1.get('skey1') instanceof StringValue",sub1.get("skey1") instanceof StringValue); |
112 |
assertTrue("sub1.get('skey2') instanceof StringValue",sub1.get("skey2") instanceof StringValue); |
113 |
assertTrue("sub1.get('sub2') instanceof ComplexValue",sub1.get("sub2") instanceof StringValue); |
114 |
assertTrue("sub1.get('sub3') instanceof ComplexValue",sub1.get("sub3") instanceof ComplexValue); |
115 |
|
116 |
assertTrue("sub1.get('skey1').toString()",sub1.get("skey1").toString().equals("svalue1")); |
117 |
assertTrue("sub1.get('skey2').toString()",sub1.get("skey2").toString().equals("svalue2")); |
118 |
|
119 |
ComplexValue sub3 = (ComplexValue)sub1.get("sub3");
|
120 |
assertNotNull(sub3); |
121 |
assertTrue("sub3.keyset.size()",sub3.keySet().size() == 1); |
122 |
assertTrue("sub3.get('sub4') instanceof ComplexValue",sub3.get("sub4") instanceof ComplexValue); |
123 |
|
124 |
ComplexValue sub4 = (ComplexValue)sub3.get("sub4");
|
125 |
assertNotNull(sub4); |
126 |
assertTrue("sub4.keyset.size()",sub3.keySet().size() == 1); |
127 |
assertTrue("sub4.get('s4key') instanceof StringValue",sub4.get("s4key") instanceof StringValue); |
128 |
assertTrue("sub4.get('s4key').toString()",sub4.get("s4key").toString().equals("s4value")); |
129 |
|
130 |
assertTrue("toString() == original",equals(stringTest3,value.toString()));
|
131 |
} |
132 |
|
133 |
public void test4() { |
134 |
ComplexValue value = ValueFactory.createComplexValue("");
|
135 |
assertNotNull(value); |
136 |
|
137 |
try {
|
138 |
value.put("key1","value1"); |
139 |
fail("put with a no Value instance");
|
140 |
} catch (Exception e) { |
141 |
assertTrue("put with a no Value instance throws a IllegalArgumentException", e instanceof IllegalArgumentException); |
142 |
} |
143 |
|
144 |
value.put("key1",ValueFactory.createValue("value1")); |
145 |
value.put("key2",ValueFactory.createValue("value2")); |
146 |
value.put("key3",ValueFactory.createValue("value3")); |
147 |
|
148 |
assertTrue("keyset.size()",value.keySet().size() == 3); |
149 |
|
150 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
151 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
152 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
153 |
|
154 |
/*
|
155 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue);
|
156 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue);
|
157 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue);
|
158 |
*/
|
159 |
|
160 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
161 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
162 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
163 |
|
164 |
assertTrue("toString() == original",equals(stringTest1,value.toString()));
|
165 |
} |
166 |
|
167 |
public void test5() { |
168 |
ComplexValue value = ValueFactory.createComplexValue("");
|
169 |
ComplexValue sub1= ValueFactory.createComplexValue("");
|
170 |
assertNotNull(value); |
171 |
assertNotNull(sub1); |
172 |
|
173 |
|
174 |
value.put("key1",ValueFactory.createValue("value1")); |
175 |
value.put("key2",ValueFactory.createValue("value2")); |
176 |
value.put("key3",ValueFactory.createValue("value3")); |
177 |
|
178 |
sub1.put("skey1",ValueFactory.createValue("svalue1")); |
179 |
sub1.put("skey2",ValueFactory.createValue("svalue2")); |
180 |
|
181 |
value.put("sub1",sub1);
|
182 |
|
183 |
|
184 |
assertTrue("keyset.size()",value.keySet().size() == 4); |
185 |
|
186 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
187 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
188 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
189 |
assertTrue("containstKey('sub1')",value.containsKey("sub1")); |
190 |
|
191 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue); |
192 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue); |
193 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue); |
194 |
assertTrue("get('sub1') instanceof ComplexValue",value.get("sub1") instanceof ComplexValue); |
195 |
|
196 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
197 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
198 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
199 |
|
200 |
sub1 = (ComplexValue)value.get("sub1");
|
201 |
assertNotNull(sub1); |
202 |
assertTrue("sub1.keyset.size()",sub1.keySet().size() == 2); |
203 |
assertTrue("sub1.containstKey('skey1')",sub1.containsKey("skey1")); |
204 |
assertTrue("sub1.containstKey('skey2')",sub1.containsKey("skey2")); |
205 |
|
206 |
assertTrue("sub1.get('skey1') instanceof StringValue",sub1.get("skey1") instanceof StringValue); |
207 |
assertTrue("sub1.get('skey2') instanceof StringValue",sub1.get("skey2") instanceof StringValue); |
208 |
|
209 |
assertTrue("sub1.get('skey1').toString()",sub1.get("skey1").toString().equals("svalue1")); |
210 |
assertTrue("sub1.get('skey2').toString()",sub1.get("skey2").toString().equals("svalue2")); |
211 |
|
212 |
|
213 |
assertTrue("toString() == original",equals(stringTest2,value.toString()));
|
214 |
} |
215 |
|
216 |
public void test6() { |
217 |
ComplexValue value = ValueFactory.createComplexValue("");
|
218 |
ComplexValue sub1 = ValueFactory.createComplexValue("");
|
219 |
ComplexValue sub3 = ValueFactory.createComplexValue("");
|
220 |
ComplexValue sub4 = ValueFactory.createComplexValue("");
|
221 |
assertNotNull(value); |
222 |
assertNotNull(sub1); |
223 |
assertNotNull(sub3); |
224 |
assertNotNull(sub4); |
225 |
|
226 |
value.put("key1",ValueFactory.createValue("value1")); |
227 |
value.put("key2",ValueFactory.createValue("value2")); |
228 |
value.put("key3",ValueFactory.createValue("value3")); |
229 |
|
230 |
|
231 |
sub4.put("s4key",ValueFactory.createValue("s4value")); |
232 |
|
233 |
sub3.put("sub4",sub4);
|
234 |
|
235 |
sub1.put("skey1",ValueFactory.createValue("svalue1")); |
236 |
sub1.put("skey2",ValueFactory.createValue("svalue2")); |
237 |
sub1.put("sub2",ValueFactory.createComplexValue("")); |
238 |
sub1.put("sub3",sub3);
|
239 |
|
240 |
value.put("sub1",sub1);
|
241 |
|
242 |
|
243 |
assertTrue("keyset.size()",value.keySet().size() == 4); |
244 |
|
245 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
246 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
247 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
248 |
assertTrue("containstKey('sub1')",value.containsKey("sub1")); |
249 |
assertFalse("not containstKey('kk')",value.containsKey("kk")); |
250 |
|
251 |
assertTrue("get('key1') instanceof StringValue",value.get("key1") instanceof StringValue); |
252 |
assertFalse("get('key1') not instanceof ComplexValue",value.get("key1") instanceof ComplexValue); |
253 |
assertTrue("get('key2') instanceof StringValue",value.get("key2") instanceof StringValue); |
254 |
assertFalse("get('key2') not instanceof ComplexValue",value.get("key2") instanceof ComplexValue); |
255 |
assertTrue("get('key3') instanceof StringValue",value.get("key3") instanceof StringValue); |
256 |
assertTrue("get('sub1') instanceof ComplexValue",value.get("sub1") instanceof ComplexValue); |
257 |
|
258 |
assertTrue("get('key1').toString()",value.get("key1").toString().equals("value1")); |
259 |
assertTrue("get('key2').toString()",value.get("key2").toString().equals("value2")); |
260 |
assertTrue("get('key3').toString()",value.get("key3").toString().equals("value3")); |
261 |
|
262 |
sub1 = (ComplexValue)value.get("sub1");
|
263 |
assertNotNull(sub1); |
264 |
assertTrue("sub1.keyset.size()",sub1.keySet().size() == 4); |
265 |
assertTrue("sub1.containstKey('skey1')",sub1.containsKey("skey1")); |
266 |
assertTrue("sub1.containstKey('skey2')",sub1.containsKey("skey2")); |
267 |
assertTrue("sub1.containstKey('sub2')",sub1.containsKey("sub2")); |
268 |
assertTrue("sub1.containstKey('sub3')",sub1.containsKey("sub3")); |
269 |
|
270 |
assertTrue("sub1.get('skey1') instanceof StringValue",sub1.get("skey1") instanceof StringValue); |
271 |
assertTrue("sub1.get('skey2') instanceof StringValue",sub1.get("skey2") instanceof StringValue); |
272 |
assertTrue("sub1.get('sub2') instanceof ComplexValue",sub1.get("sub2") instanceof StringValue); |
273 |
assertTrue("sub1.get('sub3') instanceof ComplexValue",sub1.get("sub3") instanceof ComplexValue); |
274 |
|
275 |
assertTrue("sub1.get('skey1').toString()",sub1.get("skey1").toString().equals("svalue1")); |
276 |
assertTrue("sub1.get('skey2').toString()",sub1.get("skey2").toString().equals("svalue2")); |
277 |
|
278 |
sub3 = (ComplexValue)sub1.get("sub3");
|
279 |
assertNotNull(sub3); |
280 |
assertTrue("sub3.keyset.size()",sub3.keySet().size() == 1); |
281 |
assertTrue("sub3.get('sub4') instanceof ComplexValue",sub3.get("sub4") instanceof ComplexValue); |
282 |
|
283 |
sub4 = (ComplexValue)sub3.get("sub4");
|
284 |
assertNotNull(sub4); |
285 |
assertTrue("sub4.keyset.size()",sub3.keySet().size() == 1); |
286 |
assertTrue("sub4.get('s4key') instanceof StringValue",sub4.get("s4key") instanceof StringValue); |
287 |
assertTrue("sub4.get('s4key').toString()",sub4.get("s4key").toString().equals("s4value")); |
288 |
|
289 |
assertTrue("toString() == original",equals(stringTest3,value.toString()));
|
290 |
} |
291 |
|
292 |
public void test7() { |
293 |
ComplexValue value = ValueFactory.createComplexValue(stringTest7); |
294 |
assertNotNull(value); |
295 |
|
296 |
assertTrue("keyset.size()",value.keySet().size() == 4); |
297 |
|
298 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
299 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
300 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
301 |
assertTrue("containstKey('key4')",value.containsKey("key4")); |
302 |
|
303 |
assertTrue("get('key1') instanceof IntValue",value.get("key1") instanceof IntValue); |
304 |
assertFalse("get('key1') not instanceof ComplexValue",value.get("key1") instanceof ComplexValue); |
305 |
assertTrue("get('key2') instanceof FloatValue",value.get("key2") instanceof DoubleValue); |
306 |
assertFalse("get('key2') not instanceof ComplexValue",value.get("key2") instanceof ComplexValue); |
307 |
assertTrue("get('key3') instanceof BooleanValue",value.get("key3") instanceof BooleanValue); |
308 |
assertTrue("get('key4') instanceof IntValue",value.get("key4") instanceof IntValue); |
309 |
|
310 |
assertTrue("toString() == original",equals(stringTest7,value.toString()));
|
311 |
|
312 |
} |
313 |
|
314 |
public void test8() { |
315 |
ComplexValue value = ValueFactory.createComplexValue("");
|
316 |
assertNotNull(value); |
317 |
|
318 |
value.put("key1",ValueFactory.createValue(1)); |
319 |
value.put("key2",ValueFactory.createValue(2.2)); |
320 |
value.put("key3",ValueFactory.createValue(true)); |
321 |
try {
|
322 |
value.put("key4",ValueFactory.createValueByType("4",Types.INTEGER)); |
323 |
} catch (Exception e) { |
324 |
fail(); |
325 |
} |
326 |
ComplexValue sub1 = ValueFactory.createComplexValue("");
|
327 |
sub1.put("skey1",ValueFactory.createValue(false)); |
328 |
value.put("sub1",sub1);
|
329 |
|
330 |
assertTrue("keyset.size()",value.keySet().size() == 5); |
331 |
|
332 |
assertTrue("containstKey('key1')",value.containsKey("key1")); |
333 |
assertTrue("containstKey('key2')",value.containsKey("key2")); |
334 |
assertTrue("containstKey('key3')",value.containsKey("key3")); |
335 |
assertTrue("containstKey('key4')",value.containsKey("key4")); |
336 |
assertTrue("containstKey('sub1')",value.containsKey("sub1")); |
337 |
|
338 |
assertTrue("get('key1') instanceof IntValue",value.get("key1") instanceof IntValue); |
339 |
assertFalse("get('key1') not instanceof ComplexValue",value.get("key1") instanceof ComplexValue); |
340 |
assertTrue("get('key2') instanceof FloatValue",value.get("key2") instanceof DoubleValue); |
341 |
assertFalse("get('key2') not instanceof ComplexValue",value.get("key2") instanceof ComplexValue); |
342 |
assertTrue("get('key3') instanceof BooleanValue",value.get("key3") instanceof BooleanValue); |
343 |
assertTrue("get('key4') instanceof IntValue",value.get("key4") instanceof IntValue); |
344 |
assertTrue("get('sub1') instanceof ComplexValue",value.get("sub1") instanceof ComplexValue); |
345 |
|
346 |
sub1 = (ComplexValue)value.get("sub1");
|
347 |
assertTrue("sub1.keyset.size()",sub1.keySet().size() == 1); |
348 |
|
349 |
assertTrue("sub1.containstKey('skey1')",sub1.containsKey("skey1")); |
350 |
|
351 |
assertTrue("sub1.get('skey1') instanceof BooleanValue",sub1.get("skey1") instanceof BooleanValue); |
352 |
|
353 |
assertTrue("toString() == original",equals(stringTest8,value.toString()));
|
354 |
|
355 |
} |
356 |
|
357 |
} |