1 22 package org.jboss.test.jmx.compliance.modelmbean; 23 24 import javax.management.Descriptor ; 25 import javax.management.MBeanOperationInfo ; 26 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 27 import javax.management.modelmbean.ModelMBeanConstructorInfo ; 28 import javax.management.modelmbean.ModelMBeanInfo ; 29 import javax.management.modelmbean.ModelMBeanInfoSupport ; 30 import javax.management.modelmbean.ModelMBeanOperationInfo ; 31 import javax.management.modelmbean.RequiredModelMBean ; 32 33 import junit.framework.AssertionFailedError; 34 import junit.framework.TestCase; 35 36 37 public class ModelMBeanInfoSupportTEST extends TestCase 38 { 39 public ModelMBeanInfoSupportTEST(String s) 40 { 41 super(s); 42 } 43 44 public void testSetDescriptors() throws Exception 45 { 46 final boolean READABLE = true; 47 final boolean WRITABLE = true; 48 final boolean ISIS = true; 49 50 RequiredModelMBean mbean = new RequiredModelMBean (); 51 52 ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo ( 53 "Kissa", 54 String .class.getName(), 55 "Some attribute description", 56 !READABLE, !WRITABLE, !ISIS 57 ); 58 59 ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo ( 60 "Koira", 61 String .class.getName(), 62 "Another attribute description", 63 !READABLE, !WRITABLE, !ISIS 64 ); 65 66 ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo ( 67 "FirstConstructor", 68 "Description of the first constructor", 69 null 70 ); 71 72 ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo ( 73 "SecondConstructor", 74 "Description of the second constructor", 75 null 76 ); 77 78 ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo ( 79 "ThirdConstructor", 80 "Description of the 3rd constructor", 81 null 82 ); 83 84 ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo ( 85 "AnOperation", 86 "The description", 87 null, 88 "AType", 89 MBeanOperationInfo.ACTION 90 ); 91 92 ModelMBeanInfoSupport info = new ModelMBeanInfoSupport ( 93 mbean.getClass().getName(), 94 "some description", 95 new ModelMBeanAttributeInfo [] { attr1, attr2 }, 96 new ModelMBeanConstructorInfo [] { constr1, constr2, constr3 }, 97 new ModelMBeanOperationInfo [] { operation }, 98 null 99 ); 100 101 Descriptor descr1 = info.getDescriptor("SecondConstructor", "constructor"); 102 103 assertEquals("SecondConstructor", descr1.getFieldValue("name")); 104 assertEquals("constructor", descr1.getFieldValue("role")); 105 106 Descriptor descr2 = null; 107 108 Descriptor [] descr3 = info.getDescriptors("operation"); 109 110 assertEquals("operation", descr3[0].getFieldValue("descriptorType")); 111 assertEquals("AnOperation", descr3[0].getFieldValue("name")); 112 113 descr1.setField("someField", "someValue"); 114 descr3[0].setField("Yksi", "Kaksi"); 115 116 info.setDescriptors(new Descriptor [] { descr1, descr2, descr3[0] }); 117 118 descr1 = info.getDescriptor("SecondConstructor", "constructor"); 119 assertEquals("SecondConstructor", descr1.getFieldValue("name")); 120 assertEquals("constructor", descr1.getFieldValue("role")); 121 assertEquals("FAILS IN JBOSSMX", "someValue", descr1.getFieldValue("someField")); 122 123 descr1 = info.getDescriptor("AnOperation", "operation"); 124 125 assertEquals("AnOperation", descr1.getFieldValue("name")); 126 assertEquals("Kaksi", descr1.getFieldValue("Yksi")); 127 128 } 129 130 public void testGetDescriptor() throws Exception 131 { 132 final boolean READABLE = true; 133 final boolean WRITABLE = true; 134 final boolean ISIS = true; 135 136 RequiredModelMBean mbean = new RequiredModelMBean (); 137 138 ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo ( 139 "Kissa", 140 String .class.getName(), 141 "Some attribute description", 142 !READABLE, !WRITABLE, !ISIS 143 ); 144 145 ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo ( 146 "Koira", 147 String .class.getName(), 148 "Another attribute description", 149 !READABLE, !WRITABLE, !ISIS 150 ); 151 152 ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo ( 153 "FirstConstructor", 154 "Description of the first constructor", 155 null 156 ); 157 158 ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo ( 159 "SecondConstructor", 160 "Description of the second constructor", 161 null 162 ); 163 164 ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo ( 165 "ThirdConstructor", 166 "Description of the 3rd constructor", 167 null 168 ); 169 170 ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo ( 171 "AnOperation", 172 "The description", 173 null, 174 "AType", 175 MBeanOperationInfo.ACTION 176 ); 177 178 ModelMBeanInfoSupport info = new ModelMBeanInfoSupport ( 179 mbean.getClass().getName(), 180 "some description", 181 new ModelMBeanAttributeInfo [] { attr1, attr2 }, 182 new ModelMBeanConstructorInfo [] { constr1, constr2, constr3 }, 183 new ModelMBeanOperationInfo [] { operation }, 184 null 185 ); 186 187 Descriptor descr = info.getDescriptor("SecondConstructor", "constructor"); 188 189 try 190 { 191 assertTrue(descr.getFieldValue("descriptorType").equals("operation")); 192 } 193 catch (AssertionFailedError e) 194 { 195 throw new AssertionFailedError( 196 "FAILS IN JBOSSMX: We incorrectly return descriptor type " + 197 "'constructor' here -- should be 'operation'" 198 ); 199 } 200 201 } 202 203 204 public void testClone() throws Exception 205 { 206 final boolean READABLE = true; 207 final boolean WRITABLE = true; 208 final boolean ISIS = true; 209 210 RequiredModelMBean mbean = new RequiredModelMBean (); 211 212 ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo ( 213 "Kissa", 214 String .class.getName(), 215 "Some attribute description", 216 !READABLE, !WRITABLE, !ISIS 217 ); 218 219 ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo ( 220 "Koira", 221 String .class.getName(), 222 "Another attribute description", 223 !READABLE, !WRITABLE, !ISIS 224 ); 225 226 ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo ( 227 "FirstConstructor", 228 "Description of the first constructor", 229 null 230 ); 231 232 ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo ( 233 "SecondConstructor", 234 "Description of the second constructor", 235 null 236 ); 237 238 ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo ( 239 "ThirdConstructor", 240 "Description of the 3rd constructor", 241 null 242 ); 243 244 ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo ( 245 "AnOperation", 246 "The description", 247 null, 248 "AType", 249 MBeanOperationInfo.ACTION 250 ); 251 252 ModelMBeanInfoSupport info = new ModelMBeanInfoSupport ( 253 mbean.getClass().getName(), 254 "some description", 255 new ModelMBeanAttributeInfo [] { attr1, attr2 }, 256 new ModelMBeanConstructorInfo [] { constr1, constr2, constr3 }, 257 new ModelMBeanOperationInfo [] { operation }, 258 null 259 ); 260 261 ModelMBeanInfo clone = (ModelMBeanInfo )info.clone(); 262 263 assertTrue(clone.getDescriptors(null).length == info.getDescriptors(null).length); 264 265 271 assertTrue( 272 clone.getDescriptor("AnOperation", "operation") 273 .getFieldValue("descriptorType") 274 .equals( 275 info.getDescriptor("AnOperation", "operation") 276 .getFieldValue("descriptorType")) 277 ); 278 279 assertTrue( 280 clone.getDescriptor("AnOperation", "operation") 281 .getFieldValue("name") 282 .equals( 283 info.getDescriptor("AnOperation", "operation") 284 .getFieldValue("name")) 285 ); 286 287 } 288 289 } 290 | Popular Tags |