001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management.remote.rmi;
010:
011: import javax.management.MBeanServerConnection;
012: import javax.management.remote.JMXConnector;
013: import javax.management.remote.JMXConnectorFactory;
014: import javax.management.remote.JMXConnectorServer;
015: import javax.management.remote.JMXConnectorServerFactory;
016: import javax.management.remote.JMXServiceURL;
017: import javax.management.remote.rmi.RMIConnector;
018: import javax.management.remote.rmi.RMIServer;
019:
020: import test.javax.management.remote.JMXConnectorTestCase;
021:
022: /**
023: * @version $Revision: 1.13 $
024: */
025: public abstract class RMIConnectorTestCase extends JMXConnectorTestCase
026: implements RMITestCase {
027: public RMIConnectorTestCase(String s) {
028: super (s);
029: }
030:
031: public void testNewRMIConnectorNullURL() throws Exception {
032: try {
033: new RMIConnector((JMXServiceURL) null, null);
034: fail();
035: } catch (IllegalArgumentException x) {
036: }
037: }
038:
039: public void testNewRMIConnectorNullRMIServer() throws Exception {
040: try {
041: new RMIConnector((RMIServer) null, null);
042: fail();
043: } catch (IllegalArgumentException x) {
044: }
045: }
046:
047: public void testJNDILookupWithRelativePath() throws Exception {
048: JMXConnectorServer cntorServer = null;
049: JMXConnector cntor = null;
050: try {
051: startNaming();
052:
053: JMXServiceURL url = createJMXConnectorServerAddress();
054: url = new JMXServiceURL(url.getProtocol(), url.getHost(),
055: url.getPort(), "/jndi/jmx");
056: cntorServer = JMXConnectorServerFactory
057: .newJMXConnectorServer(url, getEnvironment(),
058: newMBeanServer());
059: cntorServer.start();
060:
061: cntor = JMXConnectorFactory.connect(cntorServer
062: .getAddress(), getEnvironment());
063: MBeanServerConnection mbsc = cntor
064: .getMBeanServerConnection();
065: mbsc.getDefaultDomain();
066: } finally {
067: if (cntor != null)
068: cntor.close();
069: if (cntorServer != null)
070: cntorServer.stop();
071: stopNaming();
072: }
073: }
074:
075: public void testJNDILookupWithAbsolutePath() throws Exception {
076: JMXConnectorServer cntorServer = null;
077: JMXConnector cntor = null;
078: try {
079: startNaming();
080:
081: JMXServiceURL url = createJMXConnectorServerAddress();
082: url = new JMXServiceURL(url.getProtocol(), url.getHost(),
083: url.getPort(), "/jndi/" + url.getProtocol()
084: + "://localhost:" + getNamingPort()
085: + "/jmx");
086: cntorServer = JMXConnectorServerFactory
087: .newJMXConnectorServer(url, getEnvironment(),
088: newMBeanServer());
089: cntorServer.start();
090:
091: cntor = JMXConnectorFactory.connect(cntorServer
092: .getAddress(), getEnvironment());
093: MBeanServerConnection mbsc = cntor
094: .getMBeanServerConnection();
095: mbsc.getDefaultDomain();
096: } finally {
097: if (cntor != null)
098: cntor.close();
099: if (cntorServer != null)
100: cntorServer.stop();
101: stopNaming();
102: }
103: }
104: }
|