1 22 package org.jboss.test.jmx.compliance.openmbean; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectOutputStream ; 28 import java.util.Arrays ; 29 import java.util.Collection ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 import java.util.Set ; 33 34 import javax.management.openmbean.CompositeData ; 35 import javax.management.openmbean.CompositeDataSupport ; 36 import javax.management.openmbean.CompositeType ; 37 import javax.management.openmbean.InvalidKeyException ; 38 import javax.management.openmbean.InvalidOpenTypeException ; 39 import javax.management.openmbean.KeyAlreadyExistsException ; 40 import javax.management.openmbean.OpenType ; 41 import javax.management.openmbean.SimpleType ; 42 import javax.management.openmbean.TabularDataSupport ; 43 import javax.management.openmbean.TabularType ; 44 45 import junit.framework.TestCase; 46 47 52 public class TabularDataSupportTestCase 53 extends TestCase 54 { 55 57 59 61 64 public TabularDataSupportTestCase(String s) 65 { 66 super(s); 67 } 68 69 71 public void testTabularDataSupport() 72 throws Exception 73 { 74 String [] itemNames = new String [] { "name1", "name2" }; 75 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 76 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 77 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 78 itemNames, itemDescriptions, itemTypes); 79 80 String [] indexNames = new String [] { "name1", "name2" }; 81 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 82 83 new TabularDataSupport (tabularType); 84 new TabularDataSupport (tabularType, 100, .5f); 85 } 86 87 public void testGetTabularType() 88 throws Exception 89 { 90 String [] itemNames = new String [] { "name1", "name2" }; 91 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 92 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 93 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 94 itemNames, itemDescriptions, itemTypes); 95 96 String [] indexNames = new String [] { "name1", "name2" }; 97 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 98 99 TabularDataSupport data = new TabularDataSupport (tabularType); 100 assertTrue("Expected the same tabular type", data.getTabularType().equals(tabularType)); 101 } 102 103 public void testCalculateIndex() 104 throws Exception 105 { 106 String [] itemNames = new String [] { "name1", "name2" }; 107 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 108 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 109 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 110 itemNames, itemDescriptions, itemTypes); 111 112 String [] indexNames = new String [] { "name1", "name2" }; 113 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 114 115 TabularDataSupport data = new TabularDataSupport (tabularType); 116 117 HashMap map = new HashMap (); 118 map.put("name1", "value1"); 119 map.put("name2", new Integer (2)); 120 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 121 Object [] index = data.calculateIndex(compData); 122 123 assertTrue("Expected index element 0 to be value1", index[0].equals("value1")); 124 assertTrue("Expected index element 1 to be 2", index[1].equals(new Integer (2))); 125 126 map = new HashMap (); 127 map.put("name1", "value2"); 128 map.put("name2", new Integer (3)); 129 compData = new CompositeDataSupport (rowType, map); 130 index = data.calculateIndex(compData); 131 132 assertTrue("Expected index element 0 to be value2", index[0].equals("value2")); 133 assertTrue("Expected index element 1 to be 3", index[1].equals(new Integer (3))); 134 } 135 136 public void testContainsKeyObject() 137 throws Exception 138 { 139 String [] itemNames = new String [] { "name1", "name2" }; 140 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 141 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 142 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 143 itemNames, itemDescriptions, itemTypes); 144 145 String [] indexNames = new String [] { "name1", "name2" }; 146 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 147 148 TabularDataSupport data = new TabularDataSupport (tabularType); 149 150 assertTrue("Didn't expect containsKey null", data.containsKey(null) == false); 151 assertTrue("Didn't expect containsKey not an Object array", data.containsKey(new Object ()) == false); 152 153 Object [] index = new Object [] { "value1", new Integer (2) }; 154 assertTrue("Didn't expect containsKey on empty data", data.containsKey((Object ) index) == false); 155 156 HashMap map = new HashMap (); 157 map.put("name1", "value1"); 158 map.put("name2", new Integer (3)); 159 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 160 assertTrue("Didn't expect containsKey on index not present", data.containsKey((Object ) index) == false); 161 162 map = new HashMap (); 163 map.put("name1", "value1"); 164 map.put("name2", new Integer (2)); 165 compData = new CompositeDataSupport (rowType, map); 166 data.put(compData); 167 assertTrue("Expected containsKey", data.containsKey((Object ) index)); 168 169 map = new HashMap (); 170 map.put("name1", "value1"); 171 map.put("name2", new Integer (3)); 172 compData = new CompositeDataSupport (rowType, map); 173 assertTrue("Didn't expect containsKey on index still not present", 174 data.containsKey((Object ) data.calculateIndex(compData)) == false); 175 176 data.remove(index); 177 assertTrue("Didn't expect removed data in containsKey", data.containsKey((Object ) index) == false); 178 } 179 180 public void testContainsKeyObjectArray() 181 throws Exception 182 { 183 String [] itemNames = new String [] { "name1", "name2" }; 184 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 185 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 186 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 187 itemNames, itemDescriptions, itemTypes); 188 189 String [] indexNames = new String [] { "name1", "name2" }; 190 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 191 192 TabularDataSupport data = new TabularDataSupport (tabularType); 193 194 assertTrue("Didn't expect containsKey null", data.containsKey(null) == false); 195 assertTrue("Didn't expect containsKey not an Object array", data.containsKey(new Object ()) == false); 196 197 Object [] index = new Object [] { "value1", new Integer (2) }; 198 assertTrue("Didn't expect containsKey on empty data", data.containsKey(index) == false); 199 200 HashMap map = new HashMap (); 201 map.put("name1", "value1"); 202 map.put("name2", new Integer (3)); 203 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 204 assertTrue("Didn't expect containsKey on index not present", data.containsKey(index) == false); 205 206 map = new HashMap (); 207 map.put("name1", "value1"); 208 map.put("name2", new Integer (2)); 209 compData = new CompositeDataSupport (rowType, map); 210 data.put(compData); 211 assertTrue("Expected containsKey", data.containsKey(index)); 212 213 map = new HashMap (); 214 map.put("name1", "value1"); 215 map.put("name2", new Integer (3)); 216 compData = new CompositeDataSupport (rowType, map); 217 assertTrue("Didn't expect containsKey on index still not present", 218 data.containsKey(data.calculateIndex(compData)) == false); 219 220 data.remove(index); 221 assertTrue("Didn't expect removed data in containsKey", data.containsKey(index) == false); 222 } 223 224 public void testContainsValueObject() 225 throws Exception 226 { 227 String [] itemNames = new String [] { "name1", "name2" }; 228 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 229 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 230 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 231 itemNames, itemDescriptions, itemTypes); 232 233 String [] indexNames = new String [] { "name1", "name2" }; 234 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 235 236 TabularDataSupport data = new TabularDataSupport (tabularType); 237 238 assertTrue("Didn't expect containsValue null", data.containsValue(null) == false); 239 240 itemNames = new String [] { "name1", "name2" }; 241 itemDescriptions = new String [] { "desc1", "desc2" }; 242 itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 243 CompositeType rowType2 = new CompositeType ("rowTypeName2", "rowDescription", 244 itemNames, itemDescriptions, itemTypes); 245 246 HashMap map = new HashMap (); 247 map.put("name1", "value1"); 248 map.put("name2", new Integer (2)); 249 CompositeDataSupport compData2 = new CompositeDataSupport (rowType2, map); 250 251 assertTrue("Didn't expect containsValue wrong composite type", data.containsValue((Object ) compData2) == false); 252 253 map = new HashMap (); 254 map.put("name1", "value1"); 255 map.put("name2", new Integer (3)); 256 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 257 assertTrue("Didn't expect containsValue on data not present", data.containsValue((Object ) compData) == false); 258 259 map = new HashMap (); 260 map.put("name1", "value1"); 261 map.put("name2", new Integer (2)); 262 compData = new CompositeDataSupport (rowType, map); 263 data.put(compData); 264 assertTrue("Expected containsValue", data.containsValue((Object ) compData)); 265 266 map = new HashMap (); 267 map.put("name1", "value1"); 268 map.put("name2", new Integer (3)); 269 compData = new CompositeDataSupport (rowType, map); 270 assertTrue("Didn't expect containsValue on value still not present", data.containsValue((Object ) compData) == false); 271 272 assertTrue("Didn't expect containsValue still wrong composite type", data.containsValue((Object ) compData2) == false); 273 274 data.remove(data.calculateIndex(compData)); 275 assertTrue("Didn't expect removed data in containsValue", data.containsValue((Object ) compData) == false); 276 } 277 278 public void testContainsValueCompositeData() 279 throws Exception 280 { 281 String [] itemNames = new String [] { "name1", "name2" }; 282 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 283 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 284 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 285 itemNames, itemDescriptions, itemTypes); 286 287 String [] indexNames = new String [] { "name1", "name2" }; 288 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 289 290 TabularDataSupport data = new TabularDataSupport (tabularType); 291 292 assertTrue("Didn't expect containsValue null", data.containsValue(null) == false); 293 294 itemNames = new String [] { "name1", "name2" }; 295 itemDescriptions = new String [] { "desc1", "desc2" }; 296 itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 297 CompositeType rowType2 = new CompositeType ("rowTypeName2", "rowDescription", 298 itemNames, itemDescriptions, itemTypes); 299 300 HashMap map = new HashMap (); 301 map.put("name1", "value1"); 302 map.put("name2", new Integer (2)); 303 CompositeDataSupport compData2 = new CompositeDataSupport (rowType2, map); 304 305 assertTrue("Didn't expect containsValue wrong composite type", data.containsValue(compData2) == false); 306 307 map = new HashMap (); 308 map.put("name1", "value1"); 309 map.put("name2", new Integer (3)); 310 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 311 assertTrue("Didn't expect containsValue on data not present", data.containsValue(compData) == false); 312 313 map = new HashMap (); 314 map.put("name1", "value1"); 315 map.put("name2", new Integer (2)); 316 compData = new CompositeDataSupport (rowType, map); 317 data.put(compData); 318 assertTrue("Expected containsValue", data.containsValue(compData)); 319 320 map = new HashMap (); 321 map.put("name1", "value1"); 322 map.put("name2", new Integer (3)); 323 compData = new CompositeDataSupport (rowType, map); 324 assertTrue("Didn't expect containsValue on value still not present", data.containsValue(compData) == false); 325 326 assertTrue("Didn't expect containsValue still wrong composite type", data.containsValue(compData2) == false); 327 328 data.remove(data.calculateIndex(compData)); 329 assertTrue("Didn't expect removed data in containsValue", data.containsValue(compData) == false); 330 } 331 332 public void testGetObject() 333 throws Exception 334 { 335 String [] itemNames = new String [] { "name1", "name2" }; 336 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 337 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 338 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 339 itemNames, itemDescriptions, itemTypes); 340 341 String [] indexNames = new String [] { "name1", "name2" }; 342 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 343 344 TabularDataSupport data = new TabularDataSupport (tabularType); 345 346 Object [] index = new Object [] { "value1", new Integer (3) }; 347 assertTrue("Expected null for get on data not present", data.get((Object ) index) == null); 348 349 HashMap map = new HashMap (); 350 map.put("name1", "value1"); 351 map.put("name2", new Integer (2)); 352 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 353 index = new Object [] { "value1", new Integer (2) }; 354 data.put(compData); 355 assertTrue("Expected get to return the same value", data.get((Object ) index).equals(compData)); 356 357 index = new Object [] { "value1", new Integer (3) }; 358 assertTrue("Didn't expect get on value still not present", data.get((Object ) index) == null); 359 360 index = new Object [] { "value1", new Integer (2) }; 361 data.remove(index); 362 assertTrue("Didn't expect removed data in get", data.get((Object ) index) == null); 363 } 364 365 public void testGetObjectArray() 366 throws Exception 367 { 368 String [] itemNames = new String [] { "name1", "name2" }; 369 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 370 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 371 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 372 itemNames, itemDescriptions, itemTypes); 373 374 String [] indexNames = new String [] { "name1", "name2" }; 375 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 376 377 TabularDataSupport data = new TabularDataSupport (tabularType); 378 379 Object [] index = new Object [] { "value1", new Integer (3) }; 380 assertTrue("Expected null for get on data not present", data.get(index) == null); 381 382 HashMap map = new HashMap (); 383 map.put("name1", "value1"); 384 map.put("name2", new Integer (2)); 385 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 386 index = new Object [] { "value1", new Integer (2) }; 387 data.put(compData); 388 assertTrue("Expected get to return the same value", data.get(index).equals(compData)); 389 390 index = new Object [] { "value1", new Integer (3) }; 391 assertTrue("Didn't expect get on value still not present", data.get(index) == null); 392 393 index = new Object [] { "value1", new Integer (2) }; 394 data.remove(index); 395 assertTrue("Didn't expect removed data in get", data.get(index) == null); 396 } 397 398 public void testPutObjectObject() 399 throws Exception 400 { 401 String [] itemNames = new String [] { "name1", "name2" }; 402 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 403 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 404 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 405 itemNames, itemDescriptions, itemTypes); 406 407 String [] indexNames = new String [] { "name1", "name2" }; 408 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 409 410 TabularDataSupport data = new TabularDataSupport (tabularType); 411 412 HashMap map = new HashMap (); 413 map.put("name1", "value1"); 414 map.put("name2", new Integer (2)); 415 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 416 Object [] index = new Object [] { "value1", new Integer (2) }; 417 data.put(index, compData); 418 assertTrue("The data should be present after put", data.get(index).equals(compData)); 419 420 HashMap map2 = new HashMap (); 421 map2.put("name1", "value1"); 422 map2.put("name2", new Integer (3)); 423 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 424 index = new Object [] { "value1", new Integer (3) }; 425 data.put(index, compData2); 426 assertTrue("Another data should be present after put", data.get(index).equals(compData2)); 427 428 index = new Object [] { "value1", new Integer (2) }; 429 assertTrue("The previous data should be present after put", data.get(index).equals(compData)); 430 431 data.remove(index); 432 data.put(index, compData); 433 assertTrue("Data should be present after remove/put", data.get(index).equals(compData)); 434 435 HashMap map3 = new HashMap (); 436 map3.put("name1", "value1"); 437 map3.put("name2", new Integer (4)); 438 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 439 index = new Object [] { "value1", new Integer (4) }; 440 data.put(new Object (), compData3); 441 assertTrue("The key should be ignored in put", data.get(index).equals(compData3)); 442 } 443 444 public void testPutCompositeData() 445 throws Exception 446 { 447 String [] itemNames = new String [] { "name1", "name2" }; 448 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 449 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 450 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 451 itemNames, itemDescriptions, itemTypes); 452 453 String [] indexNames = new String [] { "name1", "name2" }; 454 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 455 456 TabularDataSupport data = new TabularDataSupport (tabularType); 457 458 HashMap map = new HashMap (); 459 map.put("name1", "value1"); 460 map.put("name2", new Integer (2)); 461 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 462 Object [] index = new Object [] { "value1", new Integer (2) }; 463 data.put(compData); 464 assertTrue("The data should be present after put", data.get(index).equals(compData)); 465 466 HashMap map2 = new HashMap (); 467 map2.put("name1", "value1"); 468 map2.put("name2", new Integer (3)); 469 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 470 index = new Object [] { "value1", new Integer (3) }; 471 data.put(compData2); 472 assertTrue("Another data should be present after put", data.get(index).equals(compData2)); 473 474 index = new Object [] { "value1", new Integer (2) }; 475 assertTrue("The previous data should be present after put", data.get(index).equals(compData)); 476 477 data.remove(index); 478 data.put(compData); 479 assertTrue("Data should be present after remove/put", data.get(index).equals(compData)); 480 } 481 482 public void testRemoveObject() 483 throws Exception 484 { 485 String [] itemNames = new String [] { "name1", "name2" }; 486 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 487 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 488 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 489 itemNames, itemDescriptions, itemTypes); 490 491 String [] indexNames = new String [] { "name1", "name2" }; 492 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 493 494 TabularDataSupport data = new TabularDataSupport (tabularType); 495 496 HashMap map = new HashMap (); 497 map.put("name1", "value1"); 498 map.put("name2", new Integer (2)); 499 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 500 Object [] index = new Object [] { "value1", new Integer (2) }; 501 502 assertTrue("Remove on data not present returns null", data.remove((Object ) index) == null); 503 504 data.put(compData); 505 assertTrue("Remove on data present returns the data", data.remove((Object ) index).equals(compData)); 506 } 507 508 public void testRemoveObjectArray() 509 throws Exception 510 { 511 String [] itemNames = new String [] { "name1", "name2" }; 512 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 513 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 514 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 515 itemNames, itemDescriptions, itemTypes); 516 517 String [] indexNames = new String [] { "name1", "name2" }; 518 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 519 520 TabularDataSupport data = new TabularDataSupport (tabularType); 521 522 HashMap map = new HashMap (); 523 map.put("name1", "value1"); 524 map.put("name2", new Integer (2)); 525 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 526 Object [] index = new Object [] { "value1", new Integer (2) }; 527 528 assertTrue("Remove on data not present returns null", data.remove(index) == null); 529 530 data.put(compData); 531 assertTrue("Remove on data present returns the data", data.remove(index).equals(compData)); 532 } 533 534 public void testPutAllMap() 535 throws Exception 536 { 537 String [] itemNames = new String [] { "name1", "name2" }; 538 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 539 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 540 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 541 itemNames, itemDescriptions, itemTypes); 542 543 String [] indexNames = new String [] { "name1", "name2" }; 544 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 545 546 TabularDataSupport data = new TabularDataSupport (tabularType); 547 548 data.putAll((Map ) null); 549 assertTrue("Put all null is ok", data.isEmpty()); 550 551 HashMap map = new HashMap (); 552 map.put("name1", "value1"); 553 map.put("name2", new Integer (2)); 554 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 555 556 HashMap toPut = new HashMap (); 557 toPut.put(new Object (), compData); 558 data.putAll(toPut); 559 assertTrue("Put all added one", data.size() == 1); 560 assertTrue("Put all added the correct data", data.containsValue(compData)); 561 562 HashMap map2 = new HashMap (); 563 map2.put("name1", "value1"); 564 map2.put("name2", new Integer (3)); 565 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 566 567 HashMap map3 = new HashMap (); 568 map3.put("name1", "value1"); 569 map3.put("name2", new Integer (4)); 570 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 571 572 toPut = new HashMap (); 573 toPut.put(new Object (), compData2); 574 toPut.put(new Object (), compData3); 575 data.putAll(toPut); 576 assertTrue("Put all added two", data.size() == 3); 577 assertTrue("Put all added the correct data", data.containsValue(compData2)); 578 assertTrue("Put all added the correct data", data.containsValue(compData3)); 579 assertTrue("Put all original data still present", data.containsValue(compData)); 580 } 581 582 public void testPutAllCompositeData() 583 throws Exception 584 { 585 String [] itemNames = new String [] { "name1", "name2" }; 586 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 587 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 588 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 589 itemNames, itemDescriptions, itemTypes); 590 591 String [] indexNames = new String [] { "name1", "name2" }; 592 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 593 594 TabularDataSupport data = new TabularDataSupport (tabularType); 595 596 data.putAll((CompositeData []) null); 597 assertTrue("Put all null is ok", data.isEmpty()); 598 599 HashMap map = new HashMap (); 600 map.put("name1", "value1"); 601 map.put("name2", new Integer (2)); 602 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 603 604 CompositeData [] toPut = new CompositeData [] { compData }; 605 data.putAll(toPut); 606 assertTrue("Put all added one", data.size() == 1); 607 assertTrue("Put all added the correct data", data.containsValue(compData)); 608 609 HashMap map2 = new HashMap (); 610 map2.put("name1", "value1"); 611 map2.put("name2", new Integer (3)); 612 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 613 614 HashMap map3 = new HashMap (); 615 map3.put("name1", "value1"); 616 map3.put("name2", new Integer (4)); 617 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 618 619 toPut = new CompositeData [] { compData2, compData3 }; 620 data.putAll(toPut); 621 assertTrue("Put all added two", data.size() == 3); 622 assertTrue("Put all added the correct data", data.containsValue(compData2)); 623 assertTrue("Put all added the correct data", data.containsValue(compData3)); 624 assertTrue("Put all original data still present", data.containsValue(compData)); 625 } 626 627 public void testClear() 628 throws Exception 629 { 630 String [] itemNames = new String [] { "name1", "name2" }; 631 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 632 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 633 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 634 itemNames, itemDescriptions, itemTypes); 635 636 String [] indexNames = new String [] { "name1", "name2" }; 637 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 638 639 TabularDataSupport data = new TabularDataSupport (tabularType); 640 641 data.putAll((CompositeData []) null); 642 assertTrue("Put all null is ok", data.isEmpty()); 643 644 HashMap map = new HashMap (); 645 map.put("name1", "value1"); 646 map.put("name2", new Integer (2)); 647 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 648 649 HashMap map2 = new HashMap (); 650 map2.put("name1", "value1"); 651 map2.put("name2", new Integer (3)); 652 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 653 654 HashMap map3 = new HashMap (); 655 map3.put("name1", "value1"); 656 map3.put("name2", new Integer (4)); 657 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 658 659 HashMap toPut = new HashMap (); 660 toPut.put(new Object (), compData); 661 toPut.put(new Object (), compData2); 662 toPut.put(new Object (), compData3); 663 data.putAll(toPut); 664 665 data.clear(); 666 assertTrue("Clear should clear the data", data.isEmpty()); 667 } 668 669 public void testSize() 670 throws Exception 671 { 672 String [] itemNames = new String [] { "name1", "name2" }; 673 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 674 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 675 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 676 itemNames, itemDescriptions, itemTypes); 677 678 String [] indexNames = new String [] { "name1", "name2" }; 679 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 680 681 TabularDataSupport data = new TabularDataSupport (tabularType); 682 683 assertTrue("Initial size is zero", data.size() == 0); 684 685 HashMap map = new HashMap (); 686 map.put("name1", "value1"); 687 map.put("name2", new Integer (2)); 688 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 689 690 CompositeData [] toPut = new CompositeData [] { compData }; 691 data.putAll(toPut); 692 assertTrue("Expected one element", data.size() == 1); 693 694 HashMap map2 = new HashMap (); 695 map2.put("name1", "value1"); 696 map2.put("name2", new Integer (3)); 697 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 698 699 HashMap map3 = new HashMap (); 700 map3.put("name1", "value1"); 701 map3.put("name2", new Integer (4)); 702 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 703 704 toPut = new CompositeData [] { compData2, compData3 }; 705 data.putAll(toPut); 706 assertTrue("Expected three elements", data.size() == 3); 707 708 data.remove(new Object [] { "value1", new Integer (4) }); 709 assertTrue("Expected two elements", data.size() == 2); 710 711 data.clear(); 712 assertTrue("Expected no elements", data.size() == 0); 713 } 714 715 public void testIsEmpty() 716 throws Exception 717 { 718 String [] itemNames = new String [] { "name1", "name2" }; 719 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 720 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 721 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 722 itemNames, itemDescriptions, itemTypes); 723 724 String [] indexNames = new String [] { "name1", "name2" }; 725 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 726 727 TabularDataSupport data = new TabularDataSupport (tabularType); 728 729 assertTrue("Initially empty", data.isEmpty()); 730 731 HashMap map = new HashMap (); 732 map.put("name1", "value1"); 733 map.put("name2", new Integer (2)); 734 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 735 736 CompositeData [] toPut = new CompositeData [] { compData }; 737 data.putAll(toPut); 738 assertTrue("Not empty after a put", data.isEmpty() == false); 739 740 data.clear(); 741 assertTrue("Expected no elements", data.isEmpty()); 742 } 743 744 747 public void testKeySet() 748 throws Exception 749 { 750 String [] itemNames = new String [] { "name1", "name2" }; 751 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 752 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 753 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 754 itemNames, itemDescriptions, itemTypes); 755 756 String [] indexNames = new String [] { "name1", "name2" }; 757 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 758 759 TabularDataSupport data = new TabularDataSupport (tabularType); 760 761 data.putAll((CompositeData []) null); 762 assertTrue("Put all null is ok", data.isEmpty()); 763 764 HashMap map = new HashMap (); 765 map.put("name1", "value1"); 766 map.put("name2", new Integer (2)); 767 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 768 769 HashMap map2 = new HashMap (); 770 map2.put("name1", "value1"); 771 map2.put("name2", new Integer (3)); 772 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 773 774 HashMap map3 = new HashMap (); 775 map3.put("name1", "value1"); 776 map3.put("name2", new Integer (4)); 777 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 778 779 HashMap toPut = new HashMap (); 780 toPut.put(new Object (), compData); 781 toPut.put(new Object (), compData2); 782 toPut.put(new Object (), compData3); 783 data.putAll(toPut); 784 785 Set keySet = data.keySet(); 786 assertTrue("Key set should contain 3 elements", keySet.size() == 3); 787 assertTrue("Key set should contain index [value1, 2]", 788 keySet.contains(Arrays.asList(new Object [] { "value1", new Integer (2) }))); 789 assertTrue("Key set should contain index [value1, 3]", 790 keySet.contains(Arrays.asList(new Object [] { "value1", new Integer (3) }))); 791 assertTrue("Key set should contain index [value1, 4]", 792 keySet.contains(Arrays.asList(new Object [] { "value1", new Integer (4) }))); 793 } 794 795 798 public void testValues() 799 throws Exception 800 { 801 String [] itemNames = new String [] { "name1", "name2" }; 802 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 803 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 804 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 805 itemNames, itemDescriptions, itemTypes); 806 807 String [] indexNames = new String [] { "name1", "name2" }; 808 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 809 810 TabularDataSupport data = new TabularDataSupport (tabularType); 811 812 data.putAll((CompositeData []) null); 813 assertTrue("Put all null is ok", data.isEmpty()); 814 815 HashMap map = new HashMap (); 816 map.put("name1", "value1"); 817 map.put("name2", new Integer (2)); 818 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 819 820 HashMap map2 = new HashMap (); 821 map2.put("name1", "value1"); 822 map2.put("name2", new Integer (3)); 823 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 824 825 HashMap map3 = new HashMap (); 826 map3.put("name1", "value1"); 827 map3.put("name2", new Integer (4)); 828 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 829 830 HashMap toPut = new HashMap (); 831 toPut.put(new Object (), compData); 832 toPut.put(new Object (), compData2); 833 toPut.put(new Object (), compData3); 834 data.putAll(toPut); 835 836 Collection values = data.values(); 837 assertTrue("Values should contain 3 elements", values.size() == 3); 838 assertTrue("Values should contain index compData", values.contains(compData)); 839 assertTrue("Values should contain index compData2", values.contains(compData2)); 840 assertTrue("Values should contain index compData3", values.contains(compData3)); 841 } 842 843 846 public void testEntrySet() 847 throws Exception 848 { 849 } 850 851 public void testClone() 852 throws Exception 853 { 854 String [] itemNames = new String [] { "name1", "name2" }; 855 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 856 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 857 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 858 itemNames, itemDescriptions, itemTypes); 859 860 String [] indexNames = new String [] { "name1", "name2" }; 861 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 862 863 TabularDataSupport data = new TabularDataSupport (tabularType); 864 865 data.putAll((CompositeData []) null); 866 assertTrue("Put all null is ok", data.isEmpty()); 867 868 HashMap map = new HashMap (); 869 map.put("name1", "value1"); 870 map.put("name2", new Integer (2)); 871 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 872 873 HashMap map2 = new HashMap (); 874 map2.put("name1", "value1"); 875 map2.put("name2", new Integer (3)); 876 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 877 878 HashMap map3 = new HashMap (); 879 map3.put("name1", "value1"); 880 map3.put("name2", new Integer (4)); 881 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 882 883 HashMap toPut = new HashMap (); 884 toPut.put(new Object (), compData); 885 toPut.put(new Object (), compData2); 886 toPut.put(new Object (), compData3); 887 data.putAll(toPut); 888 889 TabularDataSupport clone = (TabularDataSupport ) data.clone(); 890 assertTrue("Clone should have the same tabular type", data.getTabularType().equals(clone.getTabularType())); 891 assertTrue("Clone should have the same number of elements", data.size() == clone.size()); 892 CompositeData compDataClone = clone.get(new Object [] {"value1", new Integer (2) }); 893 assertTrue("Should be a shallow clone", compData == compDataClone); 894 } 895 896 public void testEquals() 897 throws Exception 898 { 899 String [] itemNames = new String [] { "name1", "name2" }; 900 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 901 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 902 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 903 itemNames, itemDescriptions, itemTypes); 904 905 String [] indexNames = new String [] { "name1", "name2" }; 906 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 907 908 TabularDataSupport data = new TabularDataSupport (tabularType); 909 910 assertTrue("Null should not be equal", data.equals(null) == false); 911 assertTrue("Only TabularData should be equal", data.equals(new Object ()) == false); 912 913 assertTrue("An instance should equal itself", data.equals(data)); 914 915 TabularDataSupport data2 = new TabularDataSupport (tabularType); 916 917 assertTrue("Two different instances with the same tabular type are equal", data.equals(data2)); 918 assertTrue("Two different instances with the same tabular type are equal", data2.equals(data)); 919 920 TabularType tabularType2 = new TabularType ("typeName2", "description", rowType, indexNames); 921 data2 = new TabularDataSupport (tabularType2); 922 923 assertTrue("Instances with different tabular type are not equal", data.equals(data2) == false); 924 assertTrue("Instances with different tabular type are not equal", data2.equals(data) == false); 925 926 HashMap map = new HashMap (); 927 map.put("name1", "value1"); 928 map.put("name2", new Integer (2)); 929 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 930 931 HashMap map2 = new HashMap (); 932 map2.put("name1", "value1"); 933 map2.put("name2", new Integer (3)); 934 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 935 936 HashMap map3 = new HashMap (); 937 map3.put("name1", "value1"); 938 map3.put("name2", new Integer (4)); 939 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 940 941 HashMap toPut = new HashMap (); 942 toPut.put(new Object (), compData); 943 toPut.put(new Object (), compData2); 944 toPut.put(new Object (), compData3); 945 946 data.putAll(toPut); 947 data2 = new TabularDataSupport (tabularType); 948 data2.putAll(toPut); 949 assertTrue("Instances with the same composite data are equal", data.equals(data2)); 950 assertTrue("Instances with the same composite data are equal", data2.equals(data)); 951 952 toPut = new HashMap (); 953 toPut.put(new Object (), compData); 954 toPut.put(new Object (), compData2); 955 data2 = new TabularDataSupport (tabularType); 956 data2.putAll(toPut); 957 assertTrue("Instances with different composite data are not equal", data.equals(data2) == false); 958 assertTrue("Instances with different composite data are not equal", data2.equals(data) == false); 959 } 960 961 public void testHashCode() 962 throws Exception 963 { 964 String [] itemNames = new String [] { "name1", "name2" }; 965 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 966 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 967 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 968 itemNames, itemDescriptions, itemTypes); 969 970 String [] indexNames = new String [] { "name1", "name2" }; 971 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 972 973 TabularDataSupport data = new TabularDataSupport (tabularType); 974 975 data.putAll((CompositeData []) null); 976 assertTrue("Put all null is ok", data.isEmpty()); 977 978 HashMap map = new HashMap (); 979 map.put("name1", "value1"); 980 map.put("name2", new Integer (2)); 981 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 982 983 HashMap map2 = new HashMap (); 984 map2.put("name1", "value1"); 985 map2.put("name2", new Integer (3)); 986 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 987 988 HashMap map3 = new HashMap (); 989 map3.put("name1", "value1"); 990 map3.put("name2", new Integer (4)); 991 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 992 993 HashMap toPut = new HashMap (); 994 toPut.put(new Object (), compData); 995 toPut.put(new Object (), compData2); 996 toPut.put(new Object (), compData3); 997 data.putAll(toPut); 998 999 int myHashCode = tabularType.hashCode() + compData.hashCode() + compData2.hashCode() + compData3.hashCode(); 1000 assertTrue("Wrong hash code generated", myHashCode == data.hashCode()); 1001 } 1002 1003 public void testToString() 1004 throws Exception 1005 { 1006 String [] itemNames = new String [] { "name1", "name2" }; 1007 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 1008 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 1009 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 1010 itemNames, itemDescriptions, itemTypes); 1011 1012 String [] indexNames = new String [] { "name1", "name2" }; 1013 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 1014 1015 TabularDataSupport data = new TabularDataSupport (tabularType); 1016 1017 data.putAll((CompositeData []) null); 1018 assertTrue("Put all null is ok", data.isEmpty()); 1019 1020 HashMap map = new HashMap (); 1021 map.put("name1", "value1"); 1022 map.put("name2", new Integer (2)); 1023 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 1024 1025 HashMap map2 = new HashMap (); 1026 map2.put("name1", "value1"); 1027 map2.put("name2", new Integer (3)); 1028 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 1029 1030 HashMap map3 = new HashMap (); 1031 map3.put("name1", "value1"); 1032 map3.put("name2", new Integer (4)); 1033 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 1034 1035 HashMap toPut = new HashMap (); 1036 toPut.put(new Object (), compData); 1037 toPut.put(new Object (), compData2); 1038 toPut.put(new Object (), compData3); 1039 data.putAll(toPut); 1040 1041 String toString = data.toString(); 1042 1043 assertTrue("toString() should contain the tabular type", 1044 toString.indexOf(tabularType.toString()) != -1); 1045 assertTrue("toString() should contain index=compositeData for compData", 1046 toString.indexOf(Arrays.asList(data.calculateIndex(compData)) + "=" + compData) != -1); 1047 assertTrue("toString() should contain index=compositeData for compData2", 1048 toString.indexOf(Arrays.asList(data.calculateIndex(compData2)) + "=" + compData2) != -1); 1049 assertTrue("toString() should contain index=compositeData for compData3", 1050 toString.indexOf(Arrays.asList(data.calculateIndex(compData3)) + "=" + compData3) != -1); 1051 } 1052 1053 public void testSerialization() 1054 throws Exception 1055 { 1056 String [] itemNames = new String [] { "name1", "name2" }; 1057 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 1058 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 1059 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 1060 itemNames, itemDescriptions, itemTypes); 1061 1062 String [] indexNames = new String [] { "name1", "name2" }; 1063 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 1064 1065 TabularDataSupport data = new TabularDataSupport (tabularType); 1066 1067 data.putAll((CompositeData []) null); 1068 assertTrue("Put all null is ok", data.isEmpty()); 1069 1070 HashMap map = new HashMap (); 1071 map.put("name1", "value1"); 1072 map.put("name2", new Integer (2)); 1073 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 1074 1075 HashMap map2 = new HashMap (); 1076 map2.put("name1", "value1"); 1077 map2.put("name2", new Integer (3)); 1078 CompositeDataSupport compData2 = new CompositeDataSupport (rowType, map2); 1079 1080 HashMap map3 = new HashMap (); 1081 map3.put("name1", "value1"); 1082 map3.put("name2", new Integer (4)); 1083 CompositeDataSupport compData3 = new CompositeDataSupport (rowType, map3); 1084 1085 HashMap toPut = new HashMap (); 1086 toPut.put(new Object (), compData); 1087 toPut.put(new Object (), compData2); 1088 toPut.put(new Object (), compData3); 1089 data.putAll(toPut); 1090 1091 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 1093 ObjectOutputStream oos = new ObjectOutputStream (baos); 1094 oos.writeObject(data); 1095 1096 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 1098 ObjectInputStream ois = new ObjectInputStream (bais); 1099 Object result = ois.readObject(); 1100 1101 assertEquals(data, result); 1102 } 1103 1104 public void testErrors() 1105 throws Exception 1106 { 1107 String [] itemNames = new String [] { "name1", "name2" }; 1108 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 1109 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 1110 1111 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 1112 itemNames, itemDescriptions, itemTypes); 1113 HashMap map = new HashMap (); 1114 map.put("name1", "value1"); 1115 map.put("name2", new Integer (2)); 1116 CompositeDataSupport compData = new CompositeDataSupport (rowType, map); 1117 1118 CompositeType rowType2 = new CompositeType ("rowTypeName2", "rowDescription", 1119 itemNames, itemDescriptions, itemTypes); 1120 CompositeDataSupport compData2 = new CompositeDataSupport (rowType2, map); 1121 1122 String [] indexNames = new String [] { "name1", "name2" }; 1123 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 1124 1125 boolean caught = false; 1126 try 1127 { 1128 new TabularDataSupport (null); 1129 } 1130 catch (IllegalArgumentException e) 1131 { 1132 caught = true; 1133 } 1134 if (caught == false) 1135 fail("Expected IllegalArgumentException for null tabular type"); 1136 1137 caught = false; 1138 try 1139 { 1140 new TabularDataSupport (null, 10, .5f); 1141 } 1142 catch (IllegalArgumentException e) 1143 { 1144 caught = true; 1145 } 1146 if (caught == false) 1147 fail("Expected IllegalArgumentException for null tabular type"); 1148 1149 caught = false; 1150 try 1151 { 1152 new TabularDataSupport (tabularType, -1, .5f); 1153 } 1154 catch (IllegalArgumentException e) 1155 { 1156 caught = true; 1157 } 1158 if (caught == false) 1159 fail("Expected IllegalArgumentException for negative initial capacity"); 1160 1161 caught = false; 1162 try 1163 { 1164 new TabularDataSupport (tabularType, 10, 0f); 1165 } 1166 catch (IllegalArgumentException e) 1167 { 1168 caught = true; 1169 } 1170 if (caught == false) 1171 fail("Expected IllegalArgumentException for zero load factor"); 1172 1173 caught = false; 1174 try 1175 { 1176 new TabularDataSupport (tabularType, 10, -0.5f); 1177 } 1178 catch (IllegalArgumentException e) 1179 { 1180 caught = true; 1181 } 1182 if (caught == false) 1183 fail("Expected IllegalArgumentException for negative load factor"); 1184 1185 caught = false; 1186 try 1187 { 1188 TabularDataSupport data = new TabularDataSupport (tabularType); 1189 data.calculateIndex(null); 1190 } 1191 catch (NullPointerException e) 1192 { 1193 caught = true; 1194 } 1195 if (caught == false) 1196 fail("Expected NullPointerException for calculate index on null object"); 1197 1198 caught = false; 1199 try 1200 { 1201 TabularDataSupport data = new TabularDataSupport (tabularType); 1202 data.calculateIndex(compData2); 1203 } 1204 catch (InvalidOpenTypeException e) 1205 { 1206 caught = true; 1207 } 1208 if (caught == false) 1209 fail("Expected InvalidOpenTypeException for calculate index on wrong composite type"); 1210 1211 caught = false; 1212 try 1213 { 1214 TabularDataSupport data = new TabularDataSupport (tabularType); 1215 data.get((Object ) null); 1216 } 1217 catch (NullPointerException e) 1218 { 1219 caught = true; 1220 } 1221 if (caught == false) 1222 fail("Expected NullPointerException for get((Object) null)"); 1223 1224 caught = false; 1225 try 1226 { 1227 TabularDataSupport data = new TabularDataSupport (tabularType); 1228 data.get(new Object ()); 1229 } 1230 catch (ClassCastException e) 1231 { 1232 caught = true; 1233 } 1234 if (caught == false) 1235 fail("Expected ClassCastException for get(new Object())"); 1236 1237 caught = false; 1238 try 1239 { 1240 TabularDataSupport data = new TabularDataSupport (tabularType); 1241 data.get((Object ) new Object [] { "wrong" }); 1242 } 1243 catch (InvalidKeyException e) 1244 { 1245 caught = true; 1246 } 1247 if (caught == false) 1248 fail("Expected InvalidKeyException for get(Object) wrong"); 1249 1250 caught = false; 1251 try 1252 { 1253 TabularDataSupport data = new TabularDataSupport (tabularType); 1254 data.get((Object []) null); 1255 } 1256 catch (NullPointerException e) 1257 { 1258 caught = true; 1259 } 1260 if (caught == false) 1261 fail("Expected NullPointerException for get((Object[]) null)"); 1262 1263 caught = false; 1264 try 1265 { 1266 TabularDataSupport data = new TabularDataSupport (tabularType); 1267 data.get(new Object [] { "wrong" }); 1268 } 1269 catch (InvalidKeyException e) 1270 { 1271 caught = true; 1272 } 1273 if (caught == false) 1274 fail("Expected InvalidKeyException for get(Object[]) wrong"); 1275 1276 caught = false; 1277 try 1278 { 1279 TabularDataSupport data = new TabularDataSupport (tabularType); 1280 data.put(new Object (), null); 1281 } 1282 catch (NullPointerException e) 1283 { 1284 caught = true; 1285 } 1286 if (caught == false) 1287 fail("Expected NullPointerException for put(Object, Object) with null value"); 1288 1289 caught = false; 1290 try 1291 { 1292 TabularDataSupport data = new TabularDataSupport (tabularType); 1293 data.put(new Object (), new Object ()); 1294 } 1295 catch (ClassCastException e) 1296 { 1297 caught = true; 1298 } 1299 if (caught == false) 1300 fail("Expected ClassCastException for put(Object, Object) with none CompositeData"); 1301 1302 caught = false; 1303 try 1304 { 1305 TabularDataSupport data = new TabularDataSupport (tabularType); 1306 data.put(new Object (), compData2); 1307 } 1308 catch (InvalidOpenTypeException e) 1309 { 1310 caught = true; 1311 } 1312 if (caught == false) 1313 fail("Expected InvalidOpenTypeException for put(Object, Object) with wrong CompositeType"); 1314 1315 caught = false; 1316 try 1317 { 1318 TabularDataSupport data = new TabularDataSupport (tabularType); 1319 data.put(new Object (), compData); 1320 data.put(new Object (), compData); 1321 } 1322 catch (KeyAlreadyExistsException e) 1323 { 1324 caught = true; 1325 } 1326 if (caught == false) 1327 fail("Expected KeyAlreadyExistsException for put(Object, Object)"); 1328 1329 caught = false; 1330 try 1331 { 1332 TabularDataSupport data = new TabularDataSupport (tabularType); 1333 data.put(null); 1334 } 1335 catch (NullPointerException e) 1336 { 1337 caught = true; 1338 } 1339 if (caught == false) 1340 fail("Expected NullPointerException for put(CompositeData) with null value"); 1341 1342 caught = false; 1343 try 1344 { 1345 TabularDataSupport data = new TabularDataSupport (tabularType); 1346 data.put(compData2); 1347 } 1348 catch (InvalidOpenTypeException e) 1349 { 1350 caught = true; 1351 } 1352 if (caught == false) 1353 fail("Expected InvalidOpenTypeException for put(CompositeData) with wrong CompositeType"); 1354 1355 caught = false; 1356 try 1357 { 1358 TabularDataSupport data = new TabularDataSupport (tabularType); 1359 data.put(compData); 1360 data.put(compData); 1361 } 1362 catch (KeyAlreadyExistsException e) 1363 { 1364 caught = true; 1365 } 1366 if (caught == false) 1367 fail("Expected KeyAlreadyExistsException for put(CompositeData)"); 1368 1369 caught = false; 1370 try 1371 { 1372 TabularDataSupport data = new TabularDataSupport (tabularType); 1373 data.remove((Object ) null); 1374 } 1375 catch (NullPointerException e) 1376 { 1377 caught = true; 1378 } 1379 if (caught == false) 1380 fail("Expected NullPointerException for remove((Object) null)"); 1381 1382 caught = false; 1383 try 1384 { 1385 TabularDataSupport data = new TabularDataSupport (tabularType); 1386 data.remove(new Object ()); 1387 } 1388 catch (ClassCastException e) 1389 { 1390 caught = true; 1391 } 1392 if (caught == false) 1393 fail("Expected ClassCastException for remove(new Object())"); 1394 1395 caught = false; 1396 try 1397 { 1398 TabularDataSupport data = new TabularDataSupport (tabularType); 1399 data.remove((Object ) new Object [] { "wrong" }); 1400 } 1401 catch (InvalidKeyException e) 1402 { 1403 caught = true; 1404 } 1405 if (caught == false) 1406 fail("Expected InvalidKeyException for remove(Object) wrong"); 1407 1408 caught = false; 1409 try 1410 { 1411 TabularDataSupport data = new TabularDataSupport (tabularType); 1412 data.remove((Object []) null); 1413 } 1414 catch (NullPointerException e) 1415 { 1416 caught = true; 1417 } 1418 if (caught == false) 1419 fail("Expected NullPointerException for remove((Object[]) null)"); 1420 1421 caught = false; 1422 try 1423 { 1424 TabularDataSupport data = new TabularDataSupport (tabularType); 1425 data.remove(new Object [] { "wrong" }); 1426 } 1427 catch (InvalidKeyException e) 1428 { 1429 caught = true; 1430 } 1431 if (caught == false) 1432 fail("Expected InvalidKeyException for remove(Object[]) wrong"); 1433 1434 caught = false; 1435 try 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 data.putAll(toPut); 1442 } 1443 catch (NullPointerException e) 1444 { 1445 caught = true; 1446 } 1447 if (caught == false) 1448 fail("Expected NullPointerException for putAll(Map) null"); 1449 1450 { 1451 TabularDataSupport data = new TabularDataSupport (tabularType); 1452 HashMap toPut = new HashMap (); 1453 toPut.put(new Object (), compData); 1454 toPut.put(new Object (), null); 1455 try 1456 { 1457 data.putAll(toPut); 1458 } 1459 catch (NullPointerException expected) 1460 { 1461 } 1462 assertTrue("Nothing should be added for NullPointerException putAll(Map)", data.isEmpty()); 1463 } 1464 1465 caught = false; 1466 try 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 data.putAll(toPut); 1473 } 1474 catch (ClassCastException e) 1475 { 1476 caught = true; 1477 } 1478 if (caught == false) 1479 fail("Expected ClassCastException for putAll(Map) non composite data"); 1480 1481 { 1482 TabularDataSupport data = new TabularDataSupport (tabularType); 1483 HashMap toPut = new HashMap (); 1484 toPut.put(new Object (), compData); 1485 toPut.put(new Object (), new Object ()); 1486 try 1487 { 1488 data.putAll(toPut); 1489 } 1490 catch (ClassCastException expected) 1491 { 1492 } 1493 assertTrue("Nothing should be added for ClassCastException putAll(Map)", data.isEmpty()); 1494 } 1495 1496 caught = false; 1497 try 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 data.putAll(toPut); 1504 } 1505 catch (InvalidOpenTypeException e) 1506 { 1507 caught = true; 1508 } 1509 if (caught == false) 1510 fail("Expected InvalidOpenTypeException for putAll(Map) wrong composite type"); 1511 1512 { 1513 TabularDataSupport data = new TabularDataSupport (tabularType); 1514 HashMap toPut = new HashMap (); 1515 toPut.put(new Object (), compData); 1516 toPut.put(new Object (), compData2); 1517 try 1518 { 1519 data.putAll(toPut); 1520 } 1521 catch (InvalidOpenTypeException expected) 1522 { 1523 } 1524 assertTrue("Nothing should be added for InvalidOpenTypeException putAll(Map)", data.isEmpty()); 1525 } 1526 1527 caught = false; 1528 try 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 data.putAll(toPut); 1535 } 1536 catch (KeyAlreadyExistsException e) 1537 { 1538 caught = true; 1539 } 1540 if (caught == false) 1541 fail("Expected InvalidOpenTypeException for putAll(Map) with duplicate data"); 1542 1543 { 1544 TabularDataSupport data = new TabularDataSupport (tabularType); 1545 HashMap toPut = new HashMap (); 1546 toPut.put(new Object (), compData); 1547 toPut.put(new Object (), compData); 1548 try 1549 { 1550 data.putAll(toPut); 1551 } 1552 catch (KeyAlreadyExistsException expected) 1553 { 1554 } 1555 assertTrue("Nothing should be added for KeyAlreadyExistsException duplicates putAll(Map)", data.isEmpty()); 1556 } 1557 1558 caught = false; 1559 try 1560 { 1561 TabularDataSupport data = new TabularDataSupport (tabularType); 1562 HashMap toPut = new HashMap (); 1563 toPut.put(new Object (), compData); 1564 data.putAll(toPut); 1565 toPut = new HashMap (); 1566 toPut.put(new Object (), compData); 1567 data.putAll(toPut); 1568 } 1569 catch (KeyAlreadyExistsException e) 1570 { 1571 caught = true; 1572 } 1573 if (caught == false) 1574 fail("Expected InvalidOpenTypeException for putAll(Map) adding a duplicate"); 1575 1576 { 1577 TabularDataSupport data = new TabularDataSupport (tabularType); 1578 HashMap toPut = new HashMap (); 1579 toPut.put(new Object (), compData); 1580 data.putAll(toPut); 1581 toPut = new HashMap (); 1582 toPut.put(new Object (), compData); 1583 try 1584 { 1585 data.putAll(toPut); 1586 } 1587 catch (KeyAlreadyExistsException expected) 1588 { 1589 } 1590 assertTrue("Nothing should be added for KeyAlreadyExistsException already put putAll(Map)", data.size() == 1); 1591 } 1592 1593 caught = false; 1594 try 1595 { 1596 TabularDataSupport data = new TabularDataSupport (tabularType); 1597 CompositeData [] toPut = new CompositeData [] { compData, null }; 1598 data.putAll(toPut); 1599 } 1600 catch (NullPointerException e) 1601 { 1602 caught = true; 1603 } 1604 if (caught == false) 1605 fail("Expected NullPointerException for putAll(CompositeData[]) null"); 1606 1607 { 1608 TabularDataSupport data = new TabularDataSupport (tabularType); 1609 CompositeData [] toPut = new CompositeData [] { compData, null }; 1610 try 1611 { 1612 data.putAll(toPut); 1613 } 1614 catch (NullPointerException expected) 1615 { 1616 } 1617 assertTrue("Nothing should be added for NullPointerException putAll(CompositeData[])", data.isEmpty()); 1618 } 1619 1620 caught = false; 1621 try 1622 { 1623 TabularDataSupport data = new TabularDataSupport (tabularType); 1624 CompositeData [] toPut = new CompositeData [] { compData, compData2 }; 1625 data.putAll(toPut); 1626 } 1627 catch (InvalidOpenTypeException e) 1628 { 1629 caught = true; 1630 } 1631 if (caught == false) 1632 fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) wrong composite type"); 1633 1634 { 1635 TabularDataSupport data = new TabularDataSupport (tabularType); 1636 CompositeData [] toPut = new CompositeData [] { compData, compData2 }; 1637 try 1638 { 1639 data.putAll(toPut); 1640 } 1641 catch (InvalidOpenTypeException expected) 1642 { 1643 } 1644 assertTrue("Nothing should be added for InvalidOpenTypeException putAll(CompositeData[])", data.isEmpty()); 1645 } 1646 1647 caught = false; 1648 try 1649 { 1650 TabularDataSupport data = new TabularDataSupport (tabularType); 1651 CompositeData [] toPut = new CompositeData [] { compData, compData }; 1652 data.putAll(toPut); 1653 } 1654 catch (KeyAlreadyExistsException e) 1655 { 1656 caught = true; 1657 } 1658 if (caught == false) 1659 fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) with duplicate data"); 1660 1661 { 1662 TabularDataSupport data = new TabularDataSupport (tabularType); 1663 CompositeData [] toPut = new CompositeData [] { compData, compData }; 1664 try 1665 { 1666 data.putAll(toPut); 1667 } 1668 catch (KeyAlreadyExistsException expected) 1669 { 1670 } 1671 assertTrue("Nothing should be added for KeyAlreadyExistsException duplicates putAll(CompositeData[])", data.isEmpty()); 1672 } 1673 1674 caught = false; 1675 try 1676 { 1677 TabularDataSupport data = new TabularDataSupport (tabularType); 1678 CompositeData [] toPut = new CompositeData [] { compData }; 1679 data.putAll(toPut); 1680 data.putAll(toPut); 1681 } 1682 catch (KeyAlreadyExistsException e) 1683 { 1684 caught = true; 1685 } 1686 if (caught == false) 1687 fail("Expected InvalidOpenTypeException for putAll(CompositeData[]) adding a duplicate"); 1688 1689 { 1690 TabularDataSupport data = new TabularDataSupport (tabularType); 1691 CompositeData [] toPut = new CompositeData [] { compData }; 1692 data.putAll(toPut); 1693 try 1694 { 1695 data.putAll(toPut); 1696 } 1697 catch (KeyAlreadyExistsException expected) 1698 { 1699 } 1700 assertTrue("Nothing should be added for KeyAlreadyExistsException already put putAll(CompositeData[])", data.size() == 1); 1701 } 1702 } 1703} 1704 | Popular Tags |