KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javax > management > remote > rmi > RMIIIOPConnectorTest


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package test.javax.management.remote.rmi;
10
11 import java.net.MalformedURLException JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.management.remote.JMXConnectorFactory JavaDoc;
16 import javax.management.remote.JMXConnectorServer JavaDoc;
17 import javax.management.remote.JMXConnectorServerFactory JavaDoc;
18 import javax.management.remote.JMXServiceURL JavaDoc;
19 import javax.naming.Context JavaDoc;
20
21 import mx4j.tools.naming.CosNamingService;
22
23 /**
24  * @version $Revision: 1.8 $
25  */

26 public class RMIIIOPConnectorTest extends RMIConnectorTestCase
27 {
28    private CosNamingService naming;
29
30    public RMIIIOPConnectorTest(String JavaDoc s)
31    {
32       super(s);
33    }
34
35    public JMXServiceURL JavaDoc createJMXConnectorServerAddress() throws MalformedURLException JavaDoc
36    {
37       return new JMXServiceURL JavaDoc("iiop", "localhost", 0);
38    }
39
40    public void startNaming() throws Exception JavaDoc
41    {
42       naming = new CosNamingService(getNamingPort());
43       naming.start();
44       Thread.sleep(5000);
45    }
46
47    public void stopNaming() throws Exception JavaDoc
48    {
49       naming.stop();
50       naming = null;
51       Thread.sleep(5000);
52    }
53
54    public int getNamingPort()
55    {
56       return 1100;
57    }
58
59    public Map JavaDoc getEnvironment()
60    {
61       HashMap JavaDoc env = new HashMap JavaDoc();
62       env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
63       env.put(Context.PROVIDER_URL, "iiop://localhost:" + getNamingPort());
64 // env.put("org.omg.CORBA.ORBInitialPort", String.valueOf(getNamingPort()));
65
return env;
66    }
67
68    public void testInvalidProvidedORB() throws Exception JavaDoc
69    {
70       Map JavaDoc environment = new HashMap JavaDoc();
71       environment.put("java.naming.corba.orb", new Object JavaDoc());
72
73       JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc("iiop", null, 0, "/jndi/iiop://localhost:" + getNamingPort() + "/jmx");
74       JMXConnectorServer JavaDoc connectorServer = null;
75       try
76       {
77          startNaming();
78
79          connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, newMBeanServer());
80          connectorServer.start();
81
82          JMXConnectorFactory.connect(url, environment);
83          fail();
84       }
85       catch (IllegalArgumentException JavaDoc ignored)
86       {
87       }
88       finally
89       {
90          if (connectorServer != null) connectorServer.stop();
91          stopNaming();
92       }
93    }
94 }
95
Popular Tags