1 22 package org.jboss.test.jmx.compliance.metadata; 23 24 25 import java.lang.reflect.Method ; 26 27 import javax.management.MBeanOperationInfo ; 28 import javax.management.MBeanParameterInfo ; 29 30 import junit.framework.AssertionFailedError; 31 import junit.framework.TestCase; 32 33 39 public class MBeanOperationInfoTEST extends TestCase 40 { 41 public MBeanOperationInfoTEST(String s) 42 { 43 super(s); 44 } 45 46 49 public void testConstructorWithMethod() 50 { 51 try 52 { 53 Class c = this.getClass(); 54 Method m = c.getMethod("testConstructorWithMethod", new Class [0]); 55 56 MBeanOperationInfo info = new MBeanOperationInfo ("This is a description.", m); 57 58 assertTrue(info.getDescription().equals("This is a description.")); 59 assertTrue(info.getName().equals(m.getName())); 60 assertTrue(info.getReturnType().equals("void")); 61 assertTrue(info.getSignature().length == 0); 62 assertTrue(info.getImpact() == MBeanOperationInfo.UNKNOWN); 63 } 64 catch (AssertionFailedError e) 65 { 66 throw e; 67 } 68 catch (Throwable t) 69 { 70 t.printStackTrace(); 71 fail("Unexpected error: " + t.toString()); 72 } 73 } 74 75 78 public void testConstructor() 79 { 80 try 81 { 82 MBeanOperationInfo info = new MBeanOperationInfo ( 83 "MyOperation", 84 "This is a description.", 85 new MBeanParameterInfo [] { 86 new MBeanParameterInfo ("FooParam", "java.lang.Object", "description"), 87 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 88 }, 89 "java.util.StringBuffer", 90 MBeanOperationInfo.INFO 91 ); 92 93 assertTrue(info.getDescription().equals("This is a description.")); 94 assertTrue(info.getName().equals("MyOperation")); 95 assertTrue(info.getReturnType().equals("java.util.StringBuffer")); 96 assertTrue(info.getSignature().length == 2); 97 assertTrue(info.getImpact() == MBeanOperationInfo.INFO); 98 assertTrue(info.getSignature() [0].getName().equals("FooParam")); 99 assertTrue(info.getSignature() [1].getName().equals("BarParam")); 100 assertTrue(info.getSignature() [0].getDescription().equals("description")); 101 assertTrue(info.getSignature() [1].getDescription().equals("description")); 102 assertTrue(info.getSignature() [0].getType().equals("java.lang.Object")); 103 assertTrue(info.getSignature() [1].getType().equals("java.lang.String")); 104 105 } 106 catch (AssertionFailedError e) 107 { 108 throw e; 109 } 110 catch (Throwable t) 111 { 112 t.printStackTrace(); 113 fail("Unexpected error: " + t.toString()); 114 } 115 } 116 117 120 public void testClone() 121 { 122 try 123 { 124 MBeanOperationInfo info = new MBeanOperationInfo ( 125 "MyOperation", 126 "This is a description.", 127 new MBeanParameterInfo [] { 128 new MBeanParameterInfo ("FooParam", "java.lang.Object", "description"), 129 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 130 }, 131 "java.util.StringBuffer", 132 MBeanOperationInfo.ACTION_INFO 133 ); 134 135 MBeanOperationInfo clone = (MBeanOperationInfo )info.clone(); 136 137 assertTrue(clone.getDescription().equals("This is a description.")); 138 assertTrue(clone.getName().equals("MyOperation")); 139 assertTrue(clone.getReturnType().equals("java.util.StringBuffer")); 140 assertTrue(clone.getSignature().length == 2); 141 assertTrue(clone.getImpact() == MBeanOperationInfo.ACTION_INFO); 142 assertTrue(clone.getSignature() [0].getName().equals("FooParam")); 143 assertTrue(clone.getSignature() [1].getName().equals("BarParam")); 144 assertTrue(clone.getSignature() [0].getDescription().equals("description")); 145 assertTrue(clone.getSignature() [1].getDescription().equals("description")); 146 assertTrue(clone.getSignature() [0].getType().equals("java.lang.Object")); 147 assertTrue(clone.getSignature() [1].getType().equals("java.lang.String")); 148 149 } 150 catch (AssertionFailedError e) 151 { 152 throw e; 153 } 154 catch (Throwable t) 155 { 156 t.printStackTrace(); 157 fail("Unexpected error: " + t.toString()); 158 } 159 } 160 161 164 public void testGetDescriptionNull() 165 { 166 try 167 { 168 MBeanOperationInfo info1 = new MBeanOperationInfo ( 169 "SomeName", 170 null, 171 new MBeanParameterInfo [] { 172 new MBeanParameterInfo ("FooParam", "java.lang.Object", "description"), 173 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 174 }, 175 "java.util.StringBuffer", 176 MBeanOperationInfo.ACTION_INFO 177 ); 178 179 assertTrue(info1.getDescription() == null); 180 181 } 182 catch (AssertionFailedError e) 183 { 184 throw e; 185 } 186 catch (Throwable t) 187 { 188 t.printStackTrace(); 189 fail("Unexpected error: " + t.toString()); 190 } 191 } 192 193 196 public void testGetImpactInvalid() 197 { 198 try 199 { 200 MBeanOperationInfo info1 = new MBeanOperationInfo ( 201 "SomeName", 202 "some description", 203 new MBeanParameterInfo [] { 204 new MBeanParameterInfo ("FooParam", "java.lang.Object", "description"), 205 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 206 }, 207 "java.util.StringBuffer", 208 -22342 209 ); 210 211 if (info1.getImpact() != MBeanOperationInfo.ACTION) 214 if (info1.getImpact() != MBeanOperationInfo.INFO) 215 if (info1.getImpact() != MBeanOperationInfo.ACTION_INFO) 216 if (info1.getImpact() != MBeanOperationInfo.UNKNOWN) 217 218 fail("FAILS IN RI: MBeanOperation.getImpact() is only allowed to return values that match either ACTION, ACTION_INFO, INFO or UNKNOWN constant values."); 223 224 fail("ERROR IN TEST: invalid impact value test does not work correctly."); 226 } 227 catch (AssertionFailedError e) 228 { 229 throw e; 230 } 231 catch (Exception e) 232 { 233 return; 234 } 235 fail("Invalid impact"); 236 } 237 238 241 public void testGetSignatureNull() 242 { 243 try 244 { 245 MBeanOperationInfo info1 = new MBeanOperationInfo ( 246 "SomeName", 247 "some description", 248 null, 249 "java.util.StringBuffer", 250 MBeanOperationInfo.ACTION 251 ); 252 253 assertTrue(info1.getSignature().length == 0); 254 255 } 256 catch (AssertionFailedError e) 257 { 258 throw e; 259 } 260 catch (Throwable t) 261 { 262 t.printStackTrace(); 263 fail("Unexpected error: " + t.toString()); 264 } 265 } 266 267 270 public void testGetSignatureEmpty() 271 { 272 try 273 { 274 MBeanOperationInfo info1 = new MBeanOperationInfo ( 275 "SomeName", 276 "some description", 277 new MBeanParameterInfo [0], 278 "java.util.StringBuffer", 279 MBeanOperationInfo.ACTION 280 ); 281 282 assertTrue(info1.getSignature().length == 0); 283 284 } 285 catch (AssertionFailedError e) 286 { 287 throw e; 288 } 289 catch (Throwable t) 290 { 291 t.printStackTrace(); 292 fail("Unexpected error: " + t.toString()); 293 } 294 } 295 296 299 public void testGetReturnTypeEmpty() 300 { 301 try 302 { 303 new MBeanOperationInfo ( 304 "SomeName", 305 "some description", 306 new MBeanParameterInfo [0], 307 "", 308 MBeanOperationInfo.ACTION 309 ); 310 } 311 catch (Exception e) 312 { 313 return; 314 } 315 fail("An empty return type is not a valid java identifier"); 316 } 317 318 319 322 public void testGetReturnTypeNull() 323 { 324 try 325 { 326 new MBeanOperationInfo ( 327 "SomeName", 328 "some description", 329 new MBeanParameterInfo [0], 330 "", 331 MBeanOperationInfo.ACTION 332 ); 333 } 334 catch (Exception e) 335 { 336 return; 337 } 338 fail("A null return type is not a valid java identifier"); 339 } 340 341 public void testGetReturnTypeInvalid() 342 { 343 try 344 { 345 new MBeanOperationInfo ( 346 "SomeName", 347 "some description", 348 new MBeanParameterInfo [0], 349 "invalid type", 350 MBeanOperationInfo.ACTION 351 ); 352 } 353 catch (Exception e) 354 { 355 return; 356 } 357 fail("'invalid type' return type is not a valid java identifier"); 358 } 359 } 360 | Popular Tags |