KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.MBeanServerConnection JavaDoc;
12 import javax.management.remote.JMXConnector JavaDoc;
13 import javax.management.remote.JMXConnectorFactory JavaDoc;
14 import javax.management.remote.JMXConnectorServer JavaDoc;
15 import javax.management.remote.JMXConnectorServerFactory JavaDoc;
16 import javax.management.remote.JMXServiceURL JavaDoc;
17 import javax.management.remote.rmi.RMIConnector JavaDoc;
18 import javax.management.remote.rmi.RMIServer JavaDoc;
19
20 import test.javax.management.remote.JMXConnectorTestCase;
21
22 /**
23  * @version $Revision: 1.13 $
24  */

25 public abstract class RMIConnectorTestCase extends JMXConnectorTestCase implements RMITestCase
26 {
27    public RMIConnectorTestCase(String JavaDoc s)
28    {
29       super(s);
30    }
31
32    public void testNewRMIConnectorNullURL() throws Exception JavaDoc
33    {
34       try
35       {
36          new RMIConnector JavaDoc((JMXServiceURL JavaDoc)null, null);
37          fail();
38       }
39       catch (IllegalArgumentException JavaDoc x)
40       {
41       }
42    }
43
44    public void testNewRMIConnectorNullRMIServer() throws Exception JavaDoc
45    {
46       try
47       {
48          new RMIConnector JavaDoc((RMIServer JavaDoc)null, null);
49          fail();
50       }
51       catch (IllegalArgumentException JavaDoc x)
52       {
53       }
54    }
55
56    public void testJNDILookupWithRelativePath() throws Exception JavaDoc
57    {
58       JMXConnectorServer JavaDoc cntorServer = null;
59       JMXConnector JavaDoc cntor = null;
60       try
61       {
62          startNaming();
63
64          JMXServiceURL JavaDoc url = createJMXConnectorServerAddress();
65          url = new JMXServiceURL JavaDoc(url.getProtocol(), url.getHost(), url.getPort(), "/jndi/jmx");
66          cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
67          cntorServer.start();
68
69          cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
70          MBeanServerConnection JavaDoc mbsc = cntor.getMBeanServerConnection();
71          mbsc.getDefaultDomain();
72       }
73       finally
74       {
75          if (cntor != null) cntor.close();
76          if (cntorServer != null) cntorServer.stop();
77          stopNaming();
78       }
79    }
80
81    public void testJNDILookupWithAbsolutePath() throws Exception JavaDoc
82    {
83       JMXConnectorServer JavaDoc cntorServer = null;
84       JMXConnector JavaDoc cntor = null;
85       try
86       {
87          startNaming();
88
89          JMXServiceURL JavaDoc url = createJMXConnectorServerAddress();
90          url = new JMXServiceURL JavaDoc(url.getProtocol(), url.getHost(), url.getPort(), "/jndi/" + url.getProtocol() + "://localhost:" + getNamingPort() + "/jmx");
91          cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
92          cntorServer.start();
93
94          cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
95          MBeanServerConnection JavaDoc mbsc = cntor.getMBeanServerConnection();
96          mbsc.getDefaultDomain();
97       }
98       finally
99       {
100          if (cntor != null) cntor.close();
101          if (cntorServer != null) cntorServer.stop();
102          stopNaming();
103       }
104    }
105 }
106
Popular Tags