1 16 17 package org.springframework.jmx.support; 18 19 import java.net.MalformedURLException ; 20 21 import javax.management.MBeanServerConnection ; 22 import javax.management.remote.JMXConnectorServer ; 23 import javax.management.remote.JMXConnectorServerFactory ; 24 import javax.management.remote.JMXServiceURL ; 25 26 import org.springframework.core.JdkVersion; 27 import org.springframework.jmx.AbstractJmxTests; 28 29 32 public class MBeanServerConnectionFactoryBeanTests extends AbstractJmxTests { 33 34 private static final String SERVICE_URL = "service:jmx:jmxmp://localhost:9876"; 35 36 private JMXServiceURL getServiceUrl() throws MalformedURLException { 37 return new JMXServiceURL (SERVICE_URL); 38 } 39 40 private JMXConnectorServer getConnectorServer() throws Exception { 41 return JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, server); 42 } 43 44 public void testValidConnection() throws Exception { 45 if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_14) { 46 return; 48 } 49 50 JMXConnectorServer connectorServer = getConnectorServer(); 51 connectorServer.start(); 52 53 MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); 54 bean.setServiceUrl(SERVICE_URL); 55 bean.afterPropertiesSet(); 56 57 MBeanServerConnection connection = (MBeanServerConnection ) bean.getObject(); 58 assertNotNull("Connection should not be null", connection); 59 60 assertEquals("MBean count should be the same", server.getMBeanCount(), connection.getMBeanCount()); 62 } 63 64 public void testWithNoServiceUrl() throws Exception { 65 MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); 66 try { 67 bean.afterPropertiesSet(); 68 fail("IllegalArgumentException should be raised when no service url is provided"); 69 } 70 catch (IllegalArgumentException ex) { 71 } 73 } 74 75 } 76 | Popular Tags |