1 16 17 package org.springframework.jmx.access; 18 19 import javax.management.MalformedObjectNameException ; 20 import javax.management.ObjectName ; 21 22 import org.springframework.beans.factory.BeanCreationException; 23 import org.springframework.beans.factory.xml.XmlBeanFactory; 24 import org.springframework.core.io.ClassPathResource; 25 import org.springframework.jmx.AbstractJmxTests; 26 import org.springframework.jmx.IJmxTestBean; 27 import org.springframework.jmx.support.ObjectNameManager; 28 29 32 public class MBeanProxyFactoryBeanTests extends AbstractJmxTests { 33 34 private static final String OBJECT_NAME = "bean:name=testBean1"; 35 36 protected ObjectName getObjectName() throws Exception { 37 return ObjectNameManager.getInstance(OBJECT_NAME); 38 } 39 40 public void testProxyFactory() throws Exception { 41 MBeanProxyFactoryBean fb = getProxyFactory(); 42 fb.setProxyInterface(IJmxTestBean.class); 43 fb.afterPropertiesSet(); 44 45 IJmxTestBean bean = (IJmxTestBean) fb.getObject(); 46 assertNotNull("Proxy should not be null", bean); 47 } 48 49 public void testInvalidJdkProxy() throws Exception { 50 MBeanProxyFactoryBean fb = getProxyFactory(); 51 try { 52 fb.afterPropertiesSet(); 53 fail("Should not be able to create JDK proxy with no proxy interfaces"); 54 } 55 catch (Exception ex) { 56 } 58 } 59 60 public void testWithLocatedMBeanServer() throws Exception { 61 MBeanProxyFactoryBean fb = new MBeanProxyFactoryBean(); 62 fb.setProxyInterface(IJmxTestBean.class); 63 fb.setObjectName(OBJECT_NAME); 64 fb.afterPropertiesSet(); 65 Object proxy = fb.getObject(); 66 assertNotNull(proxy); 67 } 68 69 public void testProxyFactoryBeanWithAutodetect() throws Exception { 70 try { 71 XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("proxyFactoryBean.xml", getClass())); 72 bf.preInstantiateSingletons(); 73 } 74 catch (BeanCreationException ex) { 75 if (ex.getCause().getClass() == MBeanInfoRetrievalException.class) { 76 fail("MBeanProxyFactoryBean should be ignored by MBeanExporter when running autodetect process"); 77 } 78 else { 79 throw ex; 80 } 81 } 82 } 83 84 private MBeanProxyFactoryBean getProxyFactory() throws MalformedObjectNameException { 85 MBeanProxyFactoryBean fb = new MBeanProxyFactoryBean(); 86 fb.setServer(server); 87 fb.setObjectName(OBJECT_NAME); 88 return fb; 89 } 90 91 } 92 | Popular Tags |