1 16 17 package org.springframework.jmx.export.assembler; 18 19 import java.util.Properties ; 20 21 import javax.management.MBeanAttributeInfo ; 22 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 23 import javax.management.modelmbean.ModelMBeanInfo ; 24 25 28 public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAssemblerTests { 29 30 protected static final String OBJECT_NAME = "bean:name=testBean4"; 31 32 public void testGetAgeIsReadOnly() throws Exception { 33 ModelMBeanInfo info = getMBeanInfoFromAssembler(); 34 ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE); 35 36 assertTrue("Age is not readable", attr.isReadable()); 37 assertFalse("Age is not writable", attr.isWritable()); 38 } 39 40 public void testWithFallThrough() throws Exception { 41 MethodNameBasedMBeanInfoAssembler assembler = 42 getWithMapping("foobar", "add,myOperation,getName,setName,getAge"); 43 assembler.setManagedMethods(new String [] {"getNickName", "setNickName"}); 44 45 ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName()); 46 MBeanAttributeInfo attr = inf.getAttribute("NickName"); 47 48 assertNickName(attr); 49 } 50 51 public void testNickNameIsExposed() throws Exception { 52 ModelMBeanInfo inf = (ModelMBeanInfo ) getMBeanInfo(); 53 MBeanAttributeInfo attr = inf.getAttribute("NickName"); 54 55 assertNickName(attr); 56 } 57 58 protected String getObjectName() { 59 return OBJECT_NAME; 60 } 61 62 protected int getExpectedOperationCount() { 63 return 7; 64 } 65 66 protected int getExpectedAttributeCount() { 67 return 3; 68 } 69 70 protected MBeanInfoAssembler getAssembler() throws Exception { 71 return getWithMapping("getNickName,setNickName,add,myOperation,getName,setName,getAge"); 72 } 73 74 protected String getApplicationContextPath() { 75 return "org/springframework/jmx/export/assembler/methodNameAssemblerMapped.xml"; 76 } 77 78 private MethodNameBasedMBeanInfoAssembler getWithMapping(String mapping) { 79 return getWithMapping(OBJECT_NAME, mapping); 80 } 81 82 private MethodNameBasedMBeanInfoAssembler getWithMapping(String name, String mapping) { 83 MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler(); 84 Properties props = new Properties (); 85 props.setProperty(name, mapping); 86 assembler.setMethodMappings(props); 87 return assembler; 88 } 89 90 private void assertNickName(MBeanAttributeInfo attr) { 91 assertNotNull("Nick Name should not be null", attr); 92 assertTrue("Nick Name should be writable", attr.isWritable()); 93 assertTrue("Nick Name should be readab;e", attr.isReadable()); 94 } 95 96 } 97 | Popular Tags |