1 22 package org.jboss.test.jmx.compliance.openmbean; 23 24 import junit.framework.TestCase; 25 26 import java.io.ByteArrayInputStream ; 27 import java.io.ByteArrayOutputStream ; 28 import java.io.ObjectInputStream ; 29 import java.io.ObjectOutputStream ; 30 31 import javax.management.openmbean.ArrayType ; 32 import javax.management.openmbean.CompositeType ; 33 import javax.management.openmbean.OpenDataException ; 34 import javax.management.openmbean.OpenMBeanParameterInfoSupport ; 35 import javax.management.openmbean.OpenType ; 36 import javax.management.openmbean.SimpleType ; 37 import javax.management.openmbean.TabularDataSupport ; 38 import javax.management.openmbean.TabularType ; 39 40 45 public class OpenMBeanParameterInfoSupportTestCase 46 extends TestCase 47 { 48 50 52 54 57 public OpenMBeanParameterInfoSupportTestCase(String s) 58 { 59 super(s); 60 } 61 62 64 public void testOpenMBeanParameterInfoSupport() 65 throws Exception 66 { 67 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 68 "name", "description", SimpleType.STRING); 69 assertEquals("name", info.getName()); 70 assertEquals("description", info.getDescription()); 71 assertEquals("java.lang.String", info.getType()); 72 73 info = new OpenMBeanParameterInfoSupport ( 74 "name", "description", SimpleType.STRING, "default"); 75 assertEquals("name", info.getName()); 76 assertEquals("description", info.getDescription()); 77 assertEquals("java.lang.String", info.getType()); 78 assertEquals("default", info.getDefaultValue()); 79 assertEquals(true, info.hasDefaultValue()); 80 81 info = new OpenMBeanParameterInfoSupport ( 82 "name", "description", SimpleType.STRING, null); 83 assertEquals("name", info.getName()); 84 assertEquals("description", info.getDescription()); 85 assertEquals("java.lang.String", info.getType()); 86 assertEquals(null, info.getDefaultValue()); 87 assertEquals(false, info.hasDefaultValue()); 88 89 info = new OpenMBeanParameterInfoSupport ( 90 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 91 assertEquals("name", info.getName()); 92 assertEquals("description", info.getDescription()); 93 assertEquals("java.lang.Integer", info.getType()); 94 assertEquals(new Integer (3), info.getDefaultValue()); 95 assertEquals(new Integer (2), info.getMinValue()); 96 assertEquals(new Integer (4), info.getMaxValue()); 97 98 info = new OpenMBeanParameterInfoSupport ( 99 "name", "description", SimpleType.INTEGER, null, new Integer (2), new Integer (4)); 100 assertEquals("name", info.getName()); 101 assertEquals("description", info.getDescription()); 102 assertEquals("java.lang.Integer", info.getType()); 103 assertEquals(null, info.getDefaultValue()); 104 assertEquals(new Integer (2), info.getMinValue()); 105 assertEquals(new Integer (4), info.getMaxValue()); 106 107 info = new OpenMBeanParameterInfoSupport ( 108 "name", "description", SimpleType.INTEGER, new Integer (3), null, new Integer (4)); 109 assertEquals("name", info.getName()); 110 assertEquals("description", info.getDescription()); 111 assertEquals("java.lang.Integer", info.getType()); 112 assertEquals(new Integer (3), info.getDefaultValue()); 113 assertEquals(null, info.getMinValue()); 114 assertEquals(new Integer (4), info.getMaxValue()); 115 116 info = new OpenMBeanParameterInfoSupport ( 117 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), null); 118 assertEquals("name", info.getName()); 119 assertEquals("description", info.getDescription()); 120 assertEquals("java.lang.Integer", info.getType()); 121 assertEquals(new Integer (3), info.getDefaultValue()); 122 assertEquals(new Integer (2), info.getMinValue()); 123 assertEquals(null, info.getMaxValue()); 124 125 info = new OpenMBeanParameterInfoSupport ( 126 "name", "description", SimpleType.INTEGER, null, null, new Integer (4)); 127 assertEquals("name", info.getName()); 128 assertEquals("description", info.getDescription()); 129 assertEquals("java.lang.Integer", info.getType()); 130 assertEquals(null, info.getDefaultValue()); 131 assertEquals(null, info.getMinValue()); 132 assertEquals(new Integer (4), info.getMaxValue()); 133 134 info = new OpenMBeanParameterInfoSupport ( 135 "name", "description", SimpleType.INTEGER, null, new Integer (2), null); 136 assertEquals("name", info.getName()); 137 assertEquals("description", info.getDescription()); 138 assertEquals("java.lang.Integer", info.getType()); 139 assertEquals(null, info.getDefaultValue()); 140 assertEquals(new Integer (2), info.getMinValue()); 141 assertEquals(null, info.getMaxValue()); 142 143 info = new OpenMBeanParameterInfoSupport ( 144 "name", "description", SimpleType.INTEGER, new Integer (3), null, null); 145 assertEquals("name", info.getName()); 146 assertEquals("description", info.getDescription()); 147 assertEquals("java.lang.Integer", info.getType()); 148 assertEquals(new Integer (3), info.getDefaultValue()); 149 assertEquals(null, info.getMinValue()); 150 assertEquals(null, info.getMaxValue()); 151 152 info = new OpenMBeanParameterInfoSupport ( 153 "name", "description", SimpleType.INTEGER, null, null, null); 154 assertEquals("name", info.getName()); 155 assertEquals("description", info.getDescription()); 156 assertEquals("java.lang.Integer", info.getType()); 157 assertEquals(null, info.getDefaultValue()); 158 assertEquals(null, info.getMinValue()); 159 assertEquals(null, info.getMaxValue()); 160 161 info = new OpenMBeanParameterInfoSupport ( 162 "name", "description", SimpleType.STRING, "default", 163 new Object [] { "legal1", "legal2", "default" }); 164 assertEquals("name", info.getName()); 165 assertEquals("description", info.getDescription()); 166 assertEquals("java.lang.String", info.getType()); 167 assertEquals("default", info.getDefaultValue()); 168 assertEquals(3, info.getLegalValues().size()); 169 assertTrue("legal1 should be a legal value", info.getLegalValues().contains("legal1")); 170 assertTrue("legal2 should be a legal value", info.getLegalValues().contains("legal2")); 171 assertTrue("default should be a legal value", info.getLegalValues().contains("default")); 172 173 info = new OpenMBeanParameterInfoSupport ( 174 "name", "description", SimpleType.STRING, null, 175 new Object [] { "legal1", "legal2", "default" }); 176 assertEquals("name", info.getName()); 177 assertEquals("description", info.getDescription()); 178 assertEquals("java.lang.String", info.getType()); 179 assertEquals(null, info.getDefaultValue()); 180 assertEquals(3, info.getLegalValues().size()); 181 assertTrue("legal1 should be a legal value", info.getLegalValues().contains("legal1")); 182 assertTrue("legal2 should be a legal value", info.getLegalValues().contains("legal2")); 183 assertTrue("default should be a legal value", info.getLegalValues().contains("default")); 184 185 info = new OpenMBeanParameterInfoSupport ( 186 "name", "description", SimpleType.STRING, "default", null); 187 assertEquals("name", info.getName()); 188 assertEquals("description", info.getDescription()); 189 assertEquals("java.lang.String", info.getType()); 190 assertEquals("default", info.getDefaultValue()); 191 assertEquals(null, info.getLegalValues()); 192 193 info = new OpenMBeanParameterInfoSupport ( 194 "name", "description", SimpleType.STRING, null, null); 195 assertEquals("name", info.getName()); 196 assertEquals("description", info.getDescription()); 197 assertEquals("java.lang.String", info.getType()); 198 assertEquals(null, info.getDefaultValue()); 199 assertEquals(null, info.getLegalValues()); 200 } 201 202 public void testOpenType() 203 throws Exception 204 { 205 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 206 "name", "description", SimpleType.STRING); 207 assertEquals(SimpleType.STRING, info.getOpenType()); 208 } 209 210 public void testHas() 211 throws Exception 212 { 213 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 214 "name", "description", SimpleType.STRING, "default"); 215 assertEquals(true, info.hasDefaultValue()); 216 217 info = new OpenMBeanParameterInfoSupport ( 218 "name", "description", SimpleType.STRING, null); 219 assertEquals(false, info.hasDefaultValue()); 220 221 info = new OpenMBeanParameterInfoSupport ( 222 "name", "description", SimpleType.INTEGER, null, new Integer (3), null); 223 assertEquals(true, info.hasMinValue()); 224 225 info = new OpenMBeanParameterInfoSupport ( 226 "name", "description", SimpleType.INTEGER, null, null, null); 227 assertEquals(false, info.hasMinValue()); 228 229 info = new OpenMBeanParameterInfoSupport ( 230 "name", "description", SimpleType.INTEGER, null, null, new Integer (3)); 231 assertEquals(true, info.hasMaxValue()); 232 233 info = new OpenMBeanParameterInfoSupport ( 234 "name", "description", SimpleType.INTEGER, null, null, null); 235 assertEquals(false, info.hasMaxValue()); 236 237 info = new OpenMBeanParameterInfoSupport ( 238 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (3) }); 239 assertEquals(true, info.hasLegalValues()); 240 241 info = new OpenMBeanParameterInfoSupport ( 242 "name", "description", SimpleType.INTEGER, null, null); 243 assertEquals(false, info.hasLegalValues()); 244 } 245 246 public void testIsValue() 247 throws Exception 248 { 249 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 250 "name", "description", SimpleType.STRING); 251 assertTrue("String should be a value", info.isValue("string")); 252 assertTrue("Integer should not be a value", info.isValue(new Integer (3)) == false); 253 assertTrue("Null should not be a value", info.isValue(null) == false); 254 } 255 256 public void testEquals() 257 throws Exception 258 { 259 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 260 "name", "description", SimpleType.STRING); 261 262 assertTrue("Null should not be equal", info.equals(null) == false); 263 assertTrue("Only OpenMBeanParameterInfo should be equal", info.equals(new Object ()) == false); 264 265 OpenMBeanParameterInfoSupport info2 = new OpenMBeanParameterInfoSupport ( 266 "name", "description", SimpleType.STRING); 267 268 assertTrue("Different instances of the same data are equal", info.equals(info2)); 269 assertTrue("Different instances of the same data are equal", info2.equals(info)); 270 271 info2 = new OpenMBeanParameterInfoSupport ( 272 "name", "description2", SimpleType.STRING); 273 274 assertTrue("Different instances with different descriptions are equal", info.equals(info2)); 275 assertTrue("Different instances with different descritpions are equal", info2.equals(info)); 276 277 info2 = new OpenMBeanParameterInfoSupport ( 278 "name2", "description", SimpleType.STRING); 279 280 assertTrue("Instances with different names are not equal", info.equals(info2) == false); 281 assertTrue("Instances with different names are not equal", info2.equals(info) == false); 282 283 info2 = new OpenMBeanParameterInfoSupport ( 284 "name", "description", SimpleType.INTEGER); 285 286 assertTrue("Instances with different types are not equal", info.equals(info2) == false); 287 assertTrue("Instances with different types are not equal", info2.equals(info) == false); 288 289 info = new OpenMBeanParameterInfoSupport ( 290 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 291 info2 = new OpenMBeanParameterInfoSupport ( 292 "name", "description", SimpleType.INTEGER, new Integer (2), new Integer (2), new Integer (4)); 293 294 assertTrue("Instances with different default values are not equal", info.equals(info2) == false); 295 assertTrue("Instances with different default values are not equal", info2.equals(info) == false); 296 297 info = new OpenMBeanParameterInfoSupport ( 298 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 299 info2 = new OpenMBeanParameterInfoSupport ( 300 "name", "description", SimpleType.INTEGER, new Integer (2), null, new Integer (4)); 301 302 assertTrue("Instances with different default values are not equal", info.equals(info2) == false); 303 assertTrue("Instances with different default values are not equal", info2.equals(info) == false); 304 305 info = new OpenMBeanParameterInfoSupport ( 306 "name", "description", SimpleType.INTEGER, new Integer (3)); 307 info2 = new OpenMBeanParameterInfoSupport ( 308 "name", "description", SimpleType.INTEGER, new Integer (3)); 309 310 assertTrue("Different instances of the same default value are equal", info.equals(info2)); 311 assertTrue("Different instances of the same default value are equal", info2.equals(info)); 312 313 info = new OpenMBeanParameterInfoSupport ( 314 "name", "description", SimpleType.INTEGER, null, new Integer (2), null); 315 info2 = new OpenMBeanParameterInfoSupport ( 316 "name", "description", SimpleType.INTEGER, null, new Integer (2), null); 317 318 assertTrue("Different instances of the same minimum are equal", info.equals(info2)); 319 assertTrue("Different instances of the same minimum are equal", info2.equals(info)); 320 321 info = new OpenMBeanParameterInfoSupport ( 322 "name", "description", SimpleType.INTEGER, null, null, new Integer (2)); 323 info2 = new OpenMBeanParameterInfoSupport ( 324 "name", "description", SimpleType.INTEGER, null, null, new Integer (2)); 325 326 assertTrue("Different instances of the same maximum are equal", info.equals(info2)); 327 assertTrue("Different instances of the same maximum are equal", info2.equals(info)); 328 329 info = new OpenMBeanParameterInfoSupport ( 330 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 331 info2 = new OpenMBeanParameterInfoSupport ( 332 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (1), new Integer (4)); 333 334 assertTrue("Instances with different minimums are not equal", info.equals(info2) == false); 335 assertTrue("Instances with different minimums are not equal", info2.equals(info) == false); 336 337 info = new OpenMBeanParameterInfoSupport ( 338 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 339 info2 = new OpenMBeanParameterInfoSupport ( 340 "name", "description", SimpleType.INTEGER, new Integer (3), null, new Integer (4)); 341 342 assertTrue("Instances with different minimums are not equal", info.equals(info2) == false); 343 assertTrue("Instances with different minimums are not equal", info2.equals(info) == false); 344 345 info = new OpenMBeanParameterInfoSupport ( 346 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 347 info2 = new OpenMBeanParameterInfoSupport ( 348 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (5)); 349 350 assertTrue("Instances with different maximums are not equal", info.equals(info2) == false); 351 assertTrue("Instances with different maximums are not equal", info2.equals(info) == false); 352 353 info = new OpenMBeanParameterInfoSupport ( 354 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 355 info2 = new OpenMBeanParameterInfoSupport ( 356 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), null); 357 358 assertTrue("Instances with different maximums are not equal", info.equals(info2) == false); 359 assertTrue("Instances with different maximums are not equal", info2.equals(info) == false); 360 361 info = new OpenMBeanParameterInfoSupport ( 362 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (3) }); 363 info2 = new OpenMBeanParameterInfoSupport ( 364 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (3) }); 365 366 assertTrue("Different instances of the same legal values are equal", info.equals(info2)); 367 assertTrue("Different instances of the same legal values are equal", info2.equals(info)); 368 369 info = new OpenMBeanParameterInfoSupport ( 370 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (3) }); 371 info2 = new OpenMBeanParameterInfoSupport ( 372 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (4) }); 373 374 assertTrue("Different instances with different legal values are equal", info.equals(info2) == false); 375 assertTrue("Different instances with different legal values are equal", info2.equals(info) == false); 376 377 info = new OpenMBeanParameterInfoSupport ( 378 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (3) }); 379 info2 = new OpenMBeanParameterInfoSupport ( 380 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2) }); 381 382 assertTrue("Different instances with different legal values are equal", info.equals(info2) == false); 383 assertTrue("Different instances with different legal values are equal", info2.equals(info) == false); 384 385 info = new OpenMBeanParameterInfoSupport ( 386 "name", "description", SimpleType.INTEGER, null, new Object [] { new Integer (2), new Integer (3) }); 387 info2 = new OpenMBeanParameterInfoSupport ( 388 "name", "description", SimpleType.INTEGER, null, null); 389 390 assertTrue("Different instances with different legal values are equal", info.equals(info2) == false); 391 assertTrue("Different instances with different legal values are equal", info2.equals(info) == false); 392 } 393 394 public void testHashCode() 395 throws Exception 396 { 397 398 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 399 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 400 int myHash = "name".hashCode() + SimpleType.INTEGER.hashCode() + 401 new Integer (3).hashCode() + new Integer (2).hashCode() + new Integer (4).hashCode(); 402 assertEquals(myHash, info.hashCode()); 403 info = new OpenMBeanParameterInfoSupport ( 404 "name", "description", SimpleType.INTEGER, new Integer (3), 405 new Object [] { new Integer (2), new Integer (3), new Integer (4) } ); 406 myHash = "name".hashCode() + SimpleType.INTEGER.hashCode() + 407 new Integer (3).hashCode() + new Integer (2).hashCode() + new Integer (3).hashCode() + new Integer (4).hashCode(); 408 assertEquals(myHash, info.hashCode()); 409 } 410 411 public void testToString() 412 throws Exception 413 { 414 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 415 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 416 417 String toString = info.toString(); 418 assertTrue("info.toString() should contain the name", toString.indexOf("name") != -1); 419 assertTrue("info.toString() should contain the simple type", 420 toString.indexOf(SimpleType.INTEGER.toString()) != -1); 421 assertTrue("info.toString() should contain the default value", 422 toString.indexOf(new Integer (3).toString()) != -1); 423 assertTrue("info.toString() should contain the minimum value", 424 toString.indexOf(new Integer (2).toString()) != -1); 425 assertTrue("info.toString() should contain the maximum value", 426 toString.indexOf(new Integer (4).toString()) != -1); 427 428 info = new OpenMBeanParameterInfoSupport ( 429 "name", "description", SimpleType.INTEGER, new Integer (3), 430 new Object [] { new Integer (2), new Integer (3), new Integer (4) } ); 431 assertTrue("info.toString() should contain the legal value 2", 432 toString.indexOf(new Integer (2).toString()) != -1); 433 assertTrue("info.toString() should contain the legal value 3", 434 toString.indexOf(new Integer (3).toString()) != -1); 435 assertTrue("info.toString() should contain the legal value 4", 436 toString.indexOf(new Integer (4).toString()) != -1); 437 } 438 439 public void testSerialization() 440 throws Exception 441 { 442 OpenMBeanParameterInfoSupport info = new OpenMBeanParameterInfoSupport ( 443 "name", "description", SimpleType.INTEGER, new Integer (3), new Integer (2), new Integer (4)); 444 445 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 447 ObjectOutputStream oos = new ObjectOutputStream (baos); 448 oos.writeObject(info); 449 450 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 452 ObjectInputStream ois = new ObjectInputStream (bais); 453 Object result = ois.readObject(); 454 455 assertEquals(info, result); 456 457 info = new OpenMBeanParameterInfoSupport ( 458 "name", "description", SimpleType.INTEGER, new Integer (3), 459 new Object [] { new Integer (2), new Integer (3), new Integer (4) } ); 460 461 baos = new ByteArrayOutputStream (); 463 oos = new ObjectOutputStream (baos); 464 oos.writeObject(info); 465 466 bais = new ByteArrayInputStream (baos.toByteArray()); 468 ois = new ObjectInputStream (bais); 469 result = ois.readObject(); 470 471 assertEquals(info, result); 472 } 473 474 public void testErrors1() 475 throws Exception 476 { 477 boolean caught = false; 478 try 479 { 480 new OpenMBeanParameterInfoSupport ( 481 null, "description", SimpleType.INTEGER); 482 } 483 catch (IllegalArgumentException e) 484 { 485 caught = true; 486 } 487 if (caught == false) 488 fail("Expected IllegalArgumentException for null name"); 489 490 caught = false; 491 try 492 { 493 new OpenMBeanParameterInfoSupport ( 494 "", "description", SimpleType.INTEGER); 495 } 496 catch (IllegalArgumentException e) 497 { 498 caught = true; 499 } 500 if (caught == false) 501 fail("Expected IllegalArgumentException for an empty name"); 502 503 caught = false; 504 try 505 { 506 new OpenMBeanParameterInfoSupport ( 507 "name", null, SimpleType.INTEGER); 508 } 509 catch (IllegalArgumentException e) 510 { 511 caught = true; 512 } 513 if (caught == false) 514 fail("Expected IllegalArgumentException for null description"); 515 516 caught = false; 517 try 518 { 519 new OpenMBeanParameterInfoSupport ( 520 "name", "", SimpleType.INTEGER); 521 } 522 catch (IllegalArgumentException e) 523 { 524 caught = true; 525 } 526 if (caught == false) 527 fail("Expected IllegalArgumentException for an empty description"); 528 529 caught = false; 530 try 531 { 532 new OpenMBeanParameterInfoSupport ( 533 "", "description", SimpleType.INTEGER); 534 } 535 catch (IllegalArgumentException e) 536 { 537 caught = true; 538 } 539 if (caught == false) 540 fail("Expected IllegalArgumentException for an empty name"); 541 542 caught = false; 543 try 544 { 545 new OpenMBeanParameterInfoSupport ( 546 "name", "description", null); 547 } 548 catch (IllegalArgumentException e) 549 { 550 caught = true; 551 } 552 if (caught == false) 553 fail("Expected IllegalArgumentException for null simple type"); 554 } 555 556 public void testErrors2() 557 throws Exception 558 { 559 boolean caught = false; 560 try 561 { 562 new OpenMBeanParameterInfoSupport ( 563 null, "description", SimpleType.INTEGER, new Integer (3)); 564 } 565 catch (IllegalArgumentException e) 566 { 567 caught = true; 568 } 569 if (caught == false) 570 fail("Expected IllegalArgumentException for null name"); 571 572 caught = false; 573 try 574 { 575 new OpenMBeanParameterInfoSupport ( 576 "", "description", SimpleType.INTEGER, new Integer (3)); 577 } 578 catch (IllegalArgumentException e) 579 { 580 caught = true; 581 } 582 if (caught == false) 583 fail("Expected IllegalArgumentException for an empty name"); 584 585 caught = false; 586 try 587 { 588 new OpenMBeanParameterInfoSupport ( 589 "name", null, SimpleType.INTEGER, new Integer (3)); 590 } 591 catch (IllegalArgumentException e) 592 { 593 caught = true; 594 } 595 if (caught == false) 596 fail("Expected IllegalArgumentException for null description"); 597 598 caught = false; 599 try 600 { 601 new OpenMBeanParameterInfoSupport ( 602 "name", "", SimpleType.INTEGER, new Integer (3)); 603 } 604 catch (IllegalArgumentException e) 605 { 606 caught = true; 607 } 608 if (caught == false) 609 fail("Expected IllegalArgumentException for an empty description"); 610 611 caught = false; 612 try 613 { 614 new OpenMBeanParameterInfoSupport ( 615 "", "description", SimpleType.INTEGER, new Integer (3)); 616 } 617 catch (IllegalArgumentException e) 618 { 619 caught = true; 620 } 621 if (caught == false) 622 fail("Expected IllegalArgumentException for an empty name"); 623 624 caught = false; 625 try 626 { 627 new OpenMBeanParameterInfoSupport ( 628 "name", "description", null, new Integer (3)); 629 } 630 catch (IllegalArgumentException e) 631 { 632 caught = true; 633 } 634 if (caught == false) 635 fail("Expected IllegalArgumentException for null simple type"); 636 637 caught = false; 638 try 639 { 640 new OpenMBeanParameterInfoSupport ( 641 "name", "description", SimpleType.STRING, new Integer (3)); 642 } 643 catch (OpenDataException e) 644 { 645 caught = true; 646 } 647 if (caught == false) 648 fail("Expected OpenDataException for wrong simple type and default value"); 649 650 caught = false; 651 try 652 { 653 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 654 new OpenMBeanParameterInfoSupport ( 655 "name", "description", arrayType, new String [0]); 656 } 657 catch (OpenDataException e) 658 { 659 caught = true; 660 } 661 if (caught == false) 662 fail("Expected OpenDataException for array type and default value"); 663 664 caught = false; 665 try 666 { 667 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 668 new OpenMBeanParameterInfoSupport ( 669 "name", "description", arrayType, null); 670 } 671 catch (OpenDataException e) 672 { 673 caught = true; 674 } 675 if (caught == true) 676 fail("Didn't execpt OpenDataException for array type and no default value"); 677 678 caught = false; 679 try 680 { 681 String [] itemNames = new String [] { "name1", "name2" }; 682 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 683 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 684 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 685 itemNames, itemDescriptions, itemTypes); 686 687 String [] indexNames = new String [] { "name1", "name2" }; 688 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 689 TabularDataSupport data = new TabularDataSupport (tabularType); 690 691 new OpenMBeanParameterInfoSupport ( 692 "name", "description", tabularType, data); 693 } 694 catch (OpenDataException e) 695 { 696 caught = true; 697 } 698 if (caught == false) 699 fail("Expected OpenDataException for tabular type and default value"); 700 701 caught = false; 702 try 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 new OpenMBeanParameterInfoSupport ( 714 "name", "description", tabularType, null); 715 } 716 catch (OpenDataException e) 717 { 718 caught = true; 719 } 720 if (caught == true) 721 fail("Didn't execpt OpenDataException for tabular type and null default value"); 722 } 723 724 public void testErrors3() 725 throws Exception 726 { 727 boolean caught = false; 728 try 729 { 730 new OpenMBeanParameterInfoSupport ( 731 null, "description", SimpleType.INTEGER, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 732 } 733 catch (IllegalArgumentException e) 734 { 735 caught = true; 736 } 737 if (caught == false) 738 fail("Expected IllegalArgumentException for null name"); 739 740 caught = false; 741 try 742 { 743 new OpenMBeanParameterInfoSupport ( 744 "", "description", SimpleType.INTEGER, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 745 } 746 catch (IllegalArgumentException e) 747 { 748 caught = true; 749 } 750 if (caught == false) 751 fail("Expected IllegalArgumentException for an empty name"); 752 753 caught = false; 754 try 755 { 756 new OpenMBeanParameterInfoSupport ( 757 "name", null, SimpleType.INTEGER, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 758 } 759 catch (IllegalArgumentException e) 760 { 761 caught = true; 762 } 763 if (caught == false) 764 fail("Expected IllegalArgumentException for null description"); 765 766 caught = false; 767 try 768 { 769 new OpenMBeanParameterInfoSupport ( 770 "name", "", SimpleType.INTEGER, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 771 } 772 catch (IllegalArgumentException e) 773 { 774 caught = true; 775 } 776 if (caught == false) 777 fail("Expected IllegalArgumentException for an empty description"); 778 779 caught = false; 780 try 781 { 782 new OpenMBeanParameterInfoSupport ( 783 "", "description", SimpleType.INTEGER, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 784 } 785 catch (IllegalArgumentException e) 786 { 787 caught = true; 788 } 789 if (caught == false) 790 fail("Expected IllegalArgumentException for an empty name"); 791 792 caught = false; 793 try 794 { 795 new OpenMBeanParameterInfoSupport ( 796 "name", "description", null, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 797 } 798 catch (IllegalArgumentException e) 799 { 800 caught = true; 801 } 802 if (caught == false) 803 fail("Expected IllegalArgumentException for null simple type"); 804 805 caught = false; 806 try 807 { 808 new OpenMBeanParameterInfoSupport ( 809 "name", "description", SimpleType.STRING, new Integer (3), new Integer [] { new Integer (3), new Integer (4) }); 810 } 811 catch (OpenDataException e) 812 { 813 caught = true; 814 } 815 if (caught == false) 816 fail("Expected OpenDataException for wrong simple type and default value"); 817 818 caught = false; 819 try 820 { 821 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 822 new OpenMBeanParameterInfoSupport ( 823 "name", "description", arrayType, new String [0], null); 824 } 825 catch (OpenDataException e) 826 { 827 caught = true; 828 } 829 if (caught == false) 830 fail("Expected OpenDataException for array type and default value"); 831 832 caught = false; 833 try 834 { 835 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 836 new OpenMBeanParameterInfoSupport ( 837 "name", "description", arrayType, null, null); 838 } 839 catch (OpenDataException e) 840 { 841 caught = true; 842 } 843 if (caught == true) 844 fail("Didn't expect OpenDataException for array type and no default value and legals"); 845 846 caught = false; 847 try 848 { 849 String [] itemNames = new String [] { "name1", "name2" }; 850 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 851 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 852 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 853 itemNames, itemDescriptions, itemTypes); 854 855 String [] indexNames = new String [] { "name1", "name2" }; 856 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 857 TabularDataSupport data = new TabularDataSupport (tabularType); 858 859 new OpenMBeanParameterInfoSupport ( 860 "name", "description", tabularType, data, null); 861 } 862 catch (OpenDataException e) 863 { 864 caught = true; 865 } 866 if (caught == false) 867 fail("Expected OpenDataException for tabular type and default value"); 868 869 caught = false; 870 try 871 { 872 String [] itemNames = new String [] { "name1", "name2" }; 873 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 874 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 875 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 876 itemNames, itemDescriptions, itemTypes); 877 878 String [] indexNames = new String [] { "name1", "name2" }; 879 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 880 881 new OpenMBeanParameterInfoSupport ( 882 "name", "description", tabularType, null, null); 883 } 884 catch (OpenDataException e) 885 { 886 caught = true; 887 } 888 if (caught == true) 889 fail("Didn't expect OpenDataException for tabular type and null default value and legals"); 890 891 caught = false; 892 try 893 { 894 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 895 new OpenMBeanParameterInfoSupport ( 896 "name", "description", arrayType, null, new String [] { "hello", "goodbye" }); 897 } 898 catch (OpenDataException e) 899 { 900 caught = true; 901 } 902 if (caught == false) 903 fail("Expected OpenDataException for array type and default value"); 904 905 caught = false; 906 try 907 { 908 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 909 new OpenMBeanParameterInfoSupport ( 910 "name", "description", arrayType, null, new String [0]); 911 } 912 catch (OpenDataException e) 913 { 914 caught = true; 915 } 916 if (caught == true) 917 fail("Didn't expect OpenDataException for array type and no default value and empty legals"); 918 919 caught = false; 920 try 921 { 922 String [] itemNames = new String [] { "name1", "name2" }; 923 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 924 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 925 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 926 itemNames, itemDescriptions, itemTypes); 927 928 String [] indexNames = new String [] { "name1", "name2" }; 929 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 930 TabularDataSupport data = new TabularDataSupport (tabularType); 931 932 new OpenMBeanParameterInfoSupport ( 933 "name", "description", tabularType, null, new TabularDataSupport [] { data }); 934 } 935 catch (OpenDataException e) 936 { 937 caught = true; 938 } 939 if (caught == false) 940 fail("Expected OpenDataException for tabular type and legal values"); 941 942 caught = false; 943 try 944 { 945 String [] itemNames = new String [] { "name1", "name2" }; 946 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 947 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 948 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 949 itemNames, itemDescriptions, itemTypes); 950 951 String [] indexNames = new String [] { "name1", "name2" }; 952 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 953 954 new OpenMBeanParameterInfoSupport ( 955 "name", "description", tabularType, null, new TabularDataSupport [0]); 956 } 957 catch (OpenDataException e) 958 { 959 caught = true; 960 } 961 if (caught == true) 962 fail("Didn't expect OpenDataException for tabular type and null default value and empty legals"); 963 964 caught = false; 965 try 966 { 967 new OpenMBeanParameterInfoSupport ( 968 "name", "description", SimpleType.STRING, new Integer (3), new Integer [] { new Integer (2), new Integer (4) }); 969 } 970 catch (OpenDataException e) 971 { 972 caught = true; 973 } 974 if (caught == false) 975 fail("Expected OpenDataException for default value not a legal value"); 976 } 977 978 public void testErrors4() 979 throws Exception 980 { 981 boolean caught = false; 982 try 983 { 984 new OpenMBeanParameterInfoSupport ( 985 null, "description", SimpleType.INTEGER, new Integer (3), new Integer (3), new Integer (4)); 986 } 987 catch (IllegalArgumentException e) 988 { 989 caught = true; 990 } 991 if (caught == false) 992 fail("Expected IllegalArgumentException for null name"); 993 994 caught = false; 995 try 996 { 997 new OpenMBeanParameterInfoSupport ( 998 "", "description", SimpleType.INTEGER, new Integer (3), new Integer (3), new Integer (4)); 999 } 1000 catch (IllegalArgumentException e) 1001 { 1002 caught = true; 1003 } 1004 if (caught == false) 1005 fail("Expected IllegalArgumentException for an empty name"); 1006 1007 caught = false; 1008 try 1009 { 1010 new OpenMBeanParameterInfoSupport ( 1011 "name", null, SimpleType.INTEGER, new Integer (3), new Integer (3), new Integer (4)); 1012 } 1013 catch (IllegalArgumentException e) 1014 { 1015 caught = true; 1016 } 1017 if (caught == false) 1018 fail("Expected IllegalArgumentException for null description"); 1019 1020 caught = false; 1021 try 1022 { 1023 new OpenMBeanParameterInfoSupport ( 1024 "name", "", SimpleType.INTEGER, new Integer (3), new Integer (3), new Integer (4)); 1025 } 1026 catch (IllegalArgumentException e) 1027 { 1028 caught = true; 1029 } 1030 if (caught == false) 1031 fail("Expected IllegalArgumentException for an empty description"); 1032 1033 caught = false; 1034 try 1035 { 1036 new OpenMBeanParameterInfoSupport ( 1037 "", "description", SimpleType.INTEGER, new Integer (3), new Integer (3), new Integer (4)); 1038 } 1039 catch (IllegalArgumentException e) 1040 { 1041 caught = true; 1042 } 1043 if (caught == false) 1044 fail("Expected IllegalArgumentException for an empty name"); 1045 1046 caught = false; 1047 try 1048 { 1049 new OpenMBeanParameterInfoSupport ( 1050 "name", "description", null, new Integer (3), new Integer (3), new Integer (4)); 1051 } 1052 catch (IllegalArgumentException e) 1053 { 1054 caught = true; 1055 } 1056 if (caught == false) 1057 fail("Expected IllegalArgumentException for null simple type"); 1058 1059 caught = false; 1060 try 1061 { 1062 new OpenMBeanParameterInfoSupport ( 1063 "name", "description", SimpleType.STRING, new Integer (3), null, null); 1064 } 1065 catch (OpenDataException e) 1066 { 1067 caught = true; 1068 } 1069 if (caught == false) 1070 fail("Expected OpenDataException for wrong simple type and default value"); 1071 1072 caught = false; 1073 try 1074 { 1075 new OpenMBeanParameterInfoSupport ( 1076 "name", "description", SimpleType.STRING, null, new Integer (3), null); 1077 } 1078 catch (OpenDataException e) 1079 { 1080 caught = true; 1081 } 1082 if (caught == false) 1083 fail("Expected OpenDataException for wrong simple type and minimum value"); 1084 1085 caught = false; 1086 try 1087 { 1088 new OpenMBeanParameterInfoSupport ( 1089 "name", "description", SimpleType.STRING, null, null, new Integer (3)); 1090 } 1091 catch (OpenDataException e) 1092 { 1093 caught = true; 1094 } 1095 if (caught == false) 1096 fail("Expected OpenDataException for wrong simple type and maximum value"); 1097 1098 caught = false; 1099 try 1100 { 1101 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 1102 new OpenMBeanParameterInfoSupport ( 1103 "name", "description", arrayType, new String [0], null, null); 1104 } 1105 catch (OpenDataException e) 1106 { 1107 caught = true; 1108 } 1109 if (caught == false) 1110 fail("Expected OpenDataException for array type and default value"); 1111 1112 caught = false; 1113 try 1114 { 1115 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 1116 new OpenMBeanParameterInfoSupport ( 1117 "name", "description", arrayType, null, null, null); 1118 } 1119 catch (OpenDataException e) 1120 { 1121 caught = true; 1122 } 1123 if (caught == true) 1124 fail("Didn't expect OpenDataException for array type and no default value"); 1125 1126 caught = false; 1127 try 1128 { 1129 String [] itemNames = new String [] { "name1", "name2" }; 1130 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 1131 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 1132 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 1133 itemNames, itemDescriptions, itemTypes); 1134 1135 String [] indexNames = new String [] { "name1", "name2" }; 1136 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 1137 TabularDataSupport data = new TabularDataSupport (tabularType); 1138 1139 new OpenMBeanParameterInfoSupport ( 1140 "name", "description", tabularType, data, null, null); 1141 } 1142 catch (OpenDataException e) 1143 { 1144 caught = true; 1145 } 1146 if (caught == false) 1147 fail("Expected OpenDataException for tabular type and default value"); 1148 1149 caught = false; 1150 try 1151 { 1152 String [] itemNames = new String [] { "name1", "name2" }; 1153 String [] itemDescriptions = new String [] { "desc1", "desc2" }; 1154 OpenType [] itemTypes = new OpenType [] { SimpleType.STRING, SimpleType.INTEGER }; 1155 CompositeType rowType = new CompositeType ("rowTypeName", "rowDescription", 1156 itemNames, itemDescriptions, itemTypes); 1157 1158 String [] indexNames = new String [] { "name1", "name2" }; 1159 TabularType tabularType = new TabularType ("typeName", "description", rowType, indexNames); 1160 1161 new OpenMBeanParameterInfoSupport ( 1162 "name", "description", tabularType, null, null, null); 1163 } 1164 catch (OpenDataException e) 1165 { 1166 caught = true; 1167 } 1168 if (caught == true) 1169 fail("Didn't expect OpenDataException for tabular type and null default value"); 1170 1171 caught = false; 1172 try 1173 { 1174 ArrayType arrayType = new ArrayType (1, SimpleType.STRING); 1175 new OpenMBeanParameterInfoSupport ( 1176 "name", "description", arrayType, new String [] { "hello", "goodbye" }, null, null); 1177 } 1178 catch (OpenDataException e) 1179 { 1180 caught = true; 1181 } 1182 if (caught == false) 1183 fail("Expected OpenDataException for array type and default value"); 1184 1185 caught = false; 1186 try 1187 { 1188 new OpenMBeanParameterInfoSupport ( 1189 "name", "description", SimpleType.STRING, new Integer (3), new Integer (4), new Integer (5)); 1190 } 1191 catch (OpenDataException e) 1192 { 1193 caught = true; 1194 } 1195 if (caught == false) 1196 fail("Expected OpenDataException for default value less than minimum value"); 1197 1198 caught = false; 1199 try 1200 { 1201 new OpenMBeanParameterInfoSupport ( 1202 "name", "description", SimpleType.INTEGER, new Integer (4), new Integer (4), new Integer (5)); 1203 } 1204 catch (OpenDataException e) 1205 { 1206 caught = true; 1207 } 1208 if (caught == true) 1209 fail("Didn't expect OpenDataException for default value equal minimum value"); 1210 1211 caught = false; 1212 try 1213 { 1214 new OpenMBeanParameterInfoSupport ( 1215 "name", "description", SimpleType.INTEGER, new Integer (6), new Integer (4), new Integer (5)); 1216 } 1217 catch (OpenDataException e) 1218 { 1219 caught = true; 1220 } 1221 if (caught == false) 1222 fail("Expected OpenDataException for default value greater than maximum value"); 1223 1224 caught = false; 1225 try 1226 { 1227 new OpenMBeanParameterInfoSupport ( 1228 "name", "description", SimpleType.INTEGER, new Integer (5), new Integer (4), new Integer (5)); 1229 } 1230 catch (OpenDataException e) 1231 { 1232 caught = true; 1233 } 1234 if (caught == true) 1235 fail("Didn't expect OpenDataException for default value equal maximum value"); 1236 1237 caught = false; 1238 try 1239 { 1240 new OpenMBeanParameterInfoSupport ( 1241 "name", "description", SimpleType.INTEGER, null, new Integer (4), new Integer (3)); 1242 } 1243 catch (OpenDataException e) 1244 { 1245 caught = true; 1246 } 1247 if (caught == false) 1248 fail("Expected OpenDataException for minimum greater than maximum value"); 1249 1250 caught = false; 1251 try 1252 { 1253 new OpenMBeanParameterInfoSupport ( 1254 "name", "description", SimpleType.INTEGER, null, new Integer (4), new Integer (4)); 1255 } 1256 catch (OpenDataException e) 1257 { 1258 caught = true; 1259 } 1260 if (caught == true) 1261 fail("Didn't expect OpenDataException for minimum equal maximum value"); 1262 } 1263} 1264 | Popular Tags |