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