1 22 package org.jboss.test.mx.mxbean.test; 23 24 import javax.management.openmbean.CompositeData ; 25 import javax.management.openmbean.InvalidKeyException ; 26 27 import junit.framework.AssertionFailedError; 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 31 import org.jboss.mx.mxbean.CompositeDataInvocationHandler; 32 import org.jboss.test.mx.mxbean.support.InvalidInterface; 33 import org.jboss.test.mx.mxbean.support.SimpleInterface; 34 35 41 public class CompositeDataInvocationHandlerUnitTestCase extends AbstractMXBeanTest 42 { 43 public static Test suite() 44 { 45 return new TestSuite(CompositeDataInvocationHandlerUnitTestCase.class); 46 } 47 48 public CompositeDataInvocationHandlerUnitTestCase(String name) 49 { 50 super(name); 51 } 52 53 public void testGetCompositeData() throws Exception 54 { 55 CompositeData compositeData = createTestCompositeData(); 56 CompositeDataInvocationHandler test = new CompositeDataInvocationHandler(compositeData); 57 assertTrue(compositeData == test.getCompositeData()); 58 } 59 60 public void testNullCompositeData() throws Exception 61 { 62 try 63 { 64 new CompositeDataInvocationHandler(null); 65 fail("Should not be here"); 66 } 67 catch (AssertionFailedError e) 68 { 69 throw e; 70 } 71 catch (Throwable t) 72 { 73 checkThrowable(IllegalArgumentException .class, t); 74 } 75 } 76 77 public void testToEquals() throws Exception 78 { 79 SimpleInterface test1 = createTestCompositeDataProxy("Test1"); 80 81 assertFalse(test1.equals(null)); 82 assertFalse(test1.equals(new Object ())); 83 assertTrue(test1.equals(test1)); 84 85 SimpleInterface test2 = createTestCompositeDataProxy("Test2"); 86 87 assertFalse(test1.equals(test2)); 88 } 89 90 public void testHashCode() throws Exception 91 { 92 CompositeData compositeData = createTestCompositeData(); 93 SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData); 94 95 assertEquals(test.hashCode(), compositeData.hashCode()); 96 } 97 98 public void testToString() throws Exception 99 { 100 CompositeData compositeData = createTestCompositeData(); 101 SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData); 102 103 assertEquals(test.toString(), compositeData.toString()); 104 } 105 106 public void testGetSimpleTypes() throws Exception 107 { 108 SimpleInterface test = createTestCompositeDataProxy(); 109 assertEquals(SimpleInterface.bigDecimalValue, test.getBigDecimal()); 110 assertEquals(SimpleInterface.bigIntegerValue, test.getBigInteger()); 111 assertEquals(SimpleInterface.booleanValue, test.getBoolean()); 112 assertEquals(SimpleInterface.primitiveBooleanValue, test.isPrimitiveBoolean()); 113 assertEquals(SimpleInterface.byteValue, test.getByte()); 114 assertEquals(SimpleInterface.primitiveByteValue, test.getPrimitiveByte()); 115 assertEquals(SimpleInterface.characterValue, test.getCharacter()); 116 assertEquals(SimpleInterface.primitiveCharValue, test.getPrimitiveChar()); 117 assertEquals(SimpleInterface.dateValue, test.getDate()); 118 assertEquals(SimpleInterface.doubleValue, test.getDouble()); 119 assertEquals(SimpleInterface.primitiveDoubleValue, test.getPrimitiveDouble()); 120 assertEquals(SimpleInterface.floatValue, test.getFloat()); 121 assertEquals(SimpleInterface.primitiveFloatValue, test.getPrimitiveFloat()); 122 assertEquals(SimpleInterface.integerValue, test.getInteger()); 123 assertEquals(SimpleInterface.primitiveIntValue, test.getPrimitiveInt()); 124 assertEquals(SimpleInterface.longValue, test.getLong()); 125 assertEquals(SimpleInterface.primitiveLongValue, test.getPrimitiveLong()); 126 assertEquals(SimpleInterface.objectNameValue, test.getObjectName()); 127 assertEquals(SimpleInterface.shortValue, test.getShort()); 128 assertEquals(SimpleInterface.primitiveShortValue, test.getPrimitiveShort()); 129 assertEquals(SimpleInterface.stringValue, test.getString()); 130 } 131 132 public void testNullPrimitives() throws Exception 133 { 134 SimpleInterface test = createNullCompositeDataProxy(); 135 assertNull(test.getBigDecimal()); 136 assertNull(test.getBigInteger()); 137 assertNull(test.getBoolean()); 138 try 139 { 140 test.isPrimitiveBoolean(); 141 fail("Should not be here"); 142 } 143 catch (AssertionFailedError e) 144 { 145 throw e; 146 } 147 catch (Throwable t) 148 { 149 checkThrowableDeep(IllegalArgumentException .class, t); 150 } 151 assertNull(test.getByte()); 152 try 153 { 154 test.getPrimitiveByte(); 155 fail("Should not be here"); 156 } 157 catch (AssertionFailedError e) 158 { 159 throw e; 160 } 161 catch (Throwable t) 162 { 163 checkThrowableDeep(IllegalArgumentException .class, t); 164 } 165 assertNull(test.getCharacter()); 166 try 167 { 168 test.getPrimitiveChar(); 169 fail("Should not be here"); 170 } 171 catch (AssertionFailedError e) 172 { 173 throw e; 174 } 175 catch (Throwable t) 176 { 177 checkThrowableDeep(IllegalArgumentException .class, t); 178 } 179 assertNull(test.getDate()); 180 assertNull(test.getDouble()); 181 try 182 { 183 test.getPrimitiveDouble(); 184 fail("Should not be here"); 185 } 186 catch (AssertionFailedError e) 187 { 188 throw e; 189 } 190 catch (Throwable t) 191 { 192 checkThrowableDeep(IllegalArgumentException .class, t); 193 } 194 assertNull(test.getFloat()); 195 try 196 { 197 test.getPrimitiveFloat(); 198 fail("Should not be here"); 199 } 200 catch (AssertionFailedError e) 201 { 202 throw e; 203 } 204 catch (Throwable t) 205 { 206 checkThrowableDeep(IllegalArgumentException .class, t); 207 } 208 assertNull(test.getInteger()); 209 try 210 { 211 test.getPrimitiveInt(); 212 fail("Should not be here"); 213 } 214 catch (AssertionFailedError e) 215 { 216 throw e; 217 } 218 catch (Throwable t) 219 { 220 checkThrowableDeep(IllegalArgumentException .class, t); 221 } 222 assertNull(test.getLong()); 223 try 224 { 225 test.getPrimitiveLong(); 226 fail("Should not be here"); 227 } 228 catch (AssertionFailedError e) 229 { 230 throw e; 231 } 232 catch (Throwable t) 233 { 234 checkThrowableDeep(IllegalArgumentException .class, t); 235 } 236 assertNull(test.getObjectName()); 237 assertNull(test.getShort()); 238 try 239 { 240 test.getPrimitiveShort(); 241 fail("Should not be here"); 242 } 243 catch (AssertionFailedError e) 244 { 245 throw e; 246 } 247 catch (Throwable t) 248 { 249 checkThrowableDeep(IllegalArgumentException .class, t); 250 } 251 assertNull(SimpleInterface.stringValue, test.getString()); 252 } 253 254 public void testGetInvalid() throws Exception 255 { 256 InvalidInterface test = createInvalidCompositeDataProxy(); 257 try 258 { 259 test.getInvalid(); 260 fail("Should not be here"); 261 } 262 catch (AssertionFailedError e) 263 { 264 throw e; 265 } 266 catch (Throwable t) 267 { 268 checkThrowableDeep(IllegalArgumentException .class, InvalidKeyException .class, t); 269 } 270 } 271 272 public void testNotAGetter() throws Exception 273 { 274 InvalidInterface test = createInvalidCompositeDataProxy(); 275 try 276 { 277 test.notAGetter(); 278 fail("Should not be here"); 279 } 280 catch (AssertionFailedError e) 281 { 282 throw e; 283 } 284 catch (Throwable t) 285 { 286 checkThrowableDeep(IllegalArgumentException .class, t); 287 } 288 } 289 290 public void testGetNoReturnType() throws Exception 291 { 292 InvalidInterface test = createInvalidCompositeDataProxy(); 293 try 294 { 295 test.getString(); 296 fail("Should not be here"); 297 } 298 catch (AssertionFailedError e) 299 { 300 throw e; 301 } 302 catch (Throwable t) 303 { 304 checkThrowableDeep(IllegalArgumentException .class, t); 305 } 306 } 307 308 public void testGetWithParameters() throws Exception 309 { 310 InvalidInterface test = createInvalidCompositeDataProxy(); 311 try 312 { 313 test.getString(null); 314 fail("Should not be here"); 315 } 316 catch (AssertionFailedError e) 317 { 318 throw e; 319 } 320 catch (Throwable t) 321 { 322 checkThrowableDeep(IllegalArgumentException .class, t); 323 } 324 } 325 326 public void testIsNotBoolean() throws Exception 327 { 328 InvalidInterface test = createInvalidCompositeDataProxy(); 329 try 330 { 331 test.isString(); 332 fail("Should not be here"); 333 } 334 catch (AssertionFailedError e) 335 { 336 throw e; 337 } 338 catch (Throwable t) 339 { 340 checkThrowableDeep(IllegalArgumentException .class, t); 341 } 342 } 343 344 public void testIsBoolean() throws Exception 345 { 346 InvalidInterface test = createInvalidCompositeDataProxy(); 347 try 348 { 349 test.isBoolean(); 350 fail("Should not be here"); 351 } 352 catch (AssertionFailedError e) 353 { 354 throw e; 355 } 356 catch (Throwable t) 357 { 358 checkThrowableDeep(IllegalArgumentException .class, t); 359 } 360 } 361 } 362 | Popular Tags |