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 InterfaceBasedMBeanInfoAssemblerMappedTests 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 testWithUnknownClass() throws Exception { 41 try { 42 InterfaceBasedMBeanInfoAssembler assembler = getWithMapping("com.foo.bar.Unknown"); 43 fail("Should have thrown IllegalArgumentException"); 44 } 45 catch (IllegalArgumentException ex) { 46 } 48 } 49 50 public void testWithNonInterface() throws Exception { 51 try { 52 InterfaceBasedMBeanInfoAssembler assembler = getWithMapping("JmxTestBean"); 53 fail("Should have thrown IllegalArgumentException"); 54 } 55 catch (IllegalArgumentException ex) { 56 } 58 } 59 60 public void testWithFallThrough() throws Exception { 61 InterfaceBasedMBeanInfoAssembler assembler = 62 getWithMapping("foobar", "org.springframework.jmx.export.assembler.ICustomJmxBean"); 63 assembler.setManagedInterfaces(new Class [] {IAdditionalTestMethods.class}); 64 65 ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName()); 66 MBeanAttributeInfo attr = inf.getAttribute("NickName"); 67 68 assertNickName(attr); 69 } 70 71 public void testNickNameIsExposed() throws Exception { 72 ModelMBeanInfo inf = (ModelMBeanInfo ) getMBeanInfo(); 73 MBeanAttributeInfo attr = inf.getAttribute("NickName"); 74 75 assertNickName(attr); 76 } 77 78 protected String getObjectName() { 79 return OBJECT_NAME; 80 } 81 82 protected int getExpectedOperationCount() { 83 return 7; 84 } 85 86 protected int getExpectedAttributeCount() { 87 return 3; 88 } 89 90 protected MBeanInfoAssembler getAssembler() throws Exception { 91 return getWithMapping( 92 "org.springframework.jmx.export.assembler.IAdditionalTestMethods, " + 93 "org.springframework.jmx.export.assembler.ICustomJmxBean"); 94 } 95 96 protected String getApplicationContextPath() { 97 return "org/springframework/jmx/export/assembler/interfaceAssemblerMapped.xml"; 98 } 99 100 private InterfaceBasedMBeanInfoAssembler getWithMapping(String mapping) { 101 return getWithMapping(OBJECT_NAME, mapping); 102 } 103 104 private InterfaceBasedMBeanInfoAssembler getWithMapping(String name, String mapping) { 105 InterfaceBasedMBeanInfoAssembler assembler = new InterfaceBasedMBeanInfoAssembler(); 106 Properties props = new Properties (); 107 props.setProperty(name, mapping); 108 assembler.setInterfaceMappings(props); 109 return assembler; 110 } 111 112 private void assertNickName(MBeanAttributeInfo attr) { 113 assertNotNull("Nick Name should not be null", attr); 114 assertTrue("Nick Name should be writable", attr.isWritable()); 115 assertTrue("Nick Name should be readab;e", attr.isReadable()); 116 } 117 118 } 119 | Popular Tags |