1 8 9 package test.javax.management.remote.rmi; 10 11 import java.net.MalformedURLException ; 12 import java.util.HashMap ; 13 import java.util.Map ; 14 15 import javax.management.remote.JMXConnectorServer ; 16 import javax.management.remote.JMXConnectorServerFactory ; 17 import javax.management.remote.JMXServiceURL ; 18 import javax.naming.Context ; 19 20 import mx4j.tools.naming.CosNamingService; 21 import org.omg.CORBA.ORB ; 22 23 26 public class RMIIIOPConnectorServerTest extends RMIConnectorServerTestCase 27 { 28 private CosNamingService naming; 29 30 public RMIIIOPConnectorServerTest(String s) 31 { 32 super(s); 33 } 34 35 public void startNaming() throws Exception 36 { 37 naming = new CosNamingService(getNamingPort()); 38 naming.start(); 39 Thread.sleep(5000); 40 } 41 42 public void stopNaming() throws Exception 43 { 44 naming.stop(); 45 naming = null; 46 Thread.sleep(5000); 47 } 48 49 public int getNamingPort() 50 { 51 return 1100; 52 } 53 54 public JMXServiceURL createJMXConnectorServerAddress() throws MalformedURLException 55 { 56 return new JMXServiceURL ("iiop", "localhost", 0); 57 } 58 59 public Map getEnvironment() 60 { 61 HashMap env = new HashMap (); 62 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"); 63 env.put(Context.PROVIDER_URL, "iiop://localhost:" + getNamingPort()); 64 return env; 65 } 66 67 public void testInvalidProvidedORB() throws Exception 68 { 69 Map environment = new HashMap (); 70 environment.put("java.naming.corba.orb", new Object ()); 71 72 JMXServiceURL url = new JMXServiceURL ("iiop", null, 0, "/jndi/iiop://localhost:" + getNamingPort() + "/jmx"); 73 try 74 { 75 JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, newMBeanServer()); 76 connectorServer.start(); 77 fail(); 78 } 79 catch (IllegalArgumentException ignored) 80 { 81 } 82 } 83 84 public void testProvidedORB() throws Exception 85 { 86 ORB orb = ORB.init((String [])null, null); 87 Map environment = new HashMap (); 88 environment.put("java.naming.corba.orb", orb); 89 90 JMXServiceURL url = new JMXServiceURL ("iiop", null, 0, "/jndi/iiop://localhost:" + getNamingPort() + "/jmx"); 91 JMXConnectorServer connectorServer = null; 92 try 93 { 94 startNaming(); 95 connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, newMBeanServer()); 96 connectorServer.start(); 97 } 98 finally 99 { 100 if (connectorServer != null) connectorServer.stop(); 101 stopNaming(); 102 } 103 } 104 } 105 | Popular Tags |