1
2
3
4
5 package test.crispy.util;
6
7 import java.lang.reflect.Method;
8 import java.math.BigDecimal;
9 import java.math.BigInteger;
10 import java.sql.Time;
11 import java.sql.Timestamp;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Date;
15 import java.util.HashMap;
16 import java.util.Hashtable;
17 import java.util.Iterator;
18 import java.util.LinkedList;
19 import java.util.List;
20 import java.util.Locale;
21 import java.util.Map;
22 import java.util.Properties;
23 import java.util.Vector;
24
25 import junit.framework.TestCase;
26 import net.sf.crispy.InvocationException;
27 import net.sf.crispy.impl.ServiceManager;
28 import net.sf.crispy.util.Converter;
29 import net.sf.crispy.util.Invoker;
30 import test.crispy.example.model.Adresse;
31 import test.crispy.example.model.Car;
32 import test.crispy.example.model.ClassWithNoParameterConstructor;
33 import test.crispy.example.model.DataTransferObject;
34 import test.crispy.example.model.InvalidClass;
35 import test.crispy.example.model.Kunde;
36 import test.crispy.example.model.Node;
37 import test.crispy.example.model.NodeHashCode1;
38 import test.crispy.example.model.NodeHashCode2;
39 import test.crispy.example.model.NodeHashCode3;
40 import test.crispy.example.model.Primitive;
41 import test.crispy.example.model.ProblemNode;
42 import test.crispy.example.model.SpecialTestClass;
43 import test.crispy.example.model.Status;
44 import test.crispy.example.model.SubProblemNode;
45 import test.crispy.example.model.SubSubProblemNode;
46 import test.crispy.example.service.Calculator;
47
48 /**
49 * @author Linke
50 *
51 */
52 public class ConverterTest extends TestCase {
53
54 public static final String DELIMITER = "~_-_~";
55
56 public void testMakeSimple() throws Exception {
57 assertNull(new Converter().makeSimple(null));
58 assertEquals(new Converter().makeSimple(new Integer(5)), new Integer(5));
59 assertEquals(new Converter().makeSimple(new Double(5.4)), new Double(5.4));
60 assertEquals(new Converter().makeSimple(Boolean.TRUE), Boolean.TRUE);
61 assertEquals(new Converter().makeSimple(new String("string")), new String("string"));
62 Date lvDate = new Date();
63 assertEquals(new Converter().makeSimple(lvDate), lvDate);
64 Map lvMap = new Hashtable(2);
65 lvMap.put("String", "String");
66 lvMap.put(new Integer(1), new Integer(1));
67 assertEquals(new Converter().makeSimple(lvMap), lvMap);
68 Vector v = new Vector();
69 v.add("String");
70 v.add(new Integer(5));
71 assertEquals(new Converter().makeSimple(v), v);
72 }
73
74 public void testMakeSimpleConvert() throws Exception {
75 byte lvByte = 5;
76 short lvShort = 7;
77 assertEquals(new Converter().makeSimple(new Byte(lvByte)), new Integer(5));
78 assertEquals(new Converter().makeSimple(new Long(6)), new Integer(6));
79 assertEquals(new Converter().makeSimple(new Short(lvShort)), new Integer(7));
80 assertEquals(new Converter().makeSimple(new Float(5.4)), new Double(5.4));
81 assertEquals(new Converter().makeSimple(new Character('A')), new String("A"));
82 assertEquals(new Converter().makeSimple(new BigDecimal(4.32)), new Double(4.32));
83 Date lvDate = new Date();
84 java.sql.Date lvDateSql = new java.sql.Date(lvDate.getTime());
85 assertEquals(new Converter().makeSimple(lvDateSql), lvDate);
86 }
87
88 public void testMakeSimpleConverterWithVectorWithNullElement() throws Exception {
89 Vector v = new Vector();
90 v.add(null);
91 Object lvResult = new Converter().makeSimple(v);
92 assertNotNull(lvResult);
93 assertTrue(lvResult instanceof Vector);
94 Vector v2 = (Vector) lvResult;
95 assertEquals(v2.size(), 0);
96 }
97
98 public void testMakeComplexWithNull() throws Exception {
99 Object lvResult = new Converter().makeComplex(null);
100 assertNull(lvResult);
101 }
102
103 public void testMakeComplexWithObject() throws Exception {
104 Object lvResult = new Converter().makeComplex(new Object());
105 assertNull(lvResult);
106 }
107
108 public void testMakeSimpleTimeConvert() throws Exception {
109 Time lvTime = new Time(new Date().getTime());
110 Object o = new Converter().makeComplex(new Converter().makeSimple(lvTime), Time.class);
111 assertEquals(lvTime, o);
112 Timestamp lvTimestamp = new Timestamp(new Date().getTime());
113 o = new Converter().makeComplex(new Converter().makeSimple(lvTimestamp), Timestamp.class);
114 assertEquals(lvTimestamp, o);
115 }
116
117 public void testDate2Time() throws Exception {
118 Converter lvConverter = new Converter();
119 Date d = new Date();
120 Time time = (Time) lvConverter.makeComplex(d, Time.class);
121 assertNotNull(time);
122 assertEquals(d, time);
123
124 Timestamp ts = new Timestamp(d.getTime());
125 Time time2 = (Time) lvConverter.makeComplex(ts, Time.class);
126 assertNotNull(time2);
127 assertEquals(d, time2);
128
129 Long l = new Long(d.getTime());
130 Time time3 = (Time) lvConverter.makeComplex(l, Time.class);
131 assertNotNull(time3);
132 assertEquals(d, time3);
133
134 try {
135 lvConverter.makeComplex(new String ("blabla"), Time.class);
136 fail("String: blabla is not a Time");
137 } catch (InvocationException e) {
138 assertTrue(true);
139 }
140 }
141
142 public void testDate2Timestamp() throws Exception {
143 Converter lvConverter = new Converter();
144 Date d = new Date();
145 Timestamp ts = (Timestamp) lvConverter.makeComplex(d, Timestamp.class);
146 assertNotNull(ts);
147 assertEquals(d, ts);
148
149 Time t = new Time(d.getTime());
150 Timestamp ts2 = (Timestamp) lvConverter.makeComplex(t, Timestamp.class);
151 assertNotNull(ts2);
152 assertEquals(d, ts2);
153
154 Long l = new Long(d.getTime());
155 Timestamp ts3 = (Timestamp) lvConverter.makeComplex(l, Timestamp.class);
156 assertNotNull(ts3);
157 assertEquals(d, ts3);
158
159 try {
160 lvConverter.makeComplex(new String ("blabla"), Timestamp.class);
161 fail("String: blabla is not a Timestamp");
162 } catch (InvocationException e) {
163 assertTrue(true);
164 }
165 }
166
167
168 public void testMakeSimpleClassConvert() throws Exception {
169 Class lvTimeClass = Time.class;
170 Object o = new Converter().makeComplex(new Converter().makeSimple(lvTimeClass), Class.class);
171 assertEquals(lvTimeClass, o);
172 }
173
174 public void testMakeSimpleStringBufferConvert() throws Exception {
175 StringBuffer lvBuffer = new StringBuffer("Hallo");
176 Object o = new Converter().makeComplex(new Converter().makeSimple(lvBuffer), StringBuffer.class);
177 assertEquals(lvBuffer.toString(), o.toString());
178 assertEquals(lvBuffer.getClass(), o.getClass());
179 }
180
181 public void testMakeSimpleBigConvert() throws Exception {
182 BigInteger lvBigInteger = new BigInteger("12345");
183 Object o = new Converter().makeComplex(new Converter().makeSimple(lvBigInteger), BigInteger.class);
184 assertEquals(lvBigInteger, o);
185
186 BigDecimal lvBigDecimal = new BigDecimal("12.33");
187 o = new Converter().makeComplex(new Converter().makeSimple(lvBigDecimal), BigDecimal.class);
188 assertEquals(lvBigDecimal.doubleValue(), ((BigDecimal) o).doubleValue(), 3);
189 }
190
191
192 public void testMakeSimpleMap() throws Exception {
193 Kunde lvKunde = new Kunde();
194 lvKunde.setName("Schulz");
195 lvKunde.setVorname("Egon");
196 lvKunde.setGehalt(new BigDecimal(5467.23));
197 Hashtable lvConvertKunde = (Hashtable) new Converter().makeSimple(lvKunde);
198
199 assertEquals(lvConvertKunde.get("gehalt"), new Double(5467.23));
200 assertEquals(lvConvertKunde.get("name"), "Schulz");
201 assertEquals(lvConvertKunde.get("vorname"), "Egon");
202 assertEquals(lvConvertKunde.get("class"), Kunde.class.getName());
203 assertEquals(new Vector(), lvConvertKunde.get("adressen"));
204 }
205
206 public void testMakeSimpleMapWithIntegerKey() throws Exception {
207 Map lvMap = new HashMap();
208 lvMap.put(new Integer(1), new Integer(2));
209 Map lvResultMap = (Map) new Converter().makeSimple(lvMap);
210 Object lvKey = lvResultMap.keySet().iterator().next();
211 Object lvValue = lvResultMap.values().iterator().next();
212 assertEquals(lvKey.getClass(), Integer.class);
213 assertEquals(lvValue.getClass(), Integer.class);
214 assertEquals(lvKey, new Integer(1));
215 assertEquals(lvValue, new Integer(2));
216 }
217
218 public void testMakeSimpleMapWithKeyConverterLong2Integer() throws Exception {
219 Map lvMap = new HashMap();
220 lvMap.put(new Long(1), new Long(2));
221 Map lvResultMap = (Map) new Converter().makeSimple(lvMap);
222 Object lvKey = lvResultMap.keySet().iterator().next();
223 Object lvValue = lvResultMap.values().iterator().next();
224 assertEquals(lvKey.getClass(), Integer.class);
225 assertEquals(lvValue.getClass(), Integer.class);
226 assertEquals(lvKey, new Integer(1));
227 assertEquals(lvValue, new Integer(2));
228 }
229
230 public void testMakeSimpleAndComplexMapWithKeyConverterLong2Integer() throws Exception {
231 Map lvMap = new HashMap();
232 lvMap.put(new Long(1), new Long(2));
233 Converter lvConverter = new Converter();
234 lvConverter.setWithSimpleKeyMapper(true);
235 Object lvSimple = lvConverter.makeSimple(lvMap);
236 Object lvComplex = lvConverter.makeComplex(lvSimple);
237 assertNotNull(lvComplex);
238 assertTrue(lvComplex instanceof Map);
239 Map lvMapAfter = (Map) lvComplex;
240 assertEquals(lvMapAfter.size(), 1);
241 assertEquals(lvMapAfter.keySet().iterator().next(), new Long(1));
242 assertEquals(lvMapAfter.values().iterator().next(), new Integer(2));
243 }
244
245 public void testMakeTwiceSimpleMapWithKeyConverterLong2Integer() throws Exception {
246 Map lvMap = new HashMap();
247 lvMap.put(new Long(1), new Long(2));
248 Converter lvConverter = new Converter();
249 lvConverter.setWithSimpleKeyMapper(true);
250 Object lvSimple = lvConverter.makeSimple(lvMap);
251 lvSimple = lvConverter.makeSimple(lvSimple);
252 Object lvComplex = lvConverter.makeComplex(lvSimple);
253 assertNotNull(lvComplex);
254 assertTrue(lvComplex instanceof Map);
255 Map lvMapAfter = (Map) lvComplex;
256 assertEquals(lvMapAfter.size(), 1);
257 assertEquals(lvMapAfter.keySet().iterator().next(), new Long(1));
258 assertEquals(lvMapAfter.values().iterator().next(), new Integer(2));
259 }
260
261 public void testMakeSimpleAndComplexWithDifferentConverterAndThrownException() throws Exception {
262 Map lvMap = new HashMap();
263 lvMap.put(new Long(1), new Long(2));
264 Converter lvConverterSimple = new Converter();
265 Object lvSimple = lvConverterSimple.makeSimple(lvMap);
266
267 Converter lvConverterComplex = new Converter();
268 lvConverterComplex.setWithSimpleKeyMapper(true);
269 try {
270 lvConverterComplex.makeComplex(lvSimple);
271 fail("Key must be a String");
272 } catch (Exception e) {
273 assertTrue(true);
274 }
275
276 }
277
278 public void testMakeSimpleAndComplexWithDifferentConverterMapWithKeyConverterLong2Integer() throws Exception {
279 Map lvMap = new HashMap();
280 lvMap.put("1", new Long(2));
281 Converter lvConverterSimple = new Converter();
282 Object lvSimple = lvConverterSimple.makeSimple(lvMap);
283
284 Converter lvConverterComplex = new Converter();
285 lvConverterComplex.setWithSimpleKeyMapper(true);
286 try {
287 lvConverterComplex.makeComplex(lvSimple);
288 fail("Make simple is without SimpleKeyMappe, makeComplex has a SimpleKeyMapper");
289 } catch (Exception e) {
290 assertTrue(true);
291 }
292 }
293
294 public void testMakeSimpleAndComplexWithDifferentConverterMapWithKeyConverterLong2Integer2() throws Exception {
295 Map lvMap = new HashMap();
296 lvMap.put("1", new Long(2));
297 Converter lvConverterSimple = new Converter();
298 lvConverterSimple.setWithSimpleKeyMapper(true);
299 Object lvSimple = lvConverterSimple.makeSimple(lvMap);
300
301
302 Converter lvConverterComplex = new Converter();
303 Object lvComplex = lvConverterComplex.makeComplex(lvSimple);
304 assertNotNull(lvComplex);
305 assertTrue(lvComplex instanceof Map);
306 Map lvMapAfter = (Map) lvComplex;
307 assertEquals(1, lvMapAfter.size());
308 assertEquals("1" + DELIMITER + "1", lvMapAfter.keySet().iterator().next());
309 assertEquals(new Integer(2), lvMapAfter.values().iterator().next());
310 }
311
312
313 public void testMakeSimpleAndComplexMapWithKeyConverterLong2Integer_2() throws Exception {
314 Map lvMap = new HashMap();
315 lvMap.put(new Long(3), new Long(4));
316 lvMap.put(new Long(1), new Long(2));
317 lvMap.put(new Long(-1), new Long(-2));
318 Converter lvConverter = new Converter();
319 lvConverter.setWithSimpleKeyMapper(true);
320 Object lvSimple = lvConverter.makeSimple(lvMap);
321 Object lvComplex = lvConverter.makeComplex(lvSimple);
322 assertNotNull(lvComplex);
323 assertTrue(lvComplex instanceof Map);
324 Map lvMapAfter = (Map) lvComplex;
325 assertEquals(lvMapAfter.size(), 3);
326 Iterator it = lvMapAfter.keySet().iterator();
327 while (it.hasNext()) {
328 Object lvKey = it.next();
329 Integer lvValue = (Integer) lvMapAfter.get(lvKey);
330 Long lvValueBefore =(Long) lvMap.get(lvKey);
331 assertEquals(lvValueBefore.intValue(), lvValue.intValue());
332
333 }
334 }
335
336
337 public void testMakeSimpleMapWithKeyConverterBigDecimal2Double() throws Exception {
338 Map lvMap = new HashMap();
339 lvMap.put(new BigDecimal("4.32"), new BigDecimal(5.67));
340 Map lvResultMap = (Map) new Converter().makeSimple(lvMap);
341 Object lvKey = lvResultMap.keySet().iterator().next();
342 Object lvValue = lvResultMap.values().iterator().next();
343 assertEquals(lvKey.getClass(), Double.class);
344 assertEquals(lvValue.getClass(), Double.class);
345 assertEquals(lvKey, new Double(4.32));
346 assertEquals(lvValue, new Double(5.67));
347 }
348
349 public void testMakeSimpleAndComplexMapWithKeyConverterBigDecimal2Double() throws Exception {
350 Map lvMap = new HashMap();
351 lvMap.put(new BigDecimal("4.32"), new BigDecimal("5.67"));
352 Converter lvConverter = new Converter();
353 lvConverter.setWithSimpleKeyMapper(true);
354 Object lvSimple = lvConverter.makeSimple(lvMap);
355 Object lvComplex = lvConverter.makeComplex(lvSimple);
356 assertNotNull(lvComplex);
357 assertTrue(lvComplex instanceof Map);
358 Map lvMapAfter = (Map) lvComplex;
359 assertEquals(lvMapAfter.size(), 1);
360 assertEquals(lvMapAfter.keySet().iterator().next(), new BigDecimal("4.32"));
361 assertEquals(lvMapAfter.values().iterator().next(), new Double("5.67"));
362 }
363
364 public void testMakeSimpleVector() throws Exception {
365 Kunde lvKunde1 = new Kunde();
366 lvKunde1.setName("Schulz");
367 lvKunde1.setVorname("Egon");
368 Kunde lvKunde2 = new Kunde();
369 lvKunde2.setName("Schulz");
370 lvKunde2.setVorname("Egon");
371 List lvListKunde = new ArrayList(2);
372 lvListKunde.add(lvKunde1);
373 lvListKunde.add(lvKunde2);
374 Vector lvVecKunde = (Vector) new Converter().makeSimple(lvListKunde);
375
376 Map lvKunde1Map = (Map) lvVecKunde.get(0);
377 assertEquals(lvKunde1.getName(), lvKunde1Map.get("name"));
378 assertEquals(lvKunde1.getVorname(), lvKunde1Map.get("vorname"));
379
380 Map lvKunde2Map = (Map) lvVecKunde.get(0);
381 assertEquals(lvKunde2.getName(), lvKunde2Map.get("name"));
382 assertEquals(lvKunde2.getVorname(), lvKunde2Map.get("vorname"));
383 }
384
385 public void testMakeSimpleObjectWithCycle() throws Exception {
386 Kunde k = new Kunde ("Test");
387 Adresse a1 = new Adresse();
388 a1.setOrt("Magdeburg");
389 Adresse a2 = new Adresse();
390 a2.setOrt("Cottbus");
391 k.getAdressen().add(a1);
392 k.getAdressen().add(a2);
393 a1.setKunde(k);
394
395 Object o = new Converter().makeSimple(k);
396 assertTrue(o instanceof Hashtable);
397 Map lvMap = (Map) o;
398 assertEquals(lvMap.get("name"), "Test");
399 Vector v = (Vector) lvMap.get("adressen");
400 assertTrue(v.size() == 2);
401 lvMap = (Map) v.get(0);
402 assertEquals(lvMap.get("ort"), "Magdeburg");
403
404 o = lvMap.get("kunde");
405 assertEquals(Converter.HASH_CODE_KEY+k.hashCode(), o);
406 lvMap = (Map) v.get(1);
407 assertEquals(lvMap.get("ort"), "Cottbus");
408 }
409
410 public void testMakeSimpleObjectWithCycle2() throws Exception {
411 Kunde k = new Kunde ("Test");
412 Adresse a1 = new Adresse();
413 a1.setOrt("Magdeburg");
414 Adresse a2 = new Adresse();
415 a2.setOrt("Cottbus");
416 k.getAdressen().add(a1);
417 k.getAdressen().add(a2);
418 a2.setKunde(k);
419
420 Object o = new Converter().makeSimple(k);
421 assertTrue(o instanceof Hashtable);
422 Map lvMap = (Map) o;
423 assertEquals(lvMap.get("name"), "Test");
424 Vector v = (Vector) lvMap.get("adressen");
425 assertTrue(v.size() == 2);
426 lvMap = (Map) v.get(0);
427 assertEquals(lvMap.get("ort"), "Magdeburg");
428 lvMap = (Map) v.get(1);
429 assertEquals(lvMap.get("ort"), "Cottbus");
430
431 o = lvMap.get("kunde");
432 assertEquals(Converter.HASH_CODE_KEY+k.hashCode(), o);
433 }
434
435 public void testMakeSimpleObjectWithCycleInMap() throws Exception {
436 Node n1 = new Node ("1");
437 Node n2 = new Node ("2");
438 Node n3 = new Node ("3");
439 Node na = new Node ("a");
440 Node nb = new Node ("b");
441
442 n1.getChildrenMap().put("2", n2);
443 n1.getChildrenMap().put("3", n3);
444 n1.getChildrenMap().put("a", na);
445 n1.getChildrenMap().put("b", nb);
446
447 n2.getChildrenMap().put("3", n3);
448 n3.getChildrenMap().put("1", n1);
449
450 Object o = new Converter().makeSimple(n1);
451 Map lvMap1 = (Map) o;
452 assertEquals(lvMap1.get("name"), "1");
453 Map lvMap1children = (Map) lvMap1.get("childrenMap");
454 assertEquals(((Map) lvMap1children.get("2")).get("name"), "2");
455 assertEquals(((Map) lvMap1children.get("3")).get("name"), "3");
456 assertEquals(((Map) lvMap1children.get("a")).get("name"), "a");
457 assertEquals(((Map) lvMap1children.get("b")).get("name"), "b");
458 Map lvMap2children = (Map) ((Map) lvMap1children.get("2")).get("childrenMap");
459 String lvHashCode3 = (String) ((Map) lvMap1children.get("3")).get(Converter.HASH_CODE_KEY);
460 assertEquals(Converter.extractHashCode(lvMap2children.get("3")), lvHashCode3);
461
462 Node n1After = (Node) new Converter().makeComplex(o);
463 assertTrue(n1After.getChildrenMap().size() == 4);
464 assertEquals(((Node) n1After.getChildrenMap().get("a")).getName(), "a");
465 assertEquals(((Node) n1After.getChildrenMap().get("b")).getName(), "b");
466
467 Node n3After = (Node) n1After.getChildrenMap().get("3");
468 assertEquals(n3After.getChildrenMap().get("1"), n1After);
469
470 Node n2After = (Node) n1After.getChildrenMap().get("2");
471 assertEquals(n2After.getChildrenMap().get("3"), n3After);
472 }
473
474
475 public void testMakeSimpleObjectWithCycleInVector() throws Exception {
476 Adresse a1 = new Adresse();
477 a1.setOrt("Magdeburg");
478 Adresse a2 = new Adresse();
479 a2.setOrt("Cottbus");
480 a1.getAdressen().add(a2);
481 a2.getAdressen().add(a1);
482
483 Object o = new Converter().makeSimple(a1);
484 assertTrue(o instanceof Hashtable);
485 Map lvMap = (Map) o;
486 assertEquals(lvMap.get("ort"), "Magdeburg");
487 Vector v = (Vector) lvMap.get("adressen");
488 assertTrue(v.size() == 1);
489 lvMap = (Map) v.get(0);
490 assertEquals(lvMap.get("ort"), "Cottbus");
491 v = (Vector) lvMap.get("adressen");
492 assertTrue(v.size() == 1);
493 o = v.get(0);
494
495 assertEquals(Converter.HASH_CODE_KEY+a1.hashCode(), o);
496 }
497
498 public void testMakeNodeTree() throws Exception {
499 Node lvNode1 = Node.createExampleTree();
500 Object o = new Converter().makeSimple(lvNode1);
501 assertTrue(o instanceof Hashtable);
502 Map lvMap = (Map) o;
503 assertEquals(lvMap.get("name"), "1");
504 Vector v = (Vector) lvMap.get("children");
505 assertEquals(v.size(), 3);
506
507 Map lvMapNodea = (Map) v.get(0);
508 assertEquals(lvMapNodea.get("name"), "a");
509
510 Map lvMapNode2 = (Map) v.get(1);
511 assertEquals(lvMapNode2.get("name"), "2");
512 Vector v2 = (Vector) lvMapNode2.get("children");
513 assertEquals(v2.size(), 2);
514 o = v2.get(0);
515
516 Node lvNodea = (Node) lvNode1.getChildren().get(0);
517 assertEquals(Converter.HASH_CODE_KEY + lvNodea.hashCode(), o);
518
519
520 Map lvMapNode3 = (Map) v.get(2);
521 assertEquals(lvMapNode3.get("name"), "3");
522 Vector v3 = (Vector) lvMapNode3.get("children");
523 assertEquals(v3.size(), 2);
524 o = v3.get(0);
525
526 assertEquals(Converter.HASH_CODE_KEY + lvNodea.hashCode(), o);
527 }
528
529
530 public void testMakeSimpleAndComplexNodeTree() throws Exception {
531 Node n1 = new Node ("1");
532 Node n2 = new Node ("2");
533 Node n3 = new Node ("3");
534 n1.setNode(n2);
535 n2.setNode(n3);
536 n3.setNode(n1);
537
538 Object o = new Converter().makeSimple(n1);
539 o = new Converter().makeComplex(o);
540 Node n11 = (Node) o;
541 assertEquals(n1.getName(), n11.getName());
542 assertEquals(n2.getName(), n11.getNode().getName());
543 assertEquals(n3.getName(), n11.getNode().getNode().getName());
544 assertEquals(n11.getNode().getNode().getNode(), n11);
545 }
546
547 public void testMakeSimpleAndComplexNodeTree2() throws Exception {
548 Node n1 = new Node ("1");
549 Node n2 = new Node ("2");
550 Node n3 = new Node ("3");
551 Node na = new Node ("a");
552 Node nb = new Node ("b");
553 n1.setNode(n2);
554 n2.setNode(n3);
555 n3.setNode(n1);
556 n1.getChildren().add(na);
557 n1.getChildren().add(nb);
558 n2.getChildren().add(na);
559 n3.getChildren().add(nb);
560
561 Object o = new Converter().makeSimple(n1);
562 o = new Converter().makeComplex(o);
563 Node n11 = (Node) o;
564 Node n1a = (Node) n11.getChildren().get(0);
565 Node n1b = ((Node) n11.getChildren().get(1));
566
567 assertEquals(n1.getName(), n11.getName());
568 assertEquals(n1a.getName(), na.getName());
569 assertEquals(n1b.getName(), nb.getName());
570
571 assertEquals(n2.getName(), n11.getNode().getName());
572 assertEquals(n1a, n11.getNode().getChildren().get(0));
573
574 assertEquals(n3.getName(), n11.getNode().getNode().getName());
575 assertEquals(n11.getNode().getNode().getNode(), n11);
576 assertEquals(n1b, n11.getNode().getNode().getChildren().get(0));
577 }
578
579 public void testMakeSimpleAndComplexTree() throws Exception {
580 Node lvNodeRoot1 = Node.createExampleTree();
581 Object o = new Converter().makeSimple(lvNodeRoot1);
582
583 Node lvNode1 = (Node) new Converter().makeComplex(o);
584 Node lvNodea = (Node) lvNode1.getChildren().get(0);
585 assertEquals(lvNodea.getName(), "a");
586 Node lvNode2 = (Node) lvNode1.getChildren().get(1);
587 assertEquals(lvNode2.getName(), "2");
588 Node lvNode3 = (Node) lvNode1.getChildren().get(2);
589 assertEquals(lvNode3.getName(), "3");
590
591 Node lvNodea2 = (Node) lvNode2.getChildren().get(0);
592 assertEquals(lvNodea.getName(), lvNodea2.getName());
593 assertEquals(lvNodea, lvNodea2);
594 Node lvNodeb2 = (Node) lvNode2.getChildren().get(1);
595 assertEquals("b", lvNodeb2.getName());
596
597 Node lvNodea3 = (Node) lvNode3.getChildren().get(0);
598 assertEquals(lvNodea.getName(), lvNodea3.getName());
599 assertEquals(lvNodea, lvNodea3);
600 Node lvNodeb3 = (Node) lvNode3.getChildren().get(1);
601 assertEquals("b", lvNodeb3.getName());
602 assertEquals(lvNodeb2, lvNodeb3);
603 }
604
605 public void testMakeSimpleAndComplexTreeMap() throws Exception {
606 Node n1 = new Node ("1");
607 Node n2 = new Node ("2");
608 Node n3 = new Node ("3");
609 Node na = new Node ("a");
610 Node nb = new Node ("b");
611
612 n1.getChildrenMap().put("2", n2);
613 n1.getChildrenMap().put("3", n3);
614 n1.getChildrenMap().put("a", na);
615 n1.getChildrenMap().put("b", nb);
616 n2.getChildrenMap().put("3", n3);
617 n3.getChildrenMap().put("1", n1);
618
619 Object o = new Converter().makeSimple(n1);
620 Node n1After = (Node) new Converter().makeComplex(o);
621 assertEquals(n1After.getName(), n1.getName());
622 assertEquals(n1After.getChildrenMap().size(), n1.getChildrenMap().size());
623 Node n2After = (Node) n1After.getChildrenMap().get("2");
624 assertEquals(n2After.getName(), n2.getName());
625 Node n3After = (Node) n1After.getChildrenMap().get("3");
626 assertEquals(n3After.getName(), n3.getName());
627 Node naAfter = (Node) n1.getChildrenMap().get("a");
628 assertEquals(naAfter.getName(), na.getName());
629 Node nbAfter = (Node) n1.getChildrenMap().get("b");
630 assertEquals(nbAfter.getName(), nb.getName());
631
632 assertEquals(n3After, n2After.getChildrenMap().get("3"));
633 assertEquals(n1After.getName(), ((Node) n3After.getChildrenMap().get("1")).getName());
634 assertEquals(n1After, n3After.getChildrenMap().get("1"));
635 }
636
637 public void testBiDirectionalNodeRelation() throws Exception {
638 Node n1 = new Node("Node1");
639 Node n2 = new Node("Node2");
640 Node n3 = new Node("Node3");
641
642 n1.getChildrenMap().put(n2.getName(), n2);
643 n1.getChildrenMap().put(n3.getName(), n3);
644 n2.setNode(n1);
645 n3.setNode(n1);
646 Vector v = new Vector();
647 v.add(n2);
648 v.add(n3);
649
650 Converter lvConverter = new Converter();
651 Object o = lvConverter.makeSimple(v);
652 o = lvConverter.makeComplex(o);
653
654 assertTrue(o instanceof Vector);
655 v = (Vector) o;
656 assertEquals(v.size(), 2);
657 Node n22 = (Node) v.get(0);
658 Node n33 = (Node) v.get(1);
659 assertEquals(n22.getName(), n2.getName());
660 assertEquals(n33.getName(), n3.getName());
661 Node n11 = n22.getNode();
662 assertEquals(n11.getName(), n33.getNode().getName());
663 assertEquals(n22.getNode(), n33.getNode());
664 assertEquals(n22.getNode(), n11);
665 assertEquals(n33.getNode(), n11);
666 assertEquals(n11.getChildrenMap().get(n22.getName()), n22);
667 assertEquals(n11.getChildrenMap().get(n33.getName()), n33);
668 }
669
670
671 public void testMakeComplex() throws Exception {
672 Map lvKundeMap = new Hashtable();
673 lvKundeMap.put("name", "Meier");
674 lvKundeMap.put("vorname", "Nadine");
675 lvKundeMap.put("gehalt", new Double(1234.5));
676 lvKundeMap.put("class", Kunde.class.getName());
677
678 Kunde lvKunde = (Kunde) new Converter().makeComplex(lvKundeMap);
679
680 assertEquals(lvKunde.getName(), lvKundeMap.get("name"));
681 assertEquals(lvKunde.getVorname(), lvKundeMap.get("vorname"));
682 assertEquals(lvKunde.getGehalt().toString(), lvKundeMap.get("gehalt").toString());
683 }
684
685 public void testMakeComplexMap() throws Exception {
686 Map lvKundeMap = new Hashtable();
687 lvKundeMap.put("name", "Meier");
688 lvKundeMap.put("vorname", "Nadine");
689 lvKundeMap.put("gehalt", new Double(1234.5));
690
691 Map lvComplexMap = (Map) new Converter().makeComplex(lvKundeMap);
692 assertTrue(lvComplexMap instanceof Hashtable);
693 assertTrue(lvComplexMap.size() == 3);
694 assertTrue(lvComplexMap.get("name").equals("Meier"));
695 }
696
697 public void testMakeComplexList() throws Exception {
698 List lvList = new ArrayList();
699 lvList.add(new Integer(5));
700 lvList.add("abc");
701
702 List lvComplexList = (List) new Converter().makeComplex(lvList);
703 assertTrue(lvComplexList instanceof Vector);
704 assertTrue(lvComplexList.size() == 2);
705 assertTrue(lvComplexList.get(0).equals(new Integer(5)));
706 }
707
708 public void testMakeComplexConverterWithVectorWithNullElement() throws Exception {
709 Vector v = new Vector();
710 v.add(null);
711 Object lvResult = new Converter().makeComplex(v);
712 assertNotNull(lvResult);
713 assertTrue(lvResult instanceof Vector);
714 Vector v2 = (Vector) lvResult;
715 assertEquals(v2.size(), 0);
716 }
717
718 public void testMakeComplexSimpleDatatypes() throws Exception {
719 Date lvDate = new Date();
720 Object lvResult = new Converter().makeComplex(lvDate);
721 assertNotNull(lvResult);
722 assertTrue(lvResult instanceof Date);
723
724 java.sql.Date lvDateSql = new java.sql.Date(lvDate.getTime());
725 lvResult = new Converter().makeComplex(lvDateSql);
726 assertNotNull(lvResult);
727 assertTrue(lvResult instanceof java.sql.Date);
728
729 lvResult = new Converter().makeComplex(new Byte((byte) 5));
730 assertNotNull(lvResult);
731 assertTrue(lvResult instanceof Byte);
732 assertEquals(lvResult, new Byte((byte) 5));
733
734 lvResult = new Converter().makeComplex(new Short((short) 7));
735 assertNotNull(lvResult);
736 assertTrue(lvResult instanceof Short);
737 assertEquals(lvResult, new Short((short) 7));
738
739 lvResult = new Converter().makeComplex(new Float(5.4));
740 assertNotNull(lvResult);
741 assertTrue(lvResult instanceof Float);
742 assertEquals(lvResult, new Float(5.4));
743
744 lvResult = new Converter().makeComplex(new Character('c'));
745 assertNotNull(lvResult);
746 assertTrue(lvResult instanceof Character);
747 assertEquals(lvResult, new Character('c'));
748
749 }
750
751 public void testConvertPrimitiveDatatype() throws Exception {
752 Primitive lvPrimitive = new Primitive();
753 lvPrimitive.setBooleanValue(true);
754 short s = 1;
755 lvPrimitive.setShortValue(s);
756 byte b = 2;
757 lvPrimitive.setByteValue(b);
758 lvPrimitive.setIntValue(3);
759 lvPrimitive.setLongValue(4);
760 lvPrimitive.setDoubleValue(4.3);
761 lvPrimitive.setFloatValue(5.8f);
762 lvPrimitive.setCharValue('C');
763
764 Map lvPrimitiveMap = (Map) new Converter().makeSimple(lvPrimitive);
765 Primitive lvPrimitivePost = (Primitive) new Converter().makeComplex(lvPrimitiveMap);
766
767 assertEquals(lvPrimitive.getBooleanValue(), lvPrimitivePost.getBooleanValue());
768 assertEquals(lvPrimitive.getByteValue(), lvPrimitivePost.getByteValue());
769 assertEquals(lvPrimitive.getShortValue(), lvPrimitivePost.getShortValue());
770 assertEquals(lvPrimitive.getIntValue(), lvPrimitivePost.getIntValue());
771 assertEquals(lvPrimitive.getLongValue(), lvPrimitivePost.getLongValue());
772 assertEquals(lvPrimitive.getDoubleValue(), lvPrimitivePost.getDoubleValue(), 0);
773 assertEquals(lvPrimitive.getFloatValue(), lvPrimitivePost.getFloatValue(), 0);
774 assertEquals(lvPrimitive.getCharValue(), lvPrimitivePost.getCharValue());
775 }
776
777 public void testConvertSet() throws Exception {
778 String lvSetString = "SET";
779 String lvNodeName = "SET-NODE";
780 Node lvNode = new Node (lvNodeName);
781 lvNode.getSets().add(lvSetString);
782 Converter c = new Converter();
783 Object simple = c.makeSimple(lvNode);
784 Node lvNode2 = (Node) c.makeComplex(simple);
785 assertEquals(lvNode2.getName(), lvNodeName);
786 assertEquals(lvNode2.getSets().size(), 1);
787 assertEquals(lvNode2.getSets().iterator().next(), lvSetString);
788 }
789
790 public void testConvertString2Value() throws Exception {
791 Object o = Converter.convertString2Value("true", boolean.class);
792 assertTrue(o.getClass().getName().equals(Boolean.class.getName()));
793 o = Converter.convertString2Value("true", Boolean.class);
794 assertTrue(o.getClass().getName().equals(Boolean.class.getName()));
795 o = Converter.convertString2Value("1", short.class);
796 assertTrue(o.getClass().getName().equals(Short.class.getName()));
797 o = Converter.convertString2Value("3", byte.class);
798 assertTrue(o.getClass().getName().equals(Byte.class.getName()));
799 o = Converter.convertString2Value("3", int.class);
800 assertTrue(o.getClass().getName().equals(Integer.class.getName()));
801 o = Converter.convertString2Value("3", long.class);
802 assertTrue(o.getClass().getName().equals(Long.class.getName()));
803 o = Converter.convertString2Value("3.1", double.class);
804 assertTrue(o.getClass().getName().equals(Double.class.getName()));
805 o = Converter.convertString2Value("3.4", float.class);
806 assertTrue(o.getClass().getName().equals(Float.class.getName()));
807 o = Converter.convertString2Value("a", char.class);
808 assertTrue(o.getClass().getName().equals(Character.class.getName()));
809 o = Converter.convertString2Value("abc", String.class);
810 assertTrue(o.getClass().getName().equals(String.class.getName()));
811 if (Locale.getDefault().equals(Locale.GERMANY)) {
812 o = Converter.convertString2Value("28.12.2005", Date.class);
813 assertTrue(o.getClass().getName().equals(Date.class.getName()));
814 }
815 o = Converter.convertString2Value("BlaBla", BigInteger.class);
816 assertNull(o);
817 }
818
819 public void testConvertString2Value2() throws Exception {
820 Object o = Converter.convertString2Value("true", Boolean.class.getName());
821 assertTrue(o.getClass().getName().equals(Boolean.class.getName()));
822 assertTrue( ((Boolean)o).booleanValue() == Boolean.TRUE.booleanValue());
823
824 o = Converter.convertString2Value("true", boolean.class.getName());
825 assertTrue(o.getClass().getName().equals(Boolean.class.getName()));
826 assertTrue( ((Boolean)o).booleanValue() == Boolean.TRUE.booleanValue());
827
828 o = Converter.convertString2Value("3", Integer.class.getName());
829 assertTrue(o.getClass().getName().equals(Integer.class.getName()));
830 assertTrue( ((Integer)o).intValue() == 3);
831
832 o = Converter.convertString2Value("5", int.class.getName());
833 assertTrue(o.getClass().getName().equals(Integer.class.getName()));
834 assertTrue( ((Integer)o).intValue() == 5);
835
836 o = Converter.convertString2Value("2", byte.class.getName());
837 assertTrue(o.getClass().getName().equals(Byte.class.getName()));
838 assertTrue( ((Byte)o).byteValue() == 2);
839
840 o = Converter.convertString2Value("4", short.class.getName());
841 assertTrue(o.getClass().getName().equals(Short.class.getName()));
842 assertTrue( ((Short)o).shortValue() == 4);
843
844 o = Converter.convertString2Value("6", long.class.getName());
845 assertTrue(o.getClass().getName().equals(Long.class.getName()));
846 assertTrue( ((Long)o).longValue() == 6);
847
848 o = Converter.convertString2Value("5.4", double.class.getName());
849 assertTrue(o.getClass().getName().equals(Double.class.getName()));
850 assertTrue( ((Double)o).doubleValue() == 5.4);
851
852 o = Converter.convertString2Value("c", char.class.getName());
853 assertTrue(o.getClass().getName().equals(Character.class.getName()));
854 assertTrue( ((Character)o).charValue() == 'c');
855
856 o = Converter.convertString2Value("5.4", float.class.getName());
857 assertTrue(o.getClass().getName().equals(Float.class.getName()));
858 assertEquals( ((Float)o).floatValue(), 5.4, 0.01);
859
860 o = Converter.convertString2Value(null , float.class);
861 assertNull(o);
862
863 o = Converter.convertString2Value(new Date().toString(), Date.class.getName());
864 assertTrue(o.getClass().getName().equals(Date.class.getName()));
865
866 o = Converter.convertString2Value(new Kunde().toString(), Kunde.class.getName());
867 assertTrue(o.getClass().getName().equals(Kunde.class.getName()));
868
869 }
870
871 public void testConvertStringParams2MethodParams() throws Exception {
872 Vector lvParam = new Vector();
873 lvParam.add(new Integer(5));
874 lvParam.add(new Integer(3));
875 Method lvMethod = Invoker.findMethod(Calculator.class, "add", lvParam);
876
877 Vector lvParam2 = new Vector();
878 lvParam2.add(new String("5"));
879 lvParam2.add(new String("3"));
880 Object o[] = Converter.convertStringParams2MethodParams(lvMethod, lvParam2);
881 assertTrue(o.length == lvParam2.size());
882 assertTrue(o[0].getClass().getName().equals(Integer.class.getName()));
883 assertTrue(o[1].getClass().getName().equals(Integer.class.getName()));
884 assertTrue(o[0].equals(new Integer(5)));
885 assertTrue(o[1].equals(new Integer(3)));
886
887 try {
888 Converter.convertStringParams2MethodParams(null, lvParam2);
889 fail("convertStringParams2MethodParams with method = null must throw a Exception");
890 } catch (Exception e) {
891 assertTrue(true);
892 }
893
894 try {
895 lvParam2.remove(0);
896 Converter.convertStringParams2MethodParams(lvMethod, lvParam2);
897 fail("convertStringParams2MethodParams with must throw a Exception with false parameter size");
898 } catch (Exception e) {
899 assertTrue(true);
900 }
901
902 }
903
904 public void testString2CurrentDate() throws Exception {
905 Date d = new Date();
906 Date d2 = Converter.string2Date(d.toString());
907 assertEquals(d2.toString(), d.toString());
908
909 try {
910 d2 = Converter.string2Date(null);
911 fail("Date euqals null is illegal argument");
912 } catch (Exception e) {
913 assertTrue(true);
914 }
915
916 try {
917 d2 = Converter.string2Date("False Date");
918 fail("Date euqals String: 'False Date' is illegal argument");
919 } catch (Exception e) {
920 assertTrue(true);
921 }
922
923
924 }
925
926 /** Tue Mar 01 20:23:55 CET 2005 - 1109705105302 */
927 public void testString2DateCET() throws Exception {
928 Date d = new Date(1109705105302l);
929 Date d2 = Converter.string2Date(d.toString());
930 assertEquals(d2.toString(), d.toString());
931 }
932
933 /** Sat Oct 01 20:25:34 CEST 2005 -- 1128191134214 */
934 public void testString2DateCEST() throws Exception {
935 Date d = new Date(1128191134214l);
936 Date d2 = Converter.string2Date(d.toString());
937 assertEquals(d2.toString(), d.toString());
938 }
939
940 public void testClassWithoutPackage() throws Exception {
941 String lvString = Converter.getClassWithoutPackage(ServiceManager.class.getName(), true);
942 assertEquals(lvString, "servicemanager");
943 lvString = Converter.getClassWithoutPackage(ServiceManager.class.getName(), false);
944 assertEquals(lvString, "ServiceManager");
945 lvString = Converter.getClassWithoutPackage(null, false);
946 assertNull(lvString);
947 }
948
949 public void testConvertArray() throws Exception {
950 String s[] = new String[] {"a","b","c"};
951 Object o = new Converter().makeSimple(s);
952 assertTrue(o instanceof Vector);
953 Vector v = (Vector) o;
954 assertTrue(v.size() == 3);
955 o = new Converter().makeComplex(o, String[].class);
956 assertTrue(o.getClass().isArray());
957 String array[] = (String[]) o;
958 assertEquals(array.getClass().getComponentType(), String.class);
959 assertTrue(array.length == 3);
960 assertEquals(array[0], "a");
961 assertEquals(array[1], "b");
962 assertEquals(array[2], "c");
963 }
964
965 public void testArrayType_Array() throws Exception {
966 Class lvType = Converter.getArrayType(null);
967 assertEquals(lvType, Object.class);
968 lvType = Converter.getArrayType(new String[0]);
969 assertEquals(lvType, String.class);
970 lvType = Converter.getArrayType(new String[] {"a", "b"});
971 assertEquals(lvType, String.class);
972 lvType = Converter.getArrayType(new Long[] {new Long(1), new Long(3)});
973 assertEquals(lvType, Long.class);
974 lvType = Converter.getArrayType(new Object[] {new Long(1), new Long(3)});
975 assertEquals(lvType, Long.class);
976 lvType = Converter.getArrayType(new Object[] {new Long(1), "c"});
977 assertEquals(lvType, Object.class);
978
979 Vector v = new Vector();
980 lvType = Converter.getArrayType(v);
981 assertEquals(lvType, Object.class);
982
983 v.add(new String());
984 lvType = Converter.getArrayType(v);
985 assertEquals(lvType, String.class);
986
987 Map lvMap = new HashMap();
988 lvType = Converter.getArrayType(lvMap);
989 assertEquals(lvType, Object.class);
990 }
991
992 public void testArrayType_Collection() throws Exception {
993 Vector v = new Vector();
994 v.add("a");
995 v.add("b");
996 Class lvType = Converter.getArrayType(v);
997 assertEquals(lvType, String.class);
998 v = new Vector();
999 v.add(new Long (1));
1000 v.add(new Long (2));
1001 lvType = Converter.getArrayType(v);
1002 assertEquals(lvType, Long.class);
1003 v = new Vector();
1004 v.add(new Long (1));
1005 v.add("b");
1006 lvType = Converter.getArrayType(v);
1007 assertEquals(lvType, Object.class);
1008 }
1009
1010 public void testExtractHashCode() throws Exception {
1011 String lvHashCodeString = null;
1012 assertNull(Converter.extractHashCode(lvHashCodeString));
1013 int lvHashCode = 24306761;
1014 lvHashCodeString = Converter.HASH_CODE_KEY + lvHashCode;
1015 assertNotNull(Converter.extractHashCode(lvHashCodeString));
1016 assertEquals(Converter.extractHashCode(lvHashCodeString), Integer.toString(lvHashCode));
1017
1018 lvHashCodeString = "dummy" + lvHashCode;
1019 assertNull(Converter.extractHashCode(lvHashCodeString));
1020 }
1021
1022 public void testConvertWithComplexMapKeyNotValid() throws Exception {
1023 try {
1024 Node n1 = new Node();
1025 Node n2 = new Node();
1026 n1.getChildrenMap().put(n2, n2);
1027 Converter lvConverter = new Converter();
1028 lvConverter.makeSimple(n1);
1029 fail("Convert must throw Exception by complex Map-Key.");
1030 } catch (Exception e) {
1031 assertTrue(true);
1032 }
1033 }
1034
1035 public void testConvertObjectWithSameHashCode() throws Exception {
1036 SpecialTestClass c1 = new SpecialTestClass("Name1");
1037 SpecialTestClass c2 = new SpecialTestClass("Name2");
1038 SpecialTestClass c3 = new SpecialTestClass("Name3");
1039 c1.getChilds().put(c2.getName(), c2);
1040 c1.getChilds().put(c3.getName(), c3);
1041 Converter lvConverter = new Converter();
1042 Object o = lvConverter.makeSimple(c1);
1043 SpecialTestClass c11 = (SpecialTestClass) lvConverter.makeComplex(o);
1044 assertEquals(c1.getName(), c11.getName());
1045 assertEquals(c1.getChilds().size(), c11.getChilds().size());
1046 assertEquals(c2.getName(), ((SpecialTestClass) c11.getChilds().get(c2.getName())).getName());
1047 assertEquals(c3.getName(), ((SpecialTestClass) c11.getChilds().get(c3.getName())).getName());
1048 }
1049
1050 public void testConvertObjectWithSameHashCodeWithCycle() throws Exception {
1051 SpecialTestClass c1 = new SpecialTestClass("Name1");
1052 SpecialTestClass c2 = new SpecialTestClass("Name2");
1053 SpecialTestClass c3 = new SpecialTestClass("Name3");
1054 c1.getChilds().put(c2.getName(), c2);
1055 c2.getChilds().put(c3.getName(), c3);
1056 c3.getChilds().put(c2.getName(), c2);
1057
1058 Converter lvConverter = new Converter();
1059 Object o = lvConverter.makeSimple(c1);
1060 SpecialTestClass c11 = (SpecialTestClass) lvConverter.makeComplex(o);
1061 assertEquals(c1.getName(), c11.getName());
1062 assertEquals(c1.getChilds().size(), c11.getChilds().size());
1063 SpecialTestClass c22 = (SpecialTestClass) c11.getChilds().get(c2.getName());
1064 SpecialTestClass c33 = (SpecialTestClass) c22.getChilds().get(c3.getName());
1065 assertEquals(c2.getName(), c22.getName());
1066 assertEquals(c3.getName(), c33.getName());
1067 assertEquals(c22.getChilds().get(c3.getName()), c33);
1068 }
1069
1070 public void testIsValideEdge() throws Exception {
1071 boolean isValideEdge = Converter.isValideEdge(null);
1072 assertFalse(isValideEdge);
1073
1074 isValideEdge = Converter.isValideEdge(new String("STRING"));
1075 assertFalse(isValideEdge);
1076 }
1077
1078 public void testConvertClassString2Object() throws Exception {
1079 Object lvResult = Converter.convertClassString2Object(null);
1080 assertNull(lvResult);
1081
1082 lvResult = Converter.convertClassString2Object(int.class.getName());
1083 assertEquals(lvResult, new Integer(0));
1084
1085 lvResult = Converter.convertClassString2Object(short.class.getName());
1086 assertEquals(lvResult, new Short((short) 0));
1087
1088 lvResult = Converter.convertClassString2Object(byte.class.getName());
1089 assertEquals(lvResult, new Byte((byte) 0));
1090
1091 lvResult = Converter.convertClassString2Object(long.class.getName());
1092 assertEquals(lvResult, new Long(0));
1093
1094 lvResult = Converter.convertClassString2Object(double.class.getName());
1095 assertEquals(lvResult, new Double(0));
1096
1097 lvResult = Converter.convertClassString2Object(float.class.getName());
1098 assertEquals(lvResult, new Float(0));
1099
1100 lvResult = Converter.convertClassString2Object(char.class.getName());
1101 assertEquals(lvResult, new Character(' '));
1102
1103 lvResult = Converter.convertClassString2Object(boolean.class.getName());
1104 assertEquals(lvResult, Boolean.TRUE);
1105
1106 lvResult = Converter.convertClassString2Object("[Ljava/lang/String;");
1107 assertNotNull(lvResult);
1108 assertTrue(lvResult instanceof String[]);
1109 assertEquals(((String[])lvResult).length, 0);
1110
1111 lvResult = Converter.convertClassString2Object("[Ljava/lang/String_ERROR;");
1112 assertNull(lvResult);
1113
1114 lvResult = Converter.convertClassString2Object(new String[0].toString());
1115 assertNull(lvResult);
1116
1117 lvResult = Converter.convertClassString2Object(Long.class.getName());
1118 assertEquals(lvResult, new Long(0));
1119
1120 lvResult = Converter.convertClassString2Object(BigInteger.class.getName());
1121 assertEquals(lvResult, new BigInteger("0"));
1122
1123 lvResult = Converter.convertClassString2Object(Date.class.getName());
1124 assertTrue(lvResult instanceof Date);
1125
1126 lvResult = Converter.convertClassString2Object(Float.class.getName());
1127 assertEquals(lvResult, new Float(0));
1128
1129 lvResult = Converter.convertClassString2Object(BigDecimal.class.getName());
1130 assertEquals(lvResult, new BigDecimal("0"));
1131
1132 lvResult = Converter.convertClassString2Object(Kunde.class.getName());
1133 assertTrue(lvResult instanceof Kunde);
1134
1135 lvResult = Converter.convertClassString2Object(Timestamp.class.getName());
1136 assertEquals(lvResult, new Timestamp(0));
1137
1138 Character lvCharacter = (Character) Converter.convertClassString2Object(Character.class.getName());
1139 assertEquals(new Character(' '), lvCharacter);
1140 Boolean lvBoolean = (Boolean) Converter.convertClassString2Object(Boolean.class.getName());
1141 assertEquals(Boolean.TRUE, lvBoolean);
1142 }
1143
1144
1145 public void testByEqualsHashCode() throws Exception {
1146 NodeHashCode1 n11 = new NodeHashCode1("n11", 4);
1147 NodeHashCode1 n12 = new NodeHashCode1("n12", 1);
1148 NodeHashCode2 n21 = new NodeHashCode2("n21", 1);
1149 NodeHashCode2 n22 = new NodeHashCode2("n22", 2);
1150 n11.getChilds().add(n21);
1151 n11.getChilds().add(n22);
1152
1153 n12.getChilds().add(n21);
1154 n12.getChilds().add(n22);
1155
1156 List liste = new ArrayList();
1157 liste.add(n11);
1158 liste.add(n12);
1159 liste.add(n21);
1160 liste.add(n22);
1161
1162 Converter converter = new Converter(0);
1163 Object o = converter.makeSimple(liste);
1164 liste = (List) converter.makeComplex(o);
1165
1166 assertNotNull(liste);
1167 assertEquals(liste.size(), 4);
1168
1169 NodeHashCode1 n1After = (NodeHashCode1) liste.get(0);
1170 assertEquals( n1After.getName(), "n11");
1171 assertEquals( ((NodeHashCode2) n1After.getChilds().get(0)).getName(), "n21");
1172 assertEquals( ((NodeHashCode2) n1After.getChilds().get(1)).getName(), "n22");
1173
1174 NodeHashCode1 n2After = (NodeHashCode1) liste.get(1);
1175 assertEquals( n2After.getName(), "n12");
1176 assertEquals( ((NodeHashCode2) n2After.getChilds().get(0)).getName(), "n21");
1177 assertEquals( ((NodeHashCode2) n2After.getChilds().get(1)).getName(), "n22");
1178
1179 assertEquals( ((NodeHashCode2) liste.get(2)).getName(), "n21");
1180 assertEquals( ((NodeHashCode2) liste.get(3)).getName(), "n22");
1181 }
1182
1183 public void testByEqualsHashCode2() throws Exception {
1184 NodeHashCode1 n11 = new NodeHashCode1("n11", 2);
1185 NodeHashCode1 n12 = new NodeHashCode1("n12", 1);
1186 NodeHashCode2 n21 = new NodeHashCode2("n21", 1);
1187 NodeHashCode2 n22 = new NodeHashCode2("n22", 2);
1188 n11.getChilds().add(n21);
1189 n11.getChilds().add(n22);
1190
1191 n12.getChilds().add(n21);
1192 n12.getChilds().add(n22);
1193
1194 List liste = new ArrayList();
1195 liste.add(n11);
1196 liste.add(n12);
1197 liste.add(n21);
1198 liste.add(n22);
1199
1200 Converter converter = new Converter(0);
1201 Object o = converter.makeSimple(liste);
1202 liste = (List) converter.makeComplex(o);
1203
1204 assertNotNull(liste);
1205 assertEquals(liste.size(), 4);
1206
1207 NodeHashCode1 n1After = (NodeHashCode1) liste.get(0);
1208 assertEquals( n1After.getName(), "n11");
1209 assertEquals( ((NodeHashCode2) n1After.getChilds().get(0)).getName(), "n21");
1210 assertEquals( ((NodeHashCode2) n1After.getChilds().get(1)).getName(), "n22");
1211
1212 NodeHashCode1 n2After = (NodeHashCode1) liste.get(1);
1213 assertEquals( n2After.getName(), "n12");
1214 assertEquals( ((NodeHashCode2) n2After.getChilds().get(0)).getName(), "n21");
1215 assertEquals( ((NodeHashCode2) n2After.getChilds().get(1)).getName(), "n22");
1216
1217 assertEquals( ((NodeHashCode2) liste.get(2)).getName(), "n21");
1218 assertEquals( ((NodeHashCode2) liste.get(3)).getName(), "n22");
1219 }
1220
1221 public void testByEqualsHashCode3() throws Exception {
1222 NodeHashCode1 n11 = new NodeHashCode1("n11", 4);
1223 NodeHashCode1 n12 = new NodeHashCode1("n12", 1);
1224 NodeHashCode2 n21 = new NodeHashCode2("n21", 1);
1225 n11.getChilds().add(n21);
1226 n12.getChilds().add(n21);
1227
1228 List liste = new ArrayList();
1229 liste.add(n11);
1230 liste.add(n12);
1231 liste.add(n21);
1232
1233 Converter converter = new Converter(1);
1234 Object o = converter.makeSimple(liste);
1235 liste = (List) converter.makeComplex(o);
1236
1237 assertNotNull(liste);
1238 assertEquals(liste.size(), 3);
1239
1240 NodeHashCode1 n1After = (NodeHashCode1) liste.get(0);
1241 assertEquals( n1After.getName(), "n11");
1242 assertEquals( ((NodeHashCode2) n1After.getChilds().get(0)).getName(), "n21");
1243
1244 NodeHashCode1 n2After = (NodeHashCode1) liste.get(1);
1245 assertEquals( n2After.getName(), "n12");
1246 assertEquals( ((NodeHashCode2) n2After.getChilds().get(0)).getName(), "n21");
1247
1248 assertEquals( ((NodeHashCode2) liste.get(2)).getName(), "n21");
1249 }
1250
1251
1252 public void testConvertArrayWithNullElement() throws Exception {
1253 String s[] = new String[] {"a", null, "b","c"};
1254 Object o = new Converter().makeSimple(s);
1255 assertTrue(o instanceof Vector);
1256 Vector v = (Vector) o;
1257 assertTrue(v.size() == 3);
1258 o = new Converter().makeComplex(o, String[].class);
1259 assertTrue(o.getClass().isArray());
1260 String array[] = (String[]) o;
1261 assertEquals(array.getClass().getComponentType(), String.class);
1262 assertTrue(array.length == 3);
1263 assertEquals(array[0], "a");
1264 assertEquals(array[1], "b");
1265 assertEquals(array[2], "c");
1266 }
1267
1268 public void testConvertMapWithNullElement() throws Exception {
1269 Map lvMap = new HashMap(2);
1270 lvMap.put("String", "String");
1271 lvMap.put("null", null);
1272 Object result = new Converter().makeSimple(lvMap);
1273 assertTrue(result instanceof Map);
1274 Map lvMapAfter = (Map) result;
1275 assertEquals(lvMapAfter.size(), 1);
1276 }
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304 public void testConverterWithInvokePrivateSetMethod() throws Exception {
1305 Node n = new Node(new Long (97));
1306 n.setName("Node-JUnit");
1307 Converter c = new Converter();
1308 Object o = c.makeSimple(n);
1309 Node nAfter = (Node) c.makeComplex(o);
1310 assertEquals(n.getId(), nAfter.getId());
1311 assertEquals(nAfter.getName(), n.getName());
1312 }
1313
1314 public void testConvertByteArray() throws Exception {
1315 byte b [] = new byte[2];
1316 assertEquals(b[0], 0);
1317 assertEquals(b[1], 0);
1318 byte bAfter[] = new byte[] {5, 6};
1319 assertFalse(bAfter[0] == 0);
1320 assertFalse(bAfter[1] == 0);
1321
1322 Converter c = new Converter();
1323 byte bAfterConvert[] = (byte[]) c.makeSimple(bAfter);
1324 assertEquals(bAfter[0], bAfterConvert[0]);
1325 assertEquals(bAfter[1], bAfterConvert[1]);
1326
1327 byte bAfterConvert2[] = (byte[]) c.makeComplex(bAfterConvert);
1328 assertEquals(bAfterConvert[0], bAfterConvert2[0]);
1329 assertEquals(bAfterConvert[1], bAfterConvert2[1]);
1330 }
1331
1332 public void testConvertMakeCompleyWithInValidMap() throws Exception {
1333 Map map = new HashMap();
1334 map.put("class", "i.am.a.not.valid.Clazz");
1335 Converter c = new Converter();
1336 try {
1337 c.makeComplex(map);
1338 fail("Exception by converter.makeComplex is an Error");
1339 } catch (Exception e) {
1340 assertTrue(true);
1341 }
1342 }
1343
1344 public void testClassWithNoParameterConstructor() throws Exception {
1345 Map map = new HashMap();
1346 map.put("class", ClassWithNoParameterConstructor.class.getName());
1347 Converter c = new Converter();
1348 try {
1349 c.makeComplex(map);
1350 fail("Exception by converter.makeComplex is an Error");
1351 } catch (Exception e) {
1352 assertTrue(true);
1353 }
1354
1355 }
1356
1357 public void testMakeSimpleNull() throws Exception {
1358 Converter lvConverter = new Converter(null);
1359 Object o = lvConverter.makeSimple(null);
1360 assertNull(o);
1361 }
1362
1363 public void testMakeSimpleNullValue() throws Exception {
1364 String lvNullValue = "!!!NullValue!!!";
1365 Converter lvConverter = new Converter(lvNullValue);
1366 Object o = lvConverter.makeSimple(null);
1367 assertNotNull(o);
1368 assertEquals(o, lvNullValue);
1369 }
1370
1371 public void testMakeSimpleComplexNullValue() throws Exception {
1372 String lvNullValue = "---Null-Value--";
1373 Kunde lvKunde = new Kunde("Name");
1374 lvKunde.setVorname(null);
1375 Converter lvConverter = new Converter(lvNullValue);
1376 Object o = lvConverter.makeSimple(lvKunde);
1377 assertNotNull(o);
1378 Map lvMap = (Map) o;
1379 assertEquals(lvMap.get("vorname"), null);
1380 assertEquals(lvMap.get("gehalt"), null);
1381 }
1382
1383 public void testMakeComplexNull() throws Exception {
1384 Converter lvConverter = new Converter(null);
1385 Object o = lvConverter.makeComplex(null);
1386 assertNull(o);
1387 }
1388
1389 public void testMakeComplexNullValue() throws Exception {
1390 String lvNullValue = "!!!NullValue!!!";
1391 Converter lvConverter = new Converter(lvNullValue);
1392 Object o = lvConverter.makeComplex(lvNullValue);
1393 assertNull(o);
1394 }
1395
1396 public void testMakeComplexWithComplexObjectAndNullValue() throws Exception {
1397 String lvNullValue = "---Null-Value--";
1398 Kunde lvKunde = new Kunde("Name");
1399 lvKunde.setVorname(null);
1400 Converter lvConverter = new Converter(lvNullValue);
1401 Object o = lvConverter.makeSimple(lvKunde);
1402 assertNotNull(o);
1403 Object oAfter = lvConverter.makeComplex(o);
1404 assertNotNull(oAfter);
1405 Kunde kAfter = (Kunde) oAfter;
1406 assertEquals(kAfter.getName(), "Name");
1407 assertNull(kAfter.getVorname());
1408 assertNull(kAfter.getGehalt());
1409 }
1410
1411 public void testAllGetterMethod() throws Exception {
1412 Map lvGetterMap = Converter.getAllGetterAndSetterMethod(ProblemNode.class, Converter.GET_METHOD);
1413 assertEquals(7, lvGetterMap.size());
1414 assertNotNull(lvGetterMap.get("class"));
1415 assertNotNull(lvGetterMap.get("id"));
1416
1417 lvGetterMap = Converter.getAllGetterAndSetterMethod(SubProblemNode.class, Converter.GET_METHOD);
1418 assertEquals(8, lvGetterMap.size());
1419 assertNotNull(lvGetterMap.get("name2"));
1420
1421 lvGetterMap = Converter.getAllGetterAndSetterMethod(SubSubProblemNode.class, Converter.GET_METHOD);
1422 assertEquals(14, lvGetterMap.size());
1423 assertNotNull(lvGetterMap.get("date"));
1424 assertNotNull(lvGetterMap.get("privateDate"));
1425
1426 }
1427
1428 public void testAllSetterMethod() throws Exception {
1429 Map lvSetterMap = Converter.getAllGetterAndSetterMethod(ProblemNode.class, Converter.SET_METHOD);
1430 assertEquals(5, lvSetterMap.size());
1431 assertNull(lvSetterMap.get("class"));
1432 assertNotNull(lvSetterMap.get("id"));
1433
1434 lvSetterMap = Converter.getAllGetterAndSetterMethod(SubProblemNode.class, Converter.SET_METHOD);
1435 assertEquals(6, lvSetterMap.size());
1436 assertNotNull(lvSetterMap.get("name2"));
1437
1438 lvSetterMap = Converter.getAllGetterAndSetterMethod(SubSubProblemNode.class, Converter.SET_METHOD);
1439 assertEquals(12, lvSetterMap.size());
1440 assertNotNull(lvSetterMap.get("date"));
1441 assertNotNull(lvSetterMap.get("privateDate"));
1442 }
1443
1444 public void testAllNotEqualsGetterAndSetterAndRemoveThisProperties() throws Exception {
1445 Map lvGetterMap = Converter.getAllGetterAndSetterMethod(ProblemNode.class, Converter.GET_METHOD);
1446 lvGetterMap.remove("class");
1447 Map lvSetterMap = Converter.getAllGetterAndSetterMethod(ProblemNode.class, Converter.SET_METHOD);
1448 assertTrue(lvGetterMap.size() > lvSetterMap.size());
1449 Map lvNewGetterMap = Converter.getAllNotEqualsGetterAndSetterAndRemoveThisProperties(lvGetterMap, lvSetterMap);
1450 assertTrue(lvNewGetterMap.size() == lvSetterMap.size());
1451 }
1452
1453 public void testAllGetterAndSetterMethodInvalideMethodTyp() throws Exception {
1454 Map lvMap = Converter.getAllGetterAndSetterMethod(ProblemNode.class, -99);
1455 assertNotNull(lvMap);
1456 assertEquals(0, lvMap.size());
1457 }
1458 public void testNullValue() throws Exception {
1459 String lvNullValue = "MyTestNullValue";
1460 assertEquals(lvNullValue, new Converter(lvNullValue).getNullValue());
1461
1462 }
1463
1464 public void testInvalideSetGetPropertyName() throws Exception {
1465 Converter lvConverter = new Converter();
1466 try {
1467 lvConverter.makeSimple(new InvalidClass());
1468 fail("Must thrown Exception by invalid property-name!");
1469 } catch (Exception e) {
1470 assertTrue(true);
1471 }
1472 }
1473
1474 /** Resolve Bug: 1488645 */
1475 public void testTimeByDateProperty() throws Exception {
1476 SubSubProblemNode lvNode = new SubSubProblemNode();
1477 Date lvDate = new Date();
1478 Time lvTime = new Time(lvDate.getTime());
1479 lvNode.setDate(lvTime);
1480
1481 Timestamp lvTimestamp = new Timestamp(lvDate.getTime());
1482 lvNode.setDate2(lvTimestamp);
1483
1484 Converter lvConverter = new Converter();
1485 Object lvSimple = lvConverter.makeSimple(lvNode);
1486 SubSubProblemNode lvNodeAfter = (SubSubProblemNode) lvConverter.makeComplex(lvSimple);
1487
1488 assertEquals(lvDate, lvNodeAfter.getDate());
1489 assertEquals(lvDate, lvNodeAfter.getDate2());
1490 }
1491
1492 public void testListWithDoubleInstanceAndNullValue() throws Exception {
1493 Converter lvConverter = new Converter();
1494 List l = new Vector();
1495 Kunde k = new Kunde("Junit-Test-Kunde");
1496 Object lvSimple = lvConverter.makeSimple(k);
1497
1498 l.add(lvSimple);
1499 l.add(null);
1500 l.add(lvSimple);
1501
1502 Object lvComplex = lvConverter.makeComplex(l);
1503
1504 assertNotNull(lvComplex);
1505 assertTrue(lvComplex instanceof List);
1506
1507 assertEquals(2, ((List) lvComplex).size());
1508 }
1509
1510 public void testListWithDoubleInstanceAndNullValue2() throws Exception {
1511 Converter lvConverter = new Converter();
1512 List l = new Vector();
1513 Kunde k = new Kunde("Junit-Test-Kunde");
1514 k.setNullList(new ArrayList());
1515 Object lvSimple = lvConverter.makeSimple(k);
1516
1517 l.add(lvSimple);
1518 l.add(null);
1519 l.add(lvSimple);
1520
1521 Object lvComplex = lvConverter.makeComplex(l);
1522
1523 assertNotNull(lvComplex);
1524 assertTrue(lvComplex instanceof List);
1525
1526 assertEquals(2, ((List) lvComplex).size());
1527 Kunde kAfter0 = (Kunde) ((List) lvComplex).get(0);
1528 assertEquals("Junit-Test-Kunde", kAfter0.getName());
1529 assertNotNull(kAfter0.getNullList());
1530 assertEquals(0, kAfter0.getNullList().size());
1531 }
1532
1533 public void testCreateDefaultValueForPrimitiveClass() throws Exception {
1534 Object lvResult = Converter.createDefaultValueForPrimitiveClass(boolean.class);
1535 assertEquals(Boolean.FALSE, lvResult);
1536
1537 lvResult = Converter.createDefaultValueForPrimitiveClass(short.class);
1538 assertEquals(new Short((short) 0), lvResult);
1539
1540 lvResult = Converter.createDefaultValueForPrimitiveClass(byte.class);
1541 assertEquals(new Byte((byte) 0), lvResult);
1542
1543 lvResult = Converter.createDefaultValueForPrimitiveClass(int.class);
1544 assertEquals(new Integer(0), lvResult);
1545
1546 lvResult = Converter.createDefaultValueForPrimitiveClass(long.class);
1547 assertEquals(new Long(0), lvResult);
1548
1549 lvResult = Converter.createDefaultValueForPrimitiveClass(double.class);
1550 assertEquals(new Double(0), lvResult);
1551
1552 lvResult = Converter.createDefaultValueForPrimitiveClass(float.class);
1553 assertEquals(new Float(0), lvResult);
1554
1555 lvResult = Converter.createDefaultValueForPrimitiveClass(char.class);
1556 assertEquals(new Character(' '), lvResult);
1557
1558 lvResult = Converter.createDefaultValueForPrimitiveClass(Class.class);
1559 assertNull(lvResult);
1560 }
1561
1562 public void testMapInArrayByMakeComplex() throws Exception {
1563 Converter lvConverter = new Converter();
1564 Map lvPrimitiveMap = (Map) lvConverter.makeSimple(Primitive.createPrimitiveExample());
1565 assertNotNull(lvPrimitiveMap);
1566 Integer lvIntValue = (Integer) lvPrimitiveMap.get("intValue");
1567 assertEquals(3, lvIntValue.intValue());
1568
1569 Object lvPrimitiveArray[] = (Object[]) lvConverter.makeComplex(new Object [] { lvPrimitiveMap });
1570 assertEquals(1, lvPrimitiveArray.length);
1571 assertEquals(Primitive.createPrimitiveExample(), lvPrimitiveArray[0]);
1572 }
1573
1574 public void testSimpleStringMap() throws Exception {
1575 Converter lvConverter = new Converter();
1576 lvConverter.setWithSimpleKeyMapper(true);
1577
1578 Map lvMap = new Hashtable();
1579 lvMap.put("1", "1");
1580 lvMap.put("5", "5");
1581 lvMap.put("3", "3");
1582 lvMap.put("A", "A");
1583 lvMap.put("1", "1");
1584
1585 Object lvSimple = lvConverter.makeSimple(lvMap);
1586 assertTrue(lvSimple instanceof Map);
1587 assertEquals(4, ((Map) lvSimple).size());
1588
1589 Object lvComplex = lvConverter.makeComplex(lvSimple);
1590 assertTrue(lvComplex instanceof Map);
1591 Map lvMapAfter = (Map) lvComplex;
1592 assertEquals(4, ((Map) lvComplex).size());
1593 assertEquals("1", lvMapAfter.get("1"));
1594 assertEquals("5", lvMapAfter.get("5"));
1595 assertEquals("A", lvMapAfter.get("A"));
1596 assertEquals("3", lvMapAfter.get("3"));
1597 }
1598
1599 public void testConvertObjectWithEqualsAndHashCodeValue() throws Exception {
1600 ProblemNode n = new ProblemNode("abc", new Long(3));
1601 n.setAspecialTestClass(new SpecialTestClass("AU1"));
1602 n.setVspecialTestClass(new SpecialTestClass("AU1"));
1603
1604 Kunde k1 = new Kunde("k1");
1605 k1.setAktuellerStatus(new Status("AU1"));
1606 k1.setVorgaengerStatus(new Status("AU1"));
1607 n.getSets().add(k1);
1608
1609 Converter c = new Converter();
1610 Object o = c.makeSimple(n);
1611 ProblemNode nAfter = (ProblemNode) c.makeComplex(o);
1612 assertNotNull(nAfter);
1613 assertEquals(nAfter.getName(), "abc");
1614 assertEquals(new SpecialTestClass("AU1"), nAfter.getAspecialTestClass());
1615 assertEquals(new SpecialTestClass("AU1"), nAfter.getVspecialTestClass());
1616 assertSame(nAfter.getAspecialTestClass(), nAfter.getVspecialTestClass());
1617
1618 assertEquals(1, nAfter.getSets().size());
1619 Kunde kAfter = (Kunde) nAfter.getSets().iterator().next();
1620 assertEquals("k1", kAfter.getName());
1621 assertEquals(new Status("AU1"), kAfter.getAktuellerStatus());
1622 assertEquals(new Status("AU1"), kAfter.getVorgaengerStatus());
1623 assertSame(kAfter.getAktuellerStatus(), kAfter.getVorgaengerStatus());
1624 }
1625
1626 public void testTwoMethodWithTheSameDateValue() throws Exception {
1627 Kunde k1 = new Kunde("k1");
1628 Date lvDate = new Date();
1629 k1.setDate(lvDate);
1630 k1.setDate2(lvDate);
1631
1632 Converter c = new Converter();
1633 Object o = c.makeSimple(k1);
1634 Kunde kAfter = (Kunde) c.makeComplex(o);
1635 assertEquals(lvDate, kAfter.getDate());
1636 assertEquals(lvDate, kAfter.getDate2());
1637 }
1638
1639 public void testTheFirstLetterByGetAndSetIs() throws Exception {
1640 Kunde k1 = new Kunde("k1");
1641 Date lvDate = new Date();
1642 k1.setdate3(lvDate);
1643
1644 Converter c = new Converter();
1645 Object o = c.makeSimple(k1);
1646 Kunde kAfter = (Kunde) c.makeComplex(o);
1647 assertEquals(lvDate, kAfter.getdate3());
1648 }
1649
1650 public void testEmptyLists() throws Exception {
1651 Kunde k1 = new Kunde("k1");
1652
1653 Converter c = new Converter();
1654 Object o = c.makeSimple(k1);
1655 Kunde kAfter = (Kunde) c.makeComplex(o);
1656
1657 assertNotNull(kAfter);
1658 assertEquals("k1", kAfter.getName());
1659 assertNotNull(kAfter.getCars());
1660 assertNotNull(kAfter.getAdressen());
1661 assertEquals(0, kAfter.getCars().size());
1662 assertEquals(0, kAfter.getAdressen().size());
1663 }
1664
1665 public void testEqualsEmptyLists() throws Exception {
1666 Kunde k1 = new Kunde("k1");
1667
1668 Converter c = new Converter();
1669 Object o = c.makeSimple(k1);
1670 Kunde kAfter = (Kunde) c.makeComplex(o);
1671
1672 assertNotNull(kAfter);
1673 assertNotNull(kAfter.getCollection());
1674 assertNotNull(kAfter.getAdressen());
1675 assertEquals(0, kAfter.getCollection().size());
1676 assertEquals(0, kAfter.getAdressen().size());
1677 }
1678
1679 public void testEqualsNullLists() throws Exception {
1680 Kunde k1 = new Kunde("k1");
1681
1682 Converter c = new Converter();
1683 Object o = c.makeSimple(k1);
1684 Kunde kAfter = (Kunde) c.makeComplex(o);
1685
1686 assertNotNull(kAfter);
1687 assertNull(kAfter.getNullList());
1688
1689 assertNotNull(kAfter.getAdressen());
1690 assertEquals(0, kAfter.getAdressen().size());
1691 }
1692
1693
1694 public void testEqualsEmptySetsWith() throws Exception {
1695 Kunde k1 = new Kunde("k1");
1696
1697 Converter c = new Converter();
1698 Object o = c.makeSimple(k1);
1699 Kunde kAfter = (Kunde) c.makeComplex(o);
1700
1701 assertNotNull(kAfter);
1702 assertNotNull(kAfter.getSets());
1703 assertNotNull(kAfter.getCars());
1704 assertEquals(0, kAfter.getSets().size());
1705 assertEquals(0, kAfter.getCars().size());
1706 }
1707
1708 public void testEqualsEmptyMapsWith() throws Exception {
1709 Kunde k1 = new Kunde("k1");
1710
1711 Converter c = new Converter();
1712 Object o = c.makeSimple(k1);
1713 Kunde kAfter = (Kunde) c.makeComplex(o);
1714
1715 assertNotNull(kAfter);
1716 assertNotNull(kAfter.getMap1());
1717 assertNotNull(kAfter.getMap2());
1718 assertEquals(0, kAfter.getMap1().size());
1719 assertEquals(0, kAfter.getMap2().size());
1720 }
1721
1722 public void testNoObjectFoundForHashCodeByMakeComplex() throws Exception {
1723 Kunde k = new Kunde("Test-Kunde");
1724 Adresse a = new Adresse();
1725 a.setOrt("Hier");
1726 k.getAdressen().add(a);
1727 Map lvMap = new Hashtable();
1728 lvMap.put("ADRESSE_KEY", a);
1729 lvMap.put("KUNDE_KEY", k);
1730
1731 try {
1732 Converter lvConverter = new Converter();
1733 Object lvSimple = lvConverter.makeSimple(lvMap);
1734 lvConverter.makeComplex(lvSimple);
1735 fail("Must throw InvocationException. No object found for HashCode.");
1736 } catch (InvocationException e) {
1737 assertTrue(true);
1738 }
1739 }
1740
1741 public void testNoObjectFoundForHashCodeByMakeComplexInCollection() throws Exception {
1742 Kunde k = new Kunde("Test-Kunde");
1743 Adresse a = new Adresse();
1744 a.setOrt("Hier");
1745 k.getAdressen().add(a);
1746 Map lvMap = new Hashtable();
1747 Collection c = new ArrayList();
1748 c.add(a);
1749
1750 lvMap.put("ADRESSE_KEY", c);
1751 lvMap.put("KUNDE_KEY", k);
1752
1753 try {
1754 Converter lvConverter = new Converter();
1755 Object lvSimple = lvConverter.makeSimple(lvMap);
1756 lvConverter.makeComplex(lvSimple);
1757 fail("Must throw InvocationException. No object found for HashCode.");
1758 } catch (InvocationException e) {
1759 assertTrue(true);
1760 }
1761 }
1762
1763 public void testNoObjectFoundForHashCodeByMakeComplexInArray() throws Exception {
1764 Kunde k = new Kunde("Test-Kunde");
1765 Adresse a = new Adresse();
1766 a.setOrt("Hier");
1767 Adresse ar[] = new Adresse[1];
1768 ar[0] = a;
1769 k.setAdresseArray(ar);
1770
1771 Map lvMap = new Hashtable();
1772 lvMap.put("KEY_1", a);
1773 lvMap.put("KEY_2", k);
1774
1775
1776 Converter lvConverter = new Converter();
1777 lvConverter.setWithSimpleKeyMapper(true);
1778
1779 Object lvSimple = lvConverter.makeSimple(lvMap);
1780
1781 assertNotNull( ((Map) lvSimple).get("1" + DELIMITER + "KEY_2"));
1782 assertNotNull( ((Map) lvSimple).get("2" + DELIMITER + "KEY_1"));
1783
1784 Object lvComplex = lvConverter.makeComplex(lvSimple);
1785
1786 assertNotNull(lvComplex);
1787 assertTrue(lvComplex instanceof Map);
1788 Map lvMapAfter = (Map) lvComplex;
1789 assertEquals(2, lvMapAfter.size());
1790 Adresse aAfter = (Adresse) lvMapAfter.get("KEY_1");
1791 Kunde kAfter = (Kunde) lvMapAfter.get("KEY_2");
1792 assertEquals("Hier", aAfter.getOrt());
1793 assertEquals("Test-Kunde", kAfter.getName());
1794 assertEquals(1, kAfter.getAdresseArray().length);
1795 assertEquals(aAfter, kAfter.getAdresseArray()[0]);
1796 }
1797
1798 public void testNoObjectFoundForHashCodeByMakeComplexInArrayWithException() throws Exception {
1799 Adresse a = new Adresse();
1800 a.setOrt("Hier");
1801 Adresse ar[] = new Adresse[2];
1802 ar[0] = a;
1803 ar[1] = a;
1804
1805 Converter lvConverter = new Converter();
1806 Object lvSimple = lvConverter.makeSimple(ar);
1807
1808 List l = new Vector();
1809
1810 l.add(((List) lvSimple).get(1));
1811 l.add(((List) lvSimple).get(0));
1812
1813 try {
1814 lvConverter.makeComplex(l, ar.getClass());
1815 fail("Invalid order of the Array.");
1816 } catch (Exception e) {
1817 assertTrue(true);
1818 }
1819 }
1820
1821 public void testNoObjectFoundForHashCodeByMakeComplexInArray_KeyOrderChange() throws Exception {
1822 Kunde k = new Kunde("Test-Kunde");
1823 Adresse a = new Adresse();
1824 a.setOrt("Hier");
1825 Adresse ar[] = new Adresse[1];
1826 ar[0] = a;
1827 k.setAdresseArray(ar);
1828
1829 Map lvMap = new Hashtable();
1830 lvMap.put("KEY_5", a);
1831 lvMap.put("KEY_2", k);
1832
1833
1834 Converter lvConverter = new Converter();
1835 lvConverter.setWithSimpleKeyMapper(true);
1836
1837 Object lvSimple = lvConverter.makeSimple(lvMap);
1838 assertNotNull( ((Map) lvSimple).get("1" + DELIMITER + "KEY_5"));
1839 assertNotNull( ((Map) lvSimple).get("2" + DELIMITER + "KEY_2"));
1840
1841 Object lvComplex = lvConverter.makeComplex(lvSimple);
1842
1843 assertNotNull(lvComplex);
1844 assertTrue(lvComplex instanceof Map);
1845 Map lvMapAfter = (Map) lvComplex;
1846 assertEquals(2, lvMapAfter.size());
1847 Adresse aAfter = (Adresse) lvMapAfter.get("KEY_5");
1848 Kunde kAfter = (Kunde) lvMapAfter.get("KEY_2");
1849 assertEquals("Hier", aAfter.getOrt());
1850 assertEquals("Test-Kunde", kAfter.getName());
1851 assertEquals(1, kAfter.getAdresseArray().length);
1852 assertEquals(aAfter, kAfter.getAdresseArray()[0]);
1853 }
1854
1855
1856 public void testObjectFoundForHashCodeByMakeComplex() throws Exception {
1857 Kunde k = new Kunde("Test-Kunde");
1858 Adresse a = new Adresse();
1859 a.setOrt("Hier");
1860 k.getAdressen().add(a);
1861 Map lvMap = new Hashtable();
1862 lvMap.put("ADRESSE_KEY", a);
1863 lvMap.put("KUNDE_KEY", k);
1864
1865 Converter lvConverter = new Converter();
1866 lvConverter.setWithSimpleKeyMapper(true);
1867 Object lvSimple = lvConverter.makeSimple(lvMap);
1868 Object lvComplex = lvConverter.makeComplex(lvSimple);
1869 assertNotNull(lvComplex);
1870 assertTrue(lvComplex instanceof Map);
1871 Map lvMapAfter = (Map) lvComplex;
1872 Object lvAdrAfter = lvMapAfter.get("ADRESSE_KEY");
1873 assertTrue(lvAdrAfter instanceof Adresse);
1874 assertEquals("Hier", ((Adresse) lvAdrAfter).getOrt());
1875 Object lvKundeAfter = lvMapAfter.get("KUNDE_KEY");
1876 assertTrue(lvKundeAfter instanceof Kunde);
1877 assertEquals("Test-Kunde", ((Kunde) lvKundeAfter).getName());
1878 }
1879
1880 public void testObjectFoundForHashCodeByMakeComplex2() throws Exception {
1881 Adresse a = new Adresse();
1882 a.setOrt("Hier");
1883 Kunde k = new Kunde("Test-Kunde");
1884 k.getAdressen().add(a);
1885
1886 Map lvMap = new Hashtable();
1887 lvMap.put("ADRESSE_KEY_3", a);
1888 lvMap.put("ADRESSE_KEY_2", a);
1889 lvMap.put("ADRESSE_KEY_1", a);
1890 lvMap.put("ADRESSE_KEY_0", k);
1891
1892 Converter lvConverter = new Converter();
1893 assertFalse(lvConverter.getWithSimpleKeyMapper());
1894
1895 lvConverter.setWithSimpleKeyMapper(true);
1896 Object lvSimple = lvConverter.makeSimple(lvMap);
1897 Object lvComplex = lvConverter.makeComplex(lvSimple);
1898 assertNotNull(lvComplex);
1899 assertTrue(lvComplex instanceof Map);
1900 Map lvMapAfter = (Map) lvComplex;
1901 assertEquals(4, lvMapAfter.size());
1902
1903 Object lvKundeAfter = lvMapAfter.get("ADRESSE_KEY_0");
1904 assertTrue(lvKundeAfter instanceof Kunde);
1905 assertEquals("Test-Kunde", ((Kunde) lvKundeAfter).getName());
1906
1907 Object lvAdrAfter1 = lvMapAfter.get("ADRESSE_KEY_1");
1908 assertTrue(lvAdrAfter1 instanceof Adresse);
1909 assertEquals("Hier", ((Adresse) lvAdrAfter1).getOrt());
1910
1911 Object lvAdrAfter2 = lvMapAfter.get("ADRESSE_KEY_2");
1912 assertTrue(lvAdrAfter2 instanceof Adresse);
1913 assertEquals("Hier", ((Adresse) lvAdrAfter2).getOrt());
1914
1915 Object lvAdrAfter3 = lvMapAfter.get("ADRESSE_KEY_3");
1916 assertTrue(lvAdrAfter3 instanceof Adresse);
1917 assertEquals("Hier", ((Adresse) lvAdrAfter3).getOrt());
1918
1919 assertTrue(lvConverter.getWithSimpleKeyMapper());
1920 }
1921
1922 public void testMakeSimpleAndComplexArrayWithSameObjects() throws Exception {
1923 Converter lvConverter = new Converter();
1924
1925 Adresse a = new Adresse();
1926 a.setOrt("Hier");
1927 Object lvArray = new Object[] {a, a, a};
1928 Object lvSimple = lvConverter.makeSimple(lvArray);
1929 Object lvComplex = lvConverter.makeComplex(lvSimple, new Object[0].getClass(), Adresse.class);
1930 assertTrue(lvComplex.getClass().isArray());
1931 Object lvArrayAfter[] = (Object[]) lvComplex;
1932 assertEquals(3, lvArrayAfter.length);
1933 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[0]).getOrt());
1934 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[1]).getOrt());
1935 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[2]).getOrt());
1936 }
1937
1938 public void testMakeSimpleAndComplexArrayWithSameObjectsWithNullValue() throws Exception {
1939 Converter lvConverter = new Converter();
1940
1941 Adresse a = new Adresse();
1942 a.setOrt("Hier");
1943 Object lvArray = new Object[] {a, null, a};
1944 Object lvSimple = lvConverter.makeSimple(lvArray);
1945 Object lvComplex = lvConverter.makeComplex(lvSimple, new Object[0].getClass(), Adresse.class);
1946 assertTrue(lvComplex.getClass().isArray());
1947 Object lvArrayAfter[] = (Object[]) lvComplex;
1948 assertEquals(2, lvArrayAfter.length);
1949 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[0]).getOrt());
1950 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[1]).getOrt());
1951 }
1952
1953 public void testMakeSimpleAndComplexArrayWithSameObjectsWithNullValue2() throws Exception {
1954 Converter lvConverter = new Converter("!--MyNullValue--!");
1955
1956 Adresse a = new Adresse();
1957 a.setOrt("Hier");
1958 Object lvArray = new Object[] {a, null, a};
1959 Object lvSimple = lvConverter.makeSimple(lvArray);
1960 Object lvComplex = lvConverter.makeComplex(lvSimple, new Object[0].getClass(), Adresse.class);
1961 assertTrue(lvComplex.getClass().isArray());
1962 Object lvArrayAfter[] = (Object[]) lvComplex;
1963 assertEquals(3, lvArrayAfter.length);
1964 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[0]).getOrt());
1965 assertNull(lvArrayAfter[1]);
1966 assertEquals(a.getOrt(), ((Adresse) lvArrayAfter[2]).getOrt());
1967 }
1968
1969 public void testMakeComplexMapAsArray() throws Exception {
1970 Map lvKunde = new Hashtable();
1971 lvKunde.put("class", Kunde.class.getName());
1972 lvKunde.put("name", "ICH");
1973 Converter lvConverter = new Converter();
1974 Object o = lvConverter.makeComplex(lvKunde, new Object[0].getClass());
1975 assertNotNull(o);
1976 assertTrue(o instanceof Kunde);
1977 Kunde lvKundeAfter = (Kunde) o;
1978 assertEquals("ICH", lvKundeAfter.getName());
1979 }
1980
1981 public void testUniqueId() throws Exception {
1982 Converter lvConverter = new Converter();
1983 List l = new Vector();
1984 NodeHashCode1 n1 = new NodeHashCode1("n1", 1);
1985 NodeHashCode2 n2 = new NodeHashCode2("n2", 1);
1986 NodeHashCode3 n3 = new NodeHashCode3("n3", 1);
1987 NodeHashCode3 n32 = new NodeHashCode3("n32", 1);
1988 l.add(n1);
1989 l.add(n2);
1990 l.add(n3);
1991 l.add(n32);
1992 Object lvSimple = lvConverter.makeSimple(l);
1993 Object lvComplex = lvConverter.makeComplex(lvSimple);
1994 assertNotNull(lvComplex);
1995 assertTrue(lvComplex instanceof List);
1996 List lAfter = (List) lvComplex;
1997 assertEquals(4, lAfter.size());
1998 assertEquals(n1.getName(), ((NodeHashCode1)lAfter.get(0)).getName());
1999 assertEquals(0, ((NodeHashCode1)lAfter.get(0)).hashCode());
2000
2001 assertEquals(n2.getName(), ((NodeHashCode2)lAfter.get(1)).getName());
2002 assertEquals(0, ((NodeHashCode2)lAfter.get(1)).hashCode());
2003
2004 assertEquals(n3.getName(), ((NodeHashCode3)lAfter.get(2)).getName());
2005 assertEquals(0, ((NodeHashCode3)lAfter.get(2)).hashCode());
2006
2007 assertEquals(n32.getName(), ((NodeHashCode3)lAfter.get(3)).getName());
2008 assertEquals(0, ((NodeHashCode3)lAfter.get(3)).hashCode());
2009 }
2010
2011 public void testMakeSimpleTwice() throws Exception {
2012 Kunde k = new Kunde("Test-Kunde");
2013 k.setDate(new Date());
2014 k.setVorname("Vorname");
2015
2016 Converter lvConverter = new Converter();
2017 Object lvSimple = lvConverter.makeSimple(k);
2018 Object lvSimple2 = lvConverter.makeSimple(lvSimple);
2019
2020 assertEquals(lvSimple, lvSimple2);
2021 }
2022
2023 public void testMakeSimpleTwice_2() throws Exception {
2024 Kunde k = new Kunde("Test-Kunde");
2025 k.setDate(new Date());
2026 k.setVorname("Vorname");
2027 Adresse a = new Adresse();
2028 a.setOrt("Hier");
2029 List l = new ArrayList();
2030 l.add(a);
2031 k.setAdressen(l);
2032
2033 Converter lvConverter = new Converter();
2034 Object lvSimple = lvConverter.makeSimple(k);
2035 Object lvSimple2 = lvConverter.makeSimple(lvSimple);
2036
2037 assertEquals(lvSimple, lvSimple2);
2038 }
2039
2040
2041 public void testMakeSimpleThreeAndBack() throws Exception {
2042 Car lvCar = new Car();
2043 lvCar.setName("Ferrari");
2044
2045 Converter lvConverter = new Converter();
2046 lvConverter.setWithSimpleKeyMapper(true);
2047 Object lvSimple = lvConverter.makeSimple(lvCar);
2048 Object lvSimple2 = lvConverter.makeSimple(lvSimple);
2049 Object lvSimple3 = lvConverter.makeSimple(lvSimple);
2050 assertFalse(lvSimple.equals(lvSimple3));
2051 assertEquals(lvSimple2, lvSimple3);
2052
2053 Object lvComplex = lvConverter.makeComplex(lvSimple);
2054 assertTrue(lvComplex instanceof Car);
2055 assertEquals("Ferrari", ((Car) lvComplex).getName());
2056
2057 Object lvComplex2 = lvConverter.makeComplex(lvSimple2);
2058 assertTrue(lvComplex2 instanceof Map);
2059 assertEquals(Car.class.getName(), ((Map) lvComplex2).get("class"));
2060
2061 lvComplex2 = lvConverter.makeComplex(lvComplex2);
2062 assertTrue(lvComplex2 instanceof Car);
2063 assertEquals("Ferrari", ((Car) lvComplex2).getName());
2064 }
2065
2066 public void testConvertJavaUtilProperties() throws Exception {
2067 Converter lvConverter = new Converter();
2068 lvConverter.setWithSimpleKeyMapper(true);
2069
2070 Properties lvProperties = new Properties();
2071 Object lvSimple = lvConverter.makeSimple(lvProperties);
2072 Object lvComplex = lvConverter.makeComplex(lvSimple);
2073 assertNotNull(lvComplex);
2074 assertTrue(lvComplex instanceof Hashtable);
2075 }
2076
2077 public void testConvertJavaUtilPropertiesAsClassProperty() throws Exception {
2078 Converter lvConverter = new Converter();
2079 lvConverter.setWithSimpleKeyMapper(true);
2080
2081 Properties lvProperties = new Properties();
2082 Car lvCar = new Car();
2083 lvCar.setName("BMW");
2084 lvCar.setProperties(lvProperties);
2085
2086 Object lvSimple = lvConverter.makeSimple(lvCar);
2087 Object lvComplex = lvConverter.makeComplex(lvSimple);
2088 assertNotNull(lvComplex);
2089 assertTrue(lvComplex instanceof Car);
2090 Car lvCarAfter = (Car) lvComplex;
2091 assertEquals(new Properties(), lvCarAfter.getProperties());
2092 }
2093
2094 public void testConvertJavaUtilPropertiesAsClassProperty_2() throws Exception {
2095 Converter lvConverter = new Converter();
2096 lvConverter.setWithSimpleKeyMapper(true);
2097
2098 Properties lvProperties = new Properties();
2099 lvProperties.put("aa", "bb");
2100 Car lvCar = new Car();
2101 lvCar.setName("BMW");
2102 lvCar.setProperties(lvProperties);
2103
2104 Object lvSimple = lvConverter.makeSimple(lvCar);
2105 Object lvComplex = lvConverter.makeComplex(lvSimple);
2106 assertNotNull(lvComplex);
2107 assertTrue(lvComplex instanceof Car);
2108 Car lvCarAfter = (Car) lvComplex;
2109 assertNotNull(lvCarAfter.getProperties());
2110 assertEquals(1, lvCarAfter.getProperties().size());
2111 assertEquals("bb", lvCarAfter.getProperties().getProperty("aa"));
2112 }
2113
2114 public void testBeanWithGetterOfTypeObjectAsList() throws Exception {
2115 Status lvStatus = new Status("MyStatus");
2116 List lvList = new ArrayList();
2117 lvList.add("String");
2118 lvStatus.setResult(lvList);
2119
2120 Converter lvConverter = new Converter();
2121 Object lvResult = lvConverter.makeSimple(lvStatus);
2122 Map lvMap = (Map) lvResult;
2123 List lvListAfter = new Vector();
2124 lvListAfter.add("String");
2125 assertEquals(lvListAfter, lvMap.get("result"));
2126
2127
2128 lvResult = lvConverter.makeComplex(lvResult);
2129 Status lvStatusAfter = (Status) lvResult;
2130 assertEquals(lvListAfter, lvStatusAfter.getResult());
2131 }
2132
2133 public void testBeanWithGetterOfTypeObjectAsMap() throws Exception {
2134 Status lvStatus = new Status("MyStatus");
2135 Map lvMap = new HashMap();
2136 lvMap.put("Key", "Value");
2137 lvStatus.setResult(lvMap);
2138
2139 Converter lvConverter = new Converter();
2140 Object lvResult = lvConverter.makeSimple(lvStatus);
2141 Map lvMapSimple = (Map) lvResult;
2142 Map lvMapAfter = new Hashtable();
2143 lvMapAfter.put("Key", "Value");
2144 assertEquals(lvMapAfter, lvMapSimple.get("result"));
2145
2146
2147 lvResult = lvConverter.makeComplex(lvResult);
2148 Status lvStatusAfter = (Status) lvResult;
2149 assertEquals(lvMapAfter, lvStatusAfter.getResult());
2150 }
2151
2152 public void testBeanWithGetterOfTypeObjectAsString() throws Exception {
2153 Status lvStatus = new Status("MyStatus");
2154 lvStatus.setResult("Result");
2155
2156 Converter lvConverter = new Converter();
2157 Object lvResult = lvConverter.makeSimple(lvStatus);
2158 Map lvMapSimple = (Map) lvResult;
2159 assertEquals("Result", lvMapSimple.get("result"));
2160
2161
2162 lvResult = lvConverter.makeComplex(lvResult);
2163 Status lvStatusAfter = (Status) lvResult;
2164 assertEquals("Result", lvStatusAfter.getResult());
2165 }
2166
2167 public void testBeanWithGetterOfTypeObjectAsLong() throws Exception {
2168 Status lvStatus = new Status("MyStatus");
2169 lvStatus.setResult(new Long("4711"));
2170
2171 Converter lvConverter = new Converter();
2172 Object lvResult = lvConverter.makeSimple(lvStatus);
2173 Map lvMapSimple = (Map) lvResult;
2174 assertEquals(new Integer("4711"), lvMapSimple.get("result"));
2175
2176
2177 lvResult = lvConverter.makeComplex(lvResult);
2178 Status lvStatusAfter = (Status) lvResult;
2179 assertEquals(new Integer("4711"), lvStatusAfter.getResult());
2180 }
2181
2182 public void testSameEmptyListsOnTheSameBean() throws Exception {
2183 Converter lvConverter = new Converter("NULL!!!!jhgfjhvjhdgfkjhgfdhjfdgfdjgh");
2184 DataTransferObject lvDataTransferObject = new DataTransferObject();
2185 LinkedList lvLinkedList = new LinkedList();
2186 lvDataTransferObject.setReturnObject(lvLinkedList);
2187 lvDataTransferObject.setParams(lvLinkedList);
2188 lvDataTransferObject.setParamtypes(null);
2189 Object lvSimple = lvConverter.makeSimple(lvDataTransferObject);
2190 Object lvComplex = lvConverter.makeComplex(lvSimple);
2191 DataTransferObject lvDataTransferObject2 = (DataTransferObject)lvComplex;
2192 assertNotNull(lvDataTransferObject2.getReturnObject());
2193 assertEquals(new Vector(), lvDataTransferObject2.getReturnObject());
2194 }
2195
2196 public void testDifferentEmptyListsOnTheSameBean() throws Exception {
2197 Converter lvConverter = new Converter("NULL!!!!jhgfjhvjhdgfkjhgfdhjfdgfdjgh");
2198 DataTransferObject lvDataTransferObject = new DataTransferObject();
2199 lvDataTransferObject.setReturnObject(new LinkedList());
2200 lvDataTransferObject.setParams(new LinkedList());
2201 lvDataTransferObject.setParamtypes(null);
2202 Object lvSimple = lvConverter.makeSimple(lvDataTransferObject);
2203 Object lvComplex = lvConverter.makeComplex(lvSimple);
2204 DataTransferObject lvDataTransferObject2 = (DataTransferObject)lvComplex;
2205 assertNotNull(lvDataTransferObject2.getReturnObject());
2206 assertEquals(new Vector(), lvDataTransferObject2.getReturnObject());
2207 }
2208
2209 public void testSameNotEmptyListsOnTheSameBean() throws Exception {
2210 Converter lvConverter = new Converter("NULL!!!!jhgfjhvjhdgfkjhgfdhjfdgfdjgh");
2211 DataTransferObject lvDataTransferObject = new DataTransferObject();
2212 LinkedList lvLinkedList = new LinkedList();
2213 lvLinkedList.add("MyString");
2214 lvDataTransferObject.setReturnObject(lvLinkedList);
2215 lvDataTransferObject.setParams(lvLinkedList);
2216 lvDataTransferObject.setParamtypes(null);
2217 Object lvSimple = lvConverter.makeSimple(lvDataTransferObject);
2218 Object lvComplex = lvConverter.makeComplex(lvSimple);
2219 DataTransferObject lvDataTransferObject2 = (DataTransferObject)lvComplex;
2220 assertNotNull(lvDataTransferObject2.getReturnObject());
2221
2222 Vector v = new Vector();
2223 v.add("MyString");
2224 assertEquals(v, lvDataTransferObject2.getReturnObject());
2225 }
2226
2227 public void testListWithNullValue() throws Exception {
2228 Converter lvConverter = new Converter();
2229 List l = new ArrayList();
2230 l.add("String 1");
2231 l.add(null);
2232 l.add("String 2");
2233
2234 Object lvSimple = lvConverter.makeSimple(l);
2235 Object lvComplex = lvConverter.makeComplex(lvSimple);
2236 List lAfter = (List) lvComplex;
2237 assertEquals(l.size() - 1, lAfter.size());
2238
2239 lvConverter.setNullValue("--Null--Value--");
2240 lvSimple = lvConverter.makeSimple(l);
2241 lvComplex = lvConverter.makeComplex(lvSimple);
2242 lAfter = (List) lvComplex;
2243 assertEquals(l.size(), lAfter.size());
2244 }
2245
2246 public void testSimpleLongValueByObjectProperty() throws Exception {
2247 Converter lvConverter = new Converter();
2248 DataTransferObject lvDataTransferObject = new DataTransferObject();
2249 lvDataTransferObject.setReturnObject(new Long("4711"));
2250 Object lvSimple = lvConverter.makeSimple(lvDataTransferObject);
2251 Object lvComplex = lvConverter.makeComplex(lvSimple);
2252 assertNotNull(lvComplex);
2253 DataTransferObject lvDataTransferObjectAfter = (DataTransferObject) lvComplex;
2254 assertEquals(new Integer("4711"), lvDataTransferObjectAfter.getReturnObject());
2255 }
2256 }