KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > openmbean > TabularDataSupportTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.openmbean;
9
10 import java.io.ByteArrayInputStream;
11 import java.io.ByteArrayOutputStream;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.Set;
19
20 import javax.management.openmbean.CompositeData;
21 import javax.management.openmbean.CompositeDataSupport;
22 import javax.management.openmbean.CompositeType;
23 import javax.management.openmbean.InvalidKeyException;
24 import javax.management.openmbean.InvalidOpenTypeException;
25 import javax.management.openmbean.KeyAlreadyExistsException;
26 import javax.management.openmbean.OpenType;
27 import javax.management.openmbean.SimpleType;
28 import javax.management.openmbean.TabularDataSupport;
29 import javax.management.openmbean.TabularType;
30
31 import junit.framework.TestCase;
32
33 /**
34  * Tabular data support tests.<p>
35  *
36  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
37  */

38 public class TabularDataSupportTestCase
39   extends TestCase
40 {
41    // Static --------------------------------------------------------------------
42

43    // Attributes ----------------------------------------------------------------
44

45    // Constructor ---------------------------------------------------------------
46

47    /**
48     * Construct the test
49     */

50    public TabularDataSupportTestCase(String s)
51    {
52       super(s);
53    }
54
55    // Tests ---------------------------------------------------------------------
56

57    public void testTabularDataSupport()
58       throws Exception
59    {
60       String[] itemNames = new String[] { "name1", "name2" };
61       String[] itemDescriptions = new String[] { "desc1", "desc2" };
62       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
63       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
64          itemNames, itemDescriptions, itemTypes);
65
66       String[] indexNames = new String[] { "name1", "name2" };
67       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
68
69       TabularDataSupport data = new TabularDataSupport(tabularType);
70       TabularDataSupport data2 = new TabularDataSupport(tabularType, 100, .5f);
71    }
72
73    public void testGetTabularType()
74       throws Exception
75    {
76       String[] itemNames = new String[] { "name1", "name2" };
77       String[] itemDescriptions = new String[] { "desc1", "desc2" };
78       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
79       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
80          itemNames, itemDescriptions, itemTypes);
81
82       String[] indexNames = new String[] { "name1", "name2" };
83       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
84
85       TabularDataSupport data = new TabularDataSupport(tabularType);
86       assertTrue("Expected the same tabular type", data.getTabularType().equals(tabularType));
87    }
88
89    public void testCalculateIndex()
90       throws Exception
91    {
92       String[] itemNames = new String[] { "name1", "name2" };
93       String[] itemDescriptions = new String[] { "desc1", "desc2" };
94       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
95       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
96          itemNames, itemDescriptions, itemTypes);
97
98       String[] indexNames = new String[] { "name1", "name2" };
99       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
100
101       TabularDataSupport data = new TabularDataSupport(tabularType);
102
103       HashMap map = new HashMap();
104       map.put("name1", "value1");
105       map.put("name2", new Integer(2));
106       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
107       Object[] index = data.calculateIndex(compData);
108
109       assertTrue("Expected index element 0 to be value1", index[0].equals("value1"));
110       assertTrue("Expected index element 1 to be 2", index[1].equals(new Integer(2)));
111
112       map = new HashMap();
113       map.put("name1", "value2");
114       map.put("name2", new Integer(3));
115       compData = new CompositeDataSupport(rowType, map);
116       index = data.calculateIndex(compData);
117
118       assertTrue("Expected index element 0 to be value2", index[0].equals("value2"));
119       assertTrue("Expected index element 1 to be 3", index[1].equals(new Integer(3)));
120    }
121
122    public void testContainsKeyObject()
123       throws Exception
124    {
125       String[] itemNames = new String[] { "name1", "name2" };
126       String[] itemDescriptions = new String[] { "desc1", "desc2" };
127       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
128       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
129          itemNames, itemDescriptions, itemTypes);
130
131       String[] indexNames = new String[] { "name1", "name2" };
132       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
133
134       TabularDataSupport data = new TabularDataSupport(tabularType);
135
136       assertTrue("Didn't expect containsKey null", data.containsKey(null) == false);
137       assertTrue("Didn't expect containsKey not an Object array", data.containsKey(new Object()) == false);
138
139       Object[] index = new Object[] { "value1", new Integer(2) };
140       assertTrue("Didn't expect containsKey on empty data", data.containsKey((Object) index) == false);
141
142       HashMap map = new HashMap();
143       map.put("name1", "value1");
144       map.put("name2", new Integer(3));
145       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
146       assertTrue("Didn't expect containsKey on index not present", data.containsKey((Object) index) == false);
147
148       map = new HashMap();
149       map.put("name1", "value1");
150       map.put("name2", new Integer(2));
151       compData = new CompositeDataSupport(rowType, map);
152       data.put(compData);
153       assertTrue("Expected containsKey", data.containsKey((Object) index));
154
155       map = new HashMap();
156       map.put("name1", "value1");
157       map.put("name2", new Integer(3));
158       compData = new CompositeDataSupport(rowType, map);
159       assertTrue("Didn't expect containsKey on index still not present",
160          data.containsKey((Object) data.calculateIndex(compData)) == false);
161
162       data.remove(index);
163       assertTrue("Didn't expect removed data in containsKey", data.containsKey((Object) index) == false);
164    }
165
166    public void testContainsKeyObjectArray()
167       throws Exception
168    {
169       String[] itemNames = new String[] { "name1", "name2" };
170       String[] itemDescriptions = new String[] { "desc1", "desc2" };
171       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
172       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
173          itemNames, itemDescriptions, itemTypes);
174
175       String[] indexNames = new String[] { "name1", "name2" };
176       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
177
178       TabularDataSupport data = new TabularDataSupport(tabularType);
179
180       assertTrue("Didn't expect containsKey null", data.containsKey(null) == false);
181       assertTrue("Didn't expect containsKey not an Object array", data.containsKey(new Object()) == false);
182
183       Object[] index = new Object[] { "value1", new Integer(2) };
184       assertTrue("Didn't expect containsKey on empty data", data.containsKey(index) == false);
185
186       HashMap map = new HashMap();
187       map.put("name1", "value1");
188       map.put("name2", new Integer(3));
189       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
190       assertTrue("Didn't expect containsKey on index not present", data.containsKey(index) == false);
191
192       map = new HashMap();
193       map.put("name1", "value1");
194       map.put("name2", new Integer(2));
195       compData = new CompositeDataSupport(rowType, map);
196       data.put(compData);
197       assertTrue("Expected containsKey", data.containsKey(index));
198
199       map = new HashMap();
200       map.put("name1", "value1");
201       map.put("name2", new Integer(3));
202       compData = new CompositeDataSupport(rowType, map);
203       assertTrue("Didn't expect containsKey on index still not present",
204          data.containsKey(data.calculateIndex(compData)) == false);
205
206       data.remove(index);
207       assertTrue("Didn't expect removed data in containsKey", data.containsKey(index) == false);
208    }
209
210    public void testContainsValueObject()
211       throws Exception
212    {
213       String[] itemNames = new String[] { "name1", "name2" };
214       String[] itemDescriptions = new String[] { "desc1", "desc2" };
215       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
216       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
217          itemNames, itemDescriptions, itemTypes);
218
219       String[] indexNames = new String[] { "name1", "name2" };
220       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
221
222       TabularDataSupport data = new TabularDataSupport(tabularType);
223
224       assertTrue("Didn't expect containsValue null", data.containsValue(null) == false);
225
226       itemNames = new String[] { "name1", "name2" };
227       itemDescriptions = new String[] { "desc1", "desc2" };
228       itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
229       CompositeType rowType2 = new CompositeType("rowTypeName2", "rowDescription",
230          itemNames, itemDescriptions, itemTypes);
231
232       HashMap map = new HashMap();
233       map.put("name1", "value1");
234       map.put("name2", new Integer(2));
235       CompositeDataSupport compData2 = new CompositeDataSupport(rowType2, map);
236
237       assertTrue("Didn't expect containsValue wrong composite type", data.containsValue((Object) compData2) == false);
238
239       map = new HashMap();
240       map.put("name1", "value1");
241       map.put("name2", new Integer(3));
242       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
243       assertTrue("Didn't expect containsValue on data not present", data.containsValue((Object) compData) == false);
244
245       map = new HashMap();
246       map.put("name1", "value1");
247       map.put("name2", new Integer(2));
248       compData = new CompositeDataSupport(rowType, map);
249       data.put(compData);
250       assertTrue("Expected containsValue", data.containsValue((Object) compData));
251
252       map = new HashMap();
253       map.put("name1", "value1");
254       map.put("name2", new Integer(3));
255       compData = new CompositeDataSupport(rowType, map);
256       assertTrue("Didn't expect containsValue on value still not present", data.containsValue((Object) compData) == false);
257
258       assertTrue("Didn't expect containsValue still wrong composite type", data.containsValue((Object) compData2) == false);
259
260       data.remove(data.calculateIndex(compData));
261       assertTrue("Didn't expect removed data in containsValue", data.containsValue((Object) compData) == false);
262    }
263
264    public void testContainsValueCompositeData()
265       throws Exception
266    {
267       String[] itemNames = new String[] { "name1", "name2" };
268       String[] itemDescriptions = new String[] { "desc1", "desc2" };
269       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
270       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
271          itemNames, itemDescriptions, itemTypes);
272
273       String[] indexNames = new String[] { "name1", "name2" };
274       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
275
276       TabularDataSupport data = new TabularDataSupport(tabularType);
277
278       assertTrue("Didn't expect containsValue null", data.containsValue(null) == false);
279
280       itemNames = new String[] { "name1", "name2" };
281       itemDescriptions = new String[] { "desc1", "desc2" };
282       itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
283       CompositeType rowType2 = new CompositeType("rowTypeName2", "rowDescription",
284          itemNames, itemDescriptions, itemTypes);
285
286       HashMap map = new HashMap();
287       map.put("name1", "value1");
288       map.put("name2", new Integer(2));
289       CompositeDataSupport compData2 = new CompositeDataSupport(rowType2, map);
290
291       assertTrue("Didn't expect containsValue wrong composite type", data.containsValue(compData2) == false);
292
293       map = new HashMap();
294       map.put("name1", "value1");
295       map.put("name2", new Integer(3));
296       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
297       assertTrue("Didn't expect containsValue on data not present", data.containsValue(compData) == false);
298
299       map = new HashMap();
300       map.put("name1", "value1");
301       map.put("name2", new Integer(2));
302       compData = new CompositeDataSupport(rowType, map);
303       data.put(compData);
304       assertTrue("Expected containsValue", data.containsValue(compData));
305
306       map = new HashMap();
307       map.put("name1", "value1");
308       map.put("name2", new Integer(3));
309       compData = new CompositeDataSupport(rowType, map);
310       assertTrue("Didn't expect containsValue on value still not present", data.containsValue(compData) == false);
311
312       assertTrue("Didn't expect containsValue still wrong composite type", data.containsValue(compData2) == false);
313
314       data.remove(data.calculateIndex(compData));
315       assertTrue("Didn't expect removed data in containsValue", data.containsValue(compData) == false);
316    }
317
318    public void testGetObject()
319       throws Exception
320    {
321       String[] itemNames = new String[] { "name1", "name2" };
322       String[] itemDescriptions = new String[] { "desc1", "desc2" };
323       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
324       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
325          itemNames, itemDescriptions, itemTypes);
326
327       String[] indexNames = new String[] { "name1", "name2" };
328       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
329
330       TabularDataSupport data = new TabularDataSupport(tabularType);
331
332       Object[] index = new Object[] { "value1", new Integer(3) };
333       assertTrue("Expected null for get on data not present", data.get((Object) index) == null);
334
335       HashMap map = new HashMap();
336       map.put("name1", "value1");
337       map.put("name2", new Integer(2));
338       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
339       index = new Object[] { "value1", new Integer(2) };
340       data.put(compData);
341       assertTrue("Expected get to return the same value", data.get((Object) index).equals(compData));
342
343       index = new Object[] { "value1", new Integer(3) };
344       assertTrue("Didn't expect get on value still not present", data.get((Object) index) == null);
345
346       index = new Object[] { "value1", new Integer(2) };
347       data.remove(index);
348       assertTrue("Didn't expect removed data in get", data.get((Object) index) == null);
349    }
350
351    public void testGetObjectArray()
352       throws Exception
353    {
354       String[] itemNames = new String[] { "name1", "name2" };
355       String[] itemDescriptions = new String[] { "desc1", "desc2" };
356       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
357       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
358          itemNames, itemDescriptions, itemTypes);
359
360       String[] indexNames = new String[] { "name1", "name2" };
361       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
362
363       TabularDataSupport data = new TabularDataSupport(tabularType);
364
365       Object[] index = new Object[] { "value1", new Integer(3) };
366       assertTrue("Expected null for get on data not present", data.get(index) == null);
367
368       HashMap map = new HashMap();
369       map.put("name1", "value1");
370       map.put("name2", new Integer(2));
371       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
372       index = new Object[] { "value1", new Integer(2) };
373       data.put(compData);
374       assertTrue("Expected get to return the same value", data.get(index).equals(compData));
375
376       index = new Object[] { "value1", new Integer(3) };
377       assertTrue("Didn't expect get on value still not present", data.get(index) == null);
378
379       index = new Object[] { "value1", new Integer(2) };
380       data.remove(index);
381       assertTrue("Didn't expect removed data in get", data.get(index) == null);
382    }
383
384    public void testPutObjectObject()
385       throws Exception
386    {
387       String[] itemNames = new String[] { "name1", "name2" };
388       String[] itemDescriptions = new String[] { "desc1", "desc2" };
389       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
390       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
391          itemNames, itemDescriptions, itemTypes);
392
393       String[] indexNames = new String[] { "name1", "name2" };
394       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
395
396       TabularDataSupport data = new TabularDataSupport(tabularType);
397
398       HashMap map = new HashMap();
399       map.put("name1", "value1");
400       map.put("name2", new Integer(2));
401       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
402       Object[] index = new Object[] { "value1", new Integer(2) };
403       data.put(index, (Object) compData);
404       assertTrue("The data should be present after put", data.get(index).equals(compData));
405
406       HashMap map2 = new HashMap();
407       map2.put("name1", "value1");
408       map2.put("name2", new Integer(3));
409       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
410       index = new Object[] { "value1", new Integer(3) };
411       data.put(index, (Object) compData2);
412       assertTrue("Another data should be present after put", data.get(index).equals(compData2));
413
414       index = new Object[] { "value1", new Integer(2) };
415       assertTrue("The previous data should be present after put", data.get(index).equals(compData));
416
417       data.remove(index);
418       data.put(index, compData);
419       assertTrue("Data should be present after remove/put", data.get(index).equals(compData));
420
421       HashMap map3 = new HashMap();
422       map3.put("name1", "value1");
423       map3.put("name2", new Integer(4));
424       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
425       index = new Object[] { "value1", new Integer(4) };
426       data.put(new Object(), compData3);
427       assertTrue("The key should be ignored in put", data.get(index).equals(compData3));
428    }
429
430    public void testPutCompositeData()
431       throws Exception
432    {
433       String[] itemNames = new String[] { "name1", "name2" };
434       String[] itemDescriptions = new String[] { "desc1", "desc2" };
435       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
436       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
437          itemNames, itemDescriptions, itemTypes);
438
439       String[] indexNames = new String[] { "name1", "name2" };
440       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
441
442       TabularDataSupport data = new TabularDataSupport(tabularType);
443
444       HashMap map = new HashMap();
445       map.put("name1", "value1");
446       map.put("name2", new Integer(2));
447       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
448       Object[] index = new Object[] { "value1", new Integer(2) };
449       data.put(compData);
450       assertTrue("The data should be present after put", data.get(index).equals(compData));
451
452       HashMap map2 = new HashMap();
453       map2.put("name1", "value1");
454       map2.put("name2", new Integer(3));
455       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
456       index = new Object[] { "value1", new Integer(3) };
457       data.put(compData2);
458       assertTrue("Another data should be present after put", data.get(index).equals(compData2));
459
460       index = new Object[] { "value1", new Integer(2) };
461       assertTrue("The previous data should be present after put", data.get(index).equals(compData));
462
463       data.remove(index);
464       data.put(compData);
465       assertTrue("Data should be present after remove/put", data.get(index).equals(compData));
466    }
467
468    public void testRemoveObject()
469       throws Exception
470    {
471       String[] itemNames = new String[] { "name1", "name2" };
472       String[] itemDescriptions = new String[] { "desc1", "desc2" };
473       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
474       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
475          itemNames, itemDescriptions, itemTypes);
476
477       String[] indexNames = new String[] { "name1", "name2" };
478       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
479
480       TabularDataSupport data = new TabularDataSupport(tabularType);
481
482       HashMap map = new HashMap();
483       map.put("name1", "value1");
484       map.put("name2", new Integer(2));
485       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
486       Object[] index = new Object[] { "value1", new Integer(2) };
487
488       assertTrue("Remove on data not present returns null", data.remove((Object) index) == null);
489
490       data.put(compData);
491       assertTrue("Remove on data present returns the data", data.remove((Object) index).equals(compData));
492    }
493
494    public void testRemoveObjectArray()
495       throws Exception
496    {
497       String[] itemNames = new String[] { "name1", "name2" };
498       String[] itemDescriptions = new String[] { "desc1", "desc2" };
499       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
500       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
501          itemNames, itemDescriptions, itemTypes);
502
503       String[] indexNames = new String[] { "name1", "name2" };
504       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
505
506       TabularDataSupport data = new TabularDataSupport(tabularType);
507
508       HashMap map = new HashMap();
509       map.put("name1", "value1");
510       map.put("name2", new Integer(2));
511       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
512       Object[] index = new Object[] { "value1", new Integer(2) };
513
514       assertTrue("Remove on data not present returns null", data.remove(index) == null);
515
516       data.put(compData);
517       assertTrue("Remove on data present returns the data", data.remove(index).equals(compData));
518    }
519
520    public void testPutAllMap()
521       throws Exception
522    {
523       String[] itemNames = new String[] { "name1", "name2" };
524       String[] itemDescriptions = new String[] { "desc1", "desc2" };
525       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
526       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
527          itemNames, itemDescriptions, itemTypes);
528
529       String[] indexNames = new String[] { "name1", "name2" };
530       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
531
532       TabularDataSupport data = new TabularDataSupport(tabularType);
533
534       data.putAll((Map) null);
535       assertTrue("Put all null is ok", data.isEmpty());
536
537       HashMap map = new HashMap();
538       map.put("name1", "value1");
539       map.put("name2", new Integer(2));
540       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
541
542       HashMap toPut = new HashMap();
543       toPut.put(new Object(), compData);
544       data.putAll(toPut);
545       assertTrue("Put all added one", data.size() == 1);
546       assertTrue("Put all added the correct data", data.containsValue(compData));
547
548       HashMap map2 = new HashMap();
549       map2.put("name1", "value1");
550       map2.put("name2", new Integer(3));
551       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
552
553       HashMap map3 = new HashMap();
554       map3.put("name1", "value1");
555       map3.put("name2", new Integer(4));
556       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
557
558       toPut = new HashMap();
559       toPut.put(new Object(), compData2);
560       toPut.put(new Object(), compData3);
561       data.putAll(toPut);
562       assertTrue("Put all added two", data.size() == 3);
563       assertTrue("Put all added the correct data", data.containsValue(compData2));
564       assertTrue("Put all added the correct data", data.containsValue(compData3));
565       assertTrue("Put all original data still present", data.containsValue(compData));
566    }
567
568    public void testPutAllCompositeData()
569       throws Exception
570    {
571       String[] itemNames = new String[] { "name1", "name2" };
572       String[] itemDescriptions = new String[] { "desc1", "desc2" };
573       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
574       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
575          itemNames, itemDescriptions, itemTypes);
576
577       String[] indexNames = new String[] { "name1", "name2" };
578       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
579
580       TabularDataSupport data = new TabularDataSupport(tabularType);
581
582       data.putAll((CompositeData[]) null);
583       assertTrue("Put all null is ok", data.isEmpty());
584
585       HashMap map = new HashMap();
586       map.put("name1", "value1");
587       map.put("name2", new Integer(2));
588       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
589
590       CompositeData[] toPut = new CompositeData[] { compData };
591       data.putAll(toPut);
592       assertTrue("Put all added one", data.size() == 1);
593       assertTrue("Put all added the correct data", data.containsValue(compData));
594
595       HashMap map2 = new HashMap();
596       map2.put("name1", "value1");
597       map2.put("name2", new Integer(3));
598       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
599
600       HashMap map3 = new HashMap();
601       map3.put("name1", "value1");
602       map3.put("name2", new Integer(4));
603       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
604
605       toPut = new CompositeData[] { compData2, compData3 };
606       data.putAll(toPut);
607       assertTrue("Put all added two", data.size() == 3);
608       assertTrue("Put all added the correct data", data.containsValue(compData2));
609       assertTrue("Put all added the correct data", data.containsValue(compData3));
610       assertTrue("Put all original data still present", data.containsValue(compData));
611    }
612
613    public void testClear()
614       throws Exception
615    {
616       String[] itemNames = new String[] { "name1", "name2" };
617       String[] itemDescriptions = new String[] { "desc1", "desc2" };
618       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
619       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
620          itemNames, itemDescriptions, itemTypes);
621
622       String[] indexNames = new String[] { "name1", "name2" };
623       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
624
625       TabularDataSupport data = new TabularDataSupport(tabularType);
626
627       data.putAll((CompositeData[]) null);
628       assertTrue("Put all null is ok", data.isEmpty());
629
630       HashMap map = new HashMap();
631       map.put("name1", "value1");
632       map.put("name2", new Integer(2));
633       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
634
635       HashMap map2 = new HashMap();
636       map2.put("name1", "value1");
637       map2.put("name2", new Integer(3));
638       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
639
640       HashMap map3 = new HashMap();
641       map3.put("name1", "value1");
642       map3.put("name2", new Integer(4));
643       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
644
645       HashMap toPut = new HashMap();
646       toPut.put(new Object(), compData);
647       toPut.put(new Object(), compData2);
648       toPut.put(new Object(), compData3);
649       data.putAll(toPut);
650
651       data.clear();
652       assertTrue("Clear should clear the data", data.isEmpty());
653    }
654
655    public void testSize()
656       throws Exception
657    {
658       String[] itemNames = new String[] { "name1", "name2" };
659       String[] itemDescriptions = new String[] { "desc1", "desc2" };
660       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
661       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
662          itemNames, itemDescriptions, itemTypes);
663
664       String[] indexNames = new String[] { "name1", "name2" };
665       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
666
667       TabularDataSupport data = new TabularDataSupport(tabularType);
668
669       assertTrue("Initial size is zero", data.size() == 0);
670
671       HashMap map = new HashMap();
672       map.put("name1", "value1");
673       map.put("name2", new Integer(2));
674       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
675
676       CompositeData[] toPut = new CompositeData[] { compData };
677       data.putAll(toPut);
678       assertTrue("Expected one element", data.size() == 1);
679
680       HashMap map2 = new HashMap();
681       map2.put("name1", "value1");
682       map2.put("name2", new Integer(3));
683       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
684
685       HashMap map3 = new HashMap();
686       map3.put("name1", "value1");
687       map3.put("name2", new Integer(4));
688       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
689
690       toPut = new CompositeData[] { compData2, compData3 };
691       data.putAll(toPut);
692       assertTrue("Expected three elements", data.size() == 3);
693
694       data.remove(new Object[] { "value1", new Integer(4) });
695       assertTrue("Expected two elements", data.size() == 2);
696
697       data.clear();
698       assertTrue("Expected no elements", data.size() == 0);
699    }
700
701    public void testIsEmpty()
702       throws Exception
703    {
704       String[] itemNames = new String[] { "name1", "name2" };
705       String[] itemDescriptions = new String[] { "desc1", "desc2" };
706       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
707       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
708          itemNames, itemDescriptions, itemTypes);
709
710       String[] indexNames = new String[] { "name1", "name2" };
711       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
712
713       TabularDataSupport data = new TabularDataSupport(tabularType);
714
715       assertTrue("Initially empty", data.isEmpty());
716
717       HashMap map = new HashMap();
718       map.put("name1", "value1");
719       map.put("name2", new Integer(2));
720       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
721
722       CompositeData[] toPut = new CompositeData[] { compData };
723       data.putAll(toPut);
724       assertTrue("Not empty after a put", data.isEmpty() == false);
725
726       data.clear();
727       assertTrue("Expected no elements", data.isEmpty());
728    }
729
730    /**
731     * @todo full test, unmodifiable/iterator
732     */

733    public void testKeySet()
734       throws Exception
735    {
736       String[] itemNames = new String[] { "name1", "name2" };
737       String[] itemDescriptions = new String[] { "desc1", "desc2" };
738       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
739       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
740          itemNames, itemDescriptions, itemTypes);
741
742       String[] indexNames = new String[] { "name1", "name2" };
743       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
744
745       TabularDataSupport data = new TabularDataSupport(tabularType);
746
747       data.putAll((CompositeData[]) null);
748       assertTrue("Put all null is ok", data.isEmpty());
749
750       HashMap map = new HashMap();
751       map.put("name1", "value1");
752       map.put("name2", new Integer(2));
753       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
754
755       HashMap map2 = new HashMap();
756       map2.put("name1", "value1");
757       map2.put("name2", new Integer(3));
758       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
759
760       HashMap map3 = new HashMap();
761       map3.put("name1", "value1");
762       map3.put("name2", new Integer(4));
763       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
764
765       HashMap toPut = new HashMap();
766       toPut.put(new Object(), compData);
767       toPut.put(new Object(), compData2);
768       toPut.put(new Object(), compData3);
769       data.putAll(toPut);
770
771       Set keySet = data.keySet();
772       assertTrue("Key set should contain 3 elements", keySet.size() == 3);
773       assertTrue("Key set should contain index [value1, 2]",
774          keySet.contains(Arrays.asList(new Object[] { "value1", new Integer(2) })));
775       assertTrue("Key set should contain index [value1, 3]",
776          keySet.contains(Arrays.asList(new Object[] { "value1", new Integer(3) })));
777       assertTrue("Key set should contain index [value1, 4]",
778          keySet.contains(Arrays.asList(new Object[] { "value1", new Integer(4) })));
779    }
780
781    /**
782     * @todo full test, modifiable/iterator
783     */

784    public void testValues()
785       throws Exception
786    {
787       String[] itemNames = new String[] { "name1", "name2" };
788       String[] itemDescriptions = new String[] { "desc1", "desc2" };
789       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
790       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
791          itemNames, itemDescriptions, itemTypes);
792
793       String[] indexNames = new String[] { "name1", "name2" };
794       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
795
796       TabularDataSupport data = new TabularDataSupport(tabularType);
797
798       data.putAll((CompositeData[]) null);
799       assertTrue("Put all null is ok", data.isEmpty());
800
801       HashMap map = new HashMap();
802       map.put("name1", "value1");
803       map.put("name2", new Integer(2));
804       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
805
806       HashMap map2 = new HashMap();
807       map2.put("name1", "value1");
808       map2.put("name2", new Integer(3));
809       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
810
811       HashMap map3 = new HashMap();
812       map3.put("name1", "value1");
813       map3.put("name2", new Integer(4));
814       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
815
816       HashMap toPut = new HashMap();
817       toPut.put(new Object(), compData);
818       toPut.put(new Object(), compData2);
819       toPut.put(new Object(), compData3);
820       data.putAll(toPut);
821
822       Collection values = data.values();
823       assertTrue("Values should contain 3 elements", values.size() == 3);
824       assertTrue("Values should contain index compData", values.contains(compData));
825       assertTrue("Values should contain index compData2", values.contains(compData2));
826       assertTrue("Values should contain index compData3", values.contains(compData3));
827    }
828
829    /**
830     * @todo this test
831     */

832    public void testEntrySet()
833       throws Exception
834    {
835    }
836
837    public void testClone()
838       throws Exception
839    {
840       String[] itemNames = new String[] { "name1", "name2" };
841       String[] itemDescriptions = new String[] { "desc1", "desc2" };
842       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
843       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
844          itemNames, itemDescriptions, itemTypes);
845
846       String[] indexNames = new String[] { "name1", "name2" };
847       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
848
849       TabularDataSupport data = new TabularDataSupport(tabularType);
850
851       data.putAll((CompositeData[]) null);
852       assertTrue("Put all null is ok", data.isEmpty());
853
854       HashMap map = new HashMap();
855       map.put("name1", "value1");
856       map.put("name2", new Integer(2));
857       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
858
859       HashMap map2 = new HashMap();
860       map2.put("name1", "value1");
861       map2.put("name2", new Integer(3));
862       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
863
864       HashMap map3 = new HashMap();
865       map3.put("name1", "value1");
866       map3.put("name2", new Integer(4));
867       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
868
869       HashMap toPut = new HashMap();
870       toPut.put(new Object(), compData);
871       toPut.put(new Object(), compData2);
872       toPut.put(new Object(), compData3);
873       data.putAll(toPut);
874
875       TabularDataSupport clone = (TabularDataSupport) data.clone();
876       assertTrue("Clone should have the same tabular type", data.getTabularType().equals(clone.getTabularType()));
877       assertTrue("Clone should have the same number of elements", data.size() == clone.size());
878       CompositeData compDataClone = clone.get(new Object[] {"value1", new Integer(2) });
879       assertTrue("Should be a shallow clone", compData == compDataClone);
880    }
881
882    public void testEquals()
883       throws Exception
884    {
885       String[] itemNames = new String[] { "name1", "name2" };
886       String[] itemDescriptions = new String[] { "desc1", "desc2" };
887       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
888       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
889          itemNames, itemDescriptions, itemTypes);
890
891       String[] indexNames = new String[] { "name1", "name2" };
892       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
893
894       TabularDataSupport data = new TabularDataSupport(tabularType);
895
896       assertTrue("Null should not be equal", data.equals(null) == false);
897       assertTrue("Only TabularData should be equal", data.equals(new Object()) == false);
898
899       assertTrue("An instance should equal itself", data.equals(data));
900
901       TabularDataSupport data2 = new TabularDataSupport(tabularType);
902
903       assertTrue("Two different instances with the same tabular type are equal", data.equals(data2));
904       assertTrue("Two different instances with the same tabular type are equal", data2.equals(data));
905
906       TabularType tabularType2 = new TabularType("typeName2", "description", rowType, indexNames);
907       data2 = new TabularDataSupport(tabularType2);
908
909       assertTrue("Instances with different tabular type are not equal", data.equals(data2) == false);
910       assertTrue("Instances with different tabular type are not equal", data2.equals(data) == false);
911
912       HashMap map = new HashMap();
913       map.put("name1", "value1");
914       map.put("name2", new Integer(2));
915       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
916
917       HashMap map2 = new HashMap();
918       map2.put("name1", "value1");
919       map2.put("name2", new Integer(3));
920       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
921
922       HashMap map3 = new HashMap();
923       map3.put("name1", "value1");
924       map3.put("name2", new Integer(4));
925       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
926
927       HashMap toPut = new HashMap();
928       toPut.put(new Object(), compData);
929       toPut.put(new Object(), compData2);
930       toPut.put(new Object(), compData3);
931
932       data.putAll(toPut);
933       data2 = new TabularDataSupport(tabularType);
934       data2.putAll(toPut);
935       assertTrue("Instances with the same composite data are equal", data.equals(data2));
936       assertTrue("Instances with the same composite data are equal", data2.equals(data));
937
938       toPut = new HashMap();
939       toPut.put(new Object(), compData);
940       toPut.put(new Object(), compData2);
941       data2 = new TabularDataSupport(tabularType);
942       data2.putAll(toPut);
943       assertTrue("Instances with different composite data are not equal", data.equals(data2) == false);
944       assertTrue("Instances with different composite data are not equal", data2.equals(data) == false);
945    }
946
947    public void testHashCode()
948       throws Exception
949    {
950       String[] itemNames = new String[] { "name1", "name2" };
951       String[] itemDescriptions = new String[] { "desc1", "desc2" };
952       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
953       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
954          itemNames, itemDescriptions, itemTypes);
955
956       String[] indexNames = new String[] { "name1", "name2" };
957       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
958
959       TabularDataSupport data = new TabularDataSupport(tabularType);
960
961       data.putAll((CompositeData[]) null);
962       assertTrue("Put all null is ok", data.isEmpty());
963
964       HashMap map = new HashMap();
965       map.put("name1", "value1");
966       map.put("name2", new Integer(2));
967       CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
968
969       HashMap map2 = new HashMap();
970       map2.put("name1", "value1");
971       map2.put("name2", new Integer(3));
972       CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
973
974       HashMap map3 = new HashMap();
975       map3.put("name1", "value1");
976       map3.put("name2", new Integer(4));
977       CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
978
979       HashMap toPut = new HashMap();
980       toPut.put(new Object(), compData);
981       toPut.put(new Object(), compData2);
982       toPut.put(new Object(), compData3);
983       data.putAll(toPut);
984
985       int myHashCode = tabularType.hashCode() + compData.hashCode() + compData2.hashCode() + compData3.hashCode();
986       assertTrue("Wrong hash code generated", myHashCode == data.hashCode());
987    }
988
989    public void testToString()
990       throws Exception
991    {
992       String[] itemNames = new String[] { "name1", "name2" };
993       String[] itemDescriptions = new String[] { "desc1", "desc2" };
994       OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
995       CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
996          itemNames, itemDescriptions, itemTypes);
997
998       String[] indexNames = new String[] { "name1", "name2" };
999       TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1000
1001      TabularDataSupport data = new TabularDataSupport(tabularType);
1002
1003      data.putAll((CompositeData[]) null);
1004      assertTrue("Put all null is ok", data.isEmpty());
1005
1006      HashMap map = new HashMap();
1007      map.put("name1", "value1");
1008      map.put("name2", new Integer(2));
1009      CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
1010
1011      HashMap map2 = new HashMap();
1012      map2.put("name1", "value1");
1013      map2.put("name2", new Integer(3));
1014      CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
1015
1016      HashMap map3 = new HashMap();
1017      map3.put("name1", "value1");
1018      map3.put("name2", new Integer(4));
1019      CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
1020
1021      HashMap toPut = new HashMap();
1022      toPut.put(new Object(), compData);
1023      toPut.put(new Object(), compData2);
1024      toPut.put(new Object(), compData3);
1025      data.putAll(toPut);
1026
1027      String toString = data.toString();
1028
1029      assertTrue("toString() should contain the tabular type",
1030         toString.indexOf(tabularType.toString()) != -1);
1031      assertTrue("toString() should contain index=compositeData for compData",
1032         toString.indexOf(Arrays.asList(data.calculateIndex(compData)) + "=" + compData) != -1);
1033      assertTrue("toString() should contain index=compositeData for compData2",
1034         toString.indexOf(Arrays.asList(data.calculateIndex(compData2)) + "=" + compData2) != -1);
1035      assertTrue("toString() should contain index=compositeData for compData3",
1036         toString.indexOf(Arrays.asList(data.calculateIndex(compData3)) + "=" + compData3) != -1);
1037   }
1038
1039   public void testSerialization()
1040      throws Exception
1041   {
1042      String[] itemNames = new String[] { "name1", "name2" };
1043      String[] itemDescriptions = new String[] { "desc1", "desc2" };
1044      OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1045      CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1046         itemNames, itemDescriptions, itemTypes);
1047
1048      String[] indexNames = new String[] { "name1", "name2" };
1049      TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1050
1051      TabularDataSupport data = new TabularDataSupport(tabularType);
1052
1053      data.putAll((CompositeData[]) null);
1054      assertTrue("Put all null is ok", data.isEmpty());
1055
1056      HashMap map = new HashMap();
1057      map.put("name1", "value1");
1058      map.put("name2", new Integer(2));
1059      CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
1060
1061      HashMap map2 = new HashMap();
1062      map2.put("name1", "value1");
1063      map2.put("name2", new Integer(3));
1064      CompositeDataSupport compData2 = new CompositeDataSupport(rowType, map2);
1065
1066      HashMap map3 = new HashMap();
1067      map3.put("name1", "value1");
1068      map3.put("name2", new Integer(4));
1069      CompositeDataSupport compData3 = new CompositeDataSupport(rowType, map3);
1070
1071      HashMap toPut = new HashMap();
1072      toPut.put(new Object(), compData);
1073      toPut.put(new Object(), compData2);
1074      toPut.put(new Object(), compData3);
1075      data.putAll(toPut);
1076
1077      // Serialize it
1078
ByteArrayOutputStream baos = new ByteArrayOutputStream();
1079      ObjectOutputStream oos = new ObjectOutputStream(baos);
1080      oos.writeObject(data);
1081    
1082      // Deserialize it
1083
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
1084      ObjectInputStream ois = new ObjectInputStream(bais);
1085      Object result = ois.readObject();
1086
1087      assertEquals(data, result);
1088   }
1089
1090   public void testErrors()
1091      throws Exception
1092   {
1093      String[] itemNames = new String[] { "name1", "name2" };
1094      String[] itemDescriptions = new String[] { "desc1", "desc2" };
1095      OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1096
1097      CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1098         itemNames, itemDescriptions, itemTypes);
1099      HashMap map = new HashMap();
1100      map.put("name1", "value1");
1101      map.put("name2", new Integer(2));
1102      CompositeDataSupport compData = new CompositeDataSupport(rowType, map);
1103
1104      CompositeType rowType2 = new CompositeType("rowTypeName2", "rowDescription",
1105         itemNames, itemDescriptions, itemTypes);
1106      CompositeDataSupport compData2 = new CompositeDataSupport(rowType2, map);
1107
1108      String[] indexNames = new String[] { "name1", "name2" };
1109      TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1110
1111      boolean caught = false;
1112      try
1113      {
1114         new TabularDataSupport(null);
1115      }
1116      catch (IllegalArgumentException e)
1117      {
1118         caught = true;
1119      }
1120      if (caught == false)
1121         fail("Expected IllegalArgumentException for null tabular type");
1122
1123      caught = false;
1124      try
1125      {
1126         new TabularDataSupport(null, 10, .5f);
1127      }
1128      catch (IllegalArgumentException e)
1129      {
1130         caught = true;
1131      }
1132      if (caught == false)
1133         fail("Expected IllegalArgumentException for null tabular type");
1134
1135      caught = false;
1136      try
1137      {
1138         new TabularDataSupport(tabularType, -1, .5f);
1139      }
1140      catch (IllegalArgumentException e)
1141      {
1142         caught = true;
1143      }
1144      if (caught == false)
1145         fail("Expected IllegalArgumentException for negative initial capacity");
1146
1147      caught = false;
1148      try
1149      {
1150         new TabularDataSupport(tabularType, 10, 0f);
1151      }
1152      catch (IllegalArgumentException e)
1153      {
1154         caught = true;
1155      }
1156      if (caught == false)
1157         fail("Expected IllegalArgumentException for zero load factor");
1158
1159      caught = false;
1160      try
1161      {
1162         new TabularDataSupport(tabularType, 10, -0.5f);
1163      }
1164      catch (IllegalArgumentException e)
1165      {
1166         caught = true;
1167      }
1168      if (caught == false)
1169         fail("Expected IllegalArgumentException for negative load factor");
1170
1171      caught = false;
1172      try
1173      {
1174         TabularDataSupport data = new TabularDataSupport(tabularType);
1175         data.calculateIndex(null);
1176      }
1177      catch (NullPointerException e)
1178      {
1179         caught = true;
1180      }
1181      if (caught == false)
1182         fail("Expected NullPointerException for calculate index on null object");
1183
1184      caught = false;
1185      try
1186      {
1187         TabularDataSupport data = new TabularDataSupport(tabularType);
1188         data.calculateIndex(compData2);
1189      }
1190      catch (InvalidOpenTypeException e)
1191      {
1192         caught = true;
1193      }
1194      if (caught == false)
1195         fail("Expected InvalidOpenTypeException for calculate index on wrong composite type");
1196
1197      caught = false;
1198      try
1199      {
1200         TabularDataSupport data = new TabularDataSupport(tabularType);
1201         data.get((Object) null);
1202      }
1203      catch (NullPointerException e)
1204      {
1205         caught = true;
1206      }
1207      if (caught == false)
1208         fail("Expected NullPointerException for get((Object) null)");
1209
1210      caught = false;
1211      try
1212      {
1213         TabularDataSupport data = new TabularDataSupport(tabularType);
1214         data.get(new Object());
1215      }
1216      catch (ClassCastException e)
1217      {
1218         caught = true;
1219      }
1220      if (caught == false)
1221         fail("Expected ClassCastException for get(new Object())");
1222
1223      caught = false;
1224      try
1225      {
1226         TabularDataSupport data = new TabularDataSupport(tabularType);
1227         data.get((Object) new Object[] { "wrong" });
1228      }
1229      catch (InvalidKeyException e)
1230      {
1231         caught = true;
1232      }
1233      if (caught == false)
1234         fail("Expected InvalidKeyException for get(Object) wrong");
1235
1236      caught = false;
1237      try
1238      {
1239         TabularDataSupport data = new TabularDataSupport(tabularType);
1240         data.get((Object[]) null);
1241      }
1242      catch (NullPointerException e)
1243      {
1244         caught = true;
1245      }
1246      if (caught == false)
1247         fail("Expected NullPointerException for get((Object[]) null)");
1248
1249      caught = false;
1250      try
1251      {
1252         TabularDataSupport data = new TabularDataSupport(tabularType);
1253         data.get(new Object[] { "wrong" });
1254      }
1255      catch (InvalidKeyException e)
1256      {
1257         caught = true;
1258      }
1259      if (caught == false)
1260         fail("Expected InvalidKeyException for get(Object[]) wrong");
1261
1262      caught = false;
1263      try
1264      {
1265         TabularDataSupport data = new TabularDataSupport(tabularType);
1266         data.put(new Object(), null);
1267      }
1268      catch (NullPointerException e)
1269      {
1270         caught = true;
1271      }
1272      if (caught == false)
1273         fail("Expected NullPointerException for put(Object, Object) with null value");
1274
1275      caught = false;
1276      try
1277      {
1278         TabularDataSupport data = new TabularDataSupport(tabularType);
1279         data.put(new Object(), new Object());
1280      }
1281      catch (ClassCastException e)
1282      {
1283         caught = true;
1284      }
1285      if (caught == false)
1286         fail("Expected ClassCastException for put(Object, Object) with none CompositeData");
1287
1288      caught = false;
1289      try
1290      {
1291         TabularDataSupport data = new TabularDataSupport(tabularType);
1292         data.put(new Object(), compData2);
1293      }
1294      catch (InvalidOpenTypeException e)
1295      {
1296         caught = true;
1297      }
1298      if (caught == false)
1299         fail("Expected InvalidOpenTypeException for put(Object, Object) with wrong CompositeType");
1300
1301      caught = false;
1302      try
1303      {
1304         TabularDataSupport data = new TabularDataSupport(tabularType);
1305         data.put(new Object(), compData);
1306         data.put(new Object(), compData);
1307      }
1308      catch (KeyAlreadyExistsException e)
1309      {
1310         caught = true;
1311      }
1312      if (caught == false)
1313         fail("Expected KeyAlreadyExistsException for put(Object, Object)");
1314
1315      caught = false;
1316      try
1317      {
1318         TabularDataSupport data = new TabularDataSupport(tabularType);
1319         data.put(null);
1320      }
1321      catch (NullPointerException e)
1322      {
1323         caught = true;
1324      }
1325      if (caught == false)
1326         fail("Expected NullPointerException for put(CompositeData) with null value");
1327
1328      caught = false;
1329      try
1330      {
1331         TabularDataSupport data = new TabularDataSupport(tabularType);
1332         data.put(compData2);
1333      }
1334      catch (InvalidOpenTypeException e)
1335      {
1336         caught = true;
1337      }
1338      if (caught == false)
1339         fail("Expected InvalidOpenTypeException for put(CompositeData) with wrong CompositeType");
1340
1341      caught = false;
1342      try
1343      {
1344         TabularDataSupport data = new TabularDataSupport(tabularType);
1345         data.put(compData);
1346         data.put(compData);
1347      }
1348      catch (KeyAlreadyExistsException e)
1349      {
1350         caught = true;
1351      }
1352      if (caught == false)
1353         fail("Expected KeyAlreadyExistsException for put(CompositeData)");
1354
1355      caught = false;
1356      try
1357      {
1358         TabularDataSupport data = new TabularDataSupport(tabularType);
1359         data.remove((Object) null);
1360      }
1361      catch (NullPointerException e)
1362      {
1363         caught = true;
1364      }
1365      if (caught == false)
1366         fail("Expected NullPointerException for remove((Object) null)");
1367
1368      caught = false;
1369      try
1370      {
1371         TabularDataSupport data = new TabularDataSupport(tabularType);
1372         data.remove(new Object());
1373      }
1374      catch (ClassCastException e)
1375      {
1376         caught = true;
1377      }
1378      if (caught == false)
1379         fail("Expected ClassCastException for remove(new Object())");
1380
1381      caught = false;
1382      try
1383      {
1384         TabularDataSupport data = new TabularDataSupport(tabularType);
1385         data.remove((Object) new Object[] { "wrong" });
1386      }
1387      catch (InvalidKeyException e)
1388      {
1389         caught = true;
1390      }
1391      if (caught == false)
1392         fail("Expected InvalidKeyException for remove(Object) wrong");
1393
1394      caught = false;
1395      try
1396      {
1397         TabularDataSupport data = new TabularDataSupport(tabularType);
1398         data.remove((Object[]) null);
1399      }
1400      catch (NullPointerException e)
1401      {
1402         caught = true;
1403      }
1404      if (caught == false)
1405         fail("Expected NullPointerException for remove((Object[]) null)");
1406
1407      caught = false;
1408      try
1409      {
1410         TabularDataSupport data = new TabularDataSupport(tabularType);
1411         data.remove(new Object[] { "wrong" });
1412      }
1413      catch (InvalidKeyException e)
1414      {
1415         caught = true;
1416      }
1417      if (caught == false)
1418         fail("Expected InvalidKeyException for remove(Object[]) wrong");
1419
1420      caught = false;
1421      try
1422      {
1423         TabularDataSupport data = new TabularDataSupport(tabularType);
1424         HashMap toPut = new HashMap();
1425         toPut.put(new Object(), compData);
1426         toPut.put(new Object(), null);
1427         data.putAll(toPut);
1428      }
1429      catch (NullPointerException e)
1430      {
1431         caught = true;
1432      }
1433      if (caught == false)
1434         fail("Expected NullPointerException for putAll(Map) null");
1435
1436      {
1437         TabularDataSupport data = new TabularDataSupport(tabularType);
1438         HashMap toPut = new HashMap();
1439         toPut.put(new Object(), compData);
1440         toPut.put(new Object(), null);
1441         try
1442         {
1443            data.putAll(toPut);
1444         }
1445         catch (NullPointerException expected)
1446         {
1447         }
1448         assertTrue("Nothing should be added for NullPointerException putAll(Map)", data.isEmpty());
1449      }
1450
1451      caught = false;
1452      try
1453      {
1454         TabularDataSupport data = new TabularDataSupport(tabularType);
1455         HashMap toPut = new HashMap();
1456         toPut.put(new Object(), compData);
1457         toPut.put(new Object(), new Object());
1458         data.putAll(toPut);
1459      }
1460      catch (ClassCastException e)
1461      {
1462         caught = true;
1463      }
1464      if (caught == false)
1465         fail("Expected ClassCastException for putAll(Map) non composite data");
1466
1467      {
1468         TabularDataSupport data = new TabularDataSupport(tabularType);
1469         HashMap toPut = new HashMap();
1470         toPut.put(new Object(), compData);
1471         toPut.put(new Object(), new Object());
1472         try
1473         {
1474            data.putAll(toPut);
1475         }
1476         catch (ClassCastException expected)
1477         {
1478         }
1479         assertTrue("Nothing should be added for ClassCastException putAll(Map)", data.isEmpty());
1480      }
1481
1482      caught = false;
1483      try
1484      {
1485         TabularDataSupport data = new TabularDataSupport(tabularType);
1486         HashMap toPut = new HashMap();
1487         toPut.put(new Object(), compData);
1488         toPut.put(new Object(), compData2);
1489         data.putAll(toPut);
1490      }
1491      catch (InvalidOpenTypeException e)
1492      {
1493         caught = true;
1494      }
1495      if (caught == false)
1496         fail("Expected InvalidOpenTypeException for putAll(Map) wrong composite type");
1497
1498      {
1499         TabularDataSupport data = new TabularDataSupport(tabularType);
1500         HashMap toPut = new HashMap();
1501         toPut.put(new Object(), compData);
1502         toPut.put(new Object(), compData2);
1503         try
1504         {
1505            data.putAll(toPut);
1506         }
1507         catch (InvalidOpenTypeException expected)
1508         {
1509         }
1510         assertTrue("Nothing should be added for InvalidOpenTypeException putAll(Map)", data.isEmpty());
1511      }
1512
1513      caught = false;
1514      try
1515      {
1516         TabularDataSupport data = new TabularDataSupport(tabularType);
1517         HashMap toPut = new HashMap();
1518         toPut.put(new Object(), compData);
1519         toPut.put(new Object(), compData);
1520         data.putAll(toPut);
1521      }
1522      catch (KeyAlreadyExistsException e)
1523      {
1524         caught = true;
1525      }
1526      if (caught == false)
1527         fail("Expected InvalidOpenTypeException for putAll(Map) with duplicate data");
1528
1529      {
1530         TabularDataSupport data = new TabularDataSupport(tabularType);
1531         HashMap toPut = new HashMap();
1532         toPut.put(new Object(), compData);
1533         toPut.put(new Object(), compData);
1534         try
1535         {
1536            data.putAll(toPut);
1537         }
1538         catch (KeyAlreadyExistsException expected)
1539         {
1540         }
1541         assertTrue("Nothing should be added for KeyAlreadyExistsException duplicates putAll(Map)", data.isEmpty());
1542      }
1543
1544      caught = false;
1545      try
1546      {
1547         TabularDataSupport data = new TabularDataSupport(tabularType);
1548         HashMap toPut = new HashMap();
1549         toPut.put(new Object(), compData);
1550         data.putAll(toPut);
1551         toPut = new HashMap();
1552         toPut.put(new Object(), compData);
1553         data.putAll(toPut);
1554      }
1555      catch (KeyAlreadyExistsException e)
1556      {
1557         caught = true;
1558      }
1559      if (caught == false)
1560         fail("Expected InvalidOpenTypeException for putAll(Map) adding a duplicate");
1561
1562      {
1563         TabularDataSupport data = new TabularDataSupport(tabularType);
1564         HashMap toPut = new HashMap();
1565         toPut.put(new Object(), compData);
1566         data.putAll(toPut);
1567         toPut = new HashMap();
1568         toPut.put(new Object(), compData);
1569         try
1570         {
1571            data.putAll(toPut);
1572         }
1573         catch (KeyAlreadyExistsException expected)
1574         {
1575         }
1576         assertTrue("Nothing should be added for KeyAlreadyExistsException already put putAll(Map)", data.size() == 1);
1577      }
1578
1579      caught = false;
1580      try
1581      {
1582         TabularDataSupport data = new TabularDataSupport(tabularType);
1583         CompositeData[] toPut = new CompositeData[] { compData, null };
1584         data.putAll(toPut);
1585      }
1586      catch (NullPointerException e)
1587      {
1588         caught = true;
1589      }
1590      if (caught == false)
1591         fail("Expected NullPointerException for putAll(CompositeData[]) null");
1592
1593      {
1594         TabularDataSupport data = new TabularDataSupport(tabularType);
1595         CompositeData[] toPut = new CompositeData[] { compData, null };
1596         try
1597         {
1598            data.putAll(toPut);
1599         }
1600         catch (NullPointerException expected)
1601         {
1602         }
1603         assertTrue("Nothing should be added for NullPointerException putAll(CompositeData[])", data.isEmpty());
1604      }
1605
1606      caught = false;
1607      try
1608      {
1609         TabularDataSupport data = new TabularDataSupport(tabularType);
1610         CompositeData[] toPut = new CompositeData[] { compData, compData2 };
1611         data.putAll(toPut);
1612      }
1613      catch (InvalidOpenTypeException e)
1614      {
1615         caught = true;
1616      }
1617      if (caught == false)
1618         fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) wrong composite type");
1619
1620      {
1621         TabularDataSupport data = new TabularDataSupport(tabularType);
1622         CompositeData[] toPut = new CompositeData[] { compData, compData2 };
1623         try
1624         {
1625            data.putAll(toPut);
1626         }
1627         catch (InvalidOpenTypeException expected)
1628         {
1629         }
1630         assertTrue("Nothing should be added for InvalidOpenTypeException putAll(CompositeData[])", data.isEmpty());
1631      }
1632
1633      caught = false;
1634      try
1635      {
1636         TabularDataSupport data = new TabularDataSupport(tabularType);
1637         CompositeData[] toPut = new CompositeData[] { compData, compData };
1638         data.putAll(toPut);
1639      }
1640      catch (KeyAlreadyExistsException e)
1641      {
1642         caught = true;
1643      }
1644      if (caught == false)
1645         fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) with duplicate data");
1646
1647      {
1648         TabularDataSupport data = new TabularDataSupport(tabularType);
1649         CompositeData[] toPut = new CompositeData[] { compData, compData };
1650         try
1651         {
1652            data.putAll(toPut);
1653         }
1654         catch (KeyAlreadyExistsException expected)
1655         {
1656         }
1657         assertTrue("Nothing should be added for KeyAlreadyExistsException duplicates putAll(CompositeData[])", data.isEmpty());
1658      }
1659
1660      caught = false;
1661      try
1662      {
1663         TabularDataSupport data = new TabularDataSupport(tabularType);
1664         CompositeData[] toPut = new CompositeData[] { compData };
1665         data.putAll(toPut);
1666         data.putAll(toPut);
1667      }
1668      catch (KeyAlreadyExistsException e)
1669      {
1670         caught = true;
1671      }
1672      if (caught == false)
1673         fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) adding a duplicate");
1674
1675      {
1676         TabularDataSupport data = new TabularDataSupport(tabularType);
1677         CompositeData[] toPut = new CompositeData[] { compData };
1678         data.putAll(toPut);
1679         try
1680         {
1681            data.putAll(toPut);
1682         }
1683         catch (KeyAlreadyExistsException expected)
1684         {
1685         }
1686         assertTrue("Nothing should be added for KeyAlreadyExistsException already put putAll(CompositeData[])", data.size() == 1);
1687      }
1688   }
1689}
1690
Popular Tags