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;
010:
011: import java.net.MalformedURLException;
012: import java.util.HashMap;
013: import javax.management.remote.JMXConnectorServer;
014: import javax.management.remote.JMXConnectorServerFactory;
015: import javax.management.remote.JMXProviderException;
016: import javax.management.remote.JMXServiceURL;
017:
018: import test.MX4JTestCase;
019:
020: /**
021: * @version $Revision: 1.3 $
022: */
023: public class JMXConnectorServerFactoryTest extends MX4JTestCase {
024: public JMXConnectorServerFactoryTest(String s) {
025: super (s);
026: }
027:
028: public void testInvalidURLs() throws Exception {
029: try {
030: JMXConnectorServerFactory.newJMXConnectorServer(null, null,
031: null);
032: fail();
033: } catch (NullPointerException x) {
034: }
035: }
036:
037: public void testInvalidPackages() throws Exception {
038: HashMap env = new HashMap();
039: JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://host");
040:
041: // Only Strings
042: env.put(JMXConnectorServerFactory.PROTOCOL_PROVIDER_PACKAGES,
043: new Object());
044: try {
045: JMXConnectorServerFactory.newJMXConnectorServer(url, env,
046: null);
047: fail("Only Strings can be specified as provider packages");
048: } catch (JMXProviderException x) {
049: }
050:
051: // Empty not allowed
052: env.put(JMXConnectorServerFactory.PROTOCOL_PROVIDER_PACKAGES,
053: "");
054: try {
055: JMXConnectorServerFactory.newJMXConnectorServer(url, env,
056: null);
057: fail("Provider package string cannot be empty");
058: } catch (JMXProviderException x) {
059: }
060:
061: // Empty not allowed
062: env.put(JMXConnectorServerFactory.PROTOCOL_PROVIDER_PACKAGES,
063: "dummy| |dummy");
064: try {
065: JMXConnectorServerFactory.newJMXConnectorServer(url, env,
066: null);
067: fail("Provider package string cannot contain an empty string");
068: } catch (JMXProviderException x) {
069: }
070: }
071:
072: public void testInvalidProtocol() throws Exception {
073: JMXServiceURL url = new JMXServiceURL(
074: "service:jmx:dummy://host");
075: try {
076: JMXConnectorServerFactory.newJMXConnectorServer(url, null,
077: null);
078: fail();
079: } catch (MalformedURLException x) {
080: }
081: }
082:
083: public void testInvalidClassLoader() throws Exception {
084: HashMap env = new HashMap();
085: JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://host");
086:
087: env
088: .put(
089: JMXConnectorServerFactory.PROTOCOL_PROVIDER_CLASS_LOADER,
090: new Object());
091: try {
092: JMXConnectorServerFactory.newJMXConnectorServer(url, env,
093: null);
094: fail();
095: } catch (IllegalArgumentException x) {
096: }
097: }
098:
099: public void testLoadProviderWithProvidedClassLoader()
100: throws Exception {
101: HashMap env = new HashMap();
102: JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://host");
103:
104: env
105: .put(
106: JMXConnectorServerFactory.PROTOCOL_PROVIDER_CLASS_LOADER,
107: getClass().getClassLoader());
108: JMXConnectorServerFactory.newJMXConnectorServer(url, env, null);
109: }
110:
111: public void testRMIProvider() throws Exception {
112: JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://host");
113: JMXConnectorServer connector = JMXConnectorServerFactory
114: .newJMXConnectorServer(url, null, null);
115: assertNotNull(connector);
116: }
117: }
|