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 javax.management.remote.JMXServiceURL;
013:
014: import junit.framework.TestCase;
015:
016: /**
017: * @version $Revision: 1.9 $
018: */
019: public class JMXServiceURLTest extends TestCase {
020: public JMXServiceURLTest(String s) {
021: super (s);
022: }
023:
024: public void testInvalidJMXServiceURLNull() throws Exception {
025: try {
026: new JMXServiceURL(null);
027: } catch (NullPointerException x) {
028: }
029: }
030:
031: public void testInvalidJMXServiceURLEmpty() throws Exception {
032: try {
033: new JMXServiceURL("");
034: } catch (MalformedURLException e) {
035: }
036: }
037:
038: public void testInvalidJMXServiceURLWhiteSpace() throws Exception {
039: try {
040: new JMXServiceURL(" ");
041: } catch (MalformedURLException e) {
042: }
043: }
044:
045: public void testInvalidJMXServiceURLNoServiceJMX() throws Exception {
046: try {
047: // No service:jmx
048: new JMXServiceURL("dummy");
049: } catch (MalformedURLException e) {
050: }
051: }
052:
053: public void testInvalidJMXServiceURLNoProtocol1() throws Exception {
054: try {
055: // No protocol
056: new JMXServiceURL("service:jmx: ");
057: } catch (MalformedURLException e) {
058: }
059: }
060:
061: public void testInvalidJMXServiceURLNoProtocol2() throws Exception {
062: try {
063: // No protocol
064: new JMXServiceURL("service:jmx: :// ");
065: } catch (MalformedURLException e) {
066: }
067: }
068:
069: public void testInvalidJMXServiceURLNoHost() throws Exception {
070: try {
071: // No host
072: new JMXServiceURL("service:jmx:rmi:// ");
073: } catch (MalformedURLException e) {
074: }
075: }
076:
077: public void testInvalidJMXServiceURLBadPort() throws Exception {
078: try {
079: // No host
080: new JMXServiceURL("service:jmx:rmi://host:port");
081: } catch (MalformedURLException e) {
082: }
083: }
084:
085: public void testInvalidJMXServiceURLWrongPath() throws Exception {
086: try {
087: // Wrong path
088: new JMXServiceURL("service:jmx:rmi://host//path");
089: } catch (MalformedURLException e) {
090: }
091: }
092:
093: public void testValidJMXServiceURLProtocolOnly() throws Exception {
094: String proto = "rmi";
095: JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto
096: + "://");
097: assertEquals(proto, url.getProtocol());
098: }
099:
100: public void testValidJMXServiceURLProtocolHost() throws Exception {
101: String proto = "rmi";
102: String host = "host";
103:
104: JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto
105: + "://" + host);
106: assertEquals(proto, url.getProtocol());
107: assertEquals(host, url.getHost());
108: assertEquals(0, url.getPort());
109: assertEquals("", url.getURLPath());
110: }
111:
112: public void testValidJMXServiceURLProtocolHostPort()
113: throws Exception {
114: String proto = "rmi";
115: String host = "host";
116: int port = 1099;
117:
118: JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto
119: + "://" + host + ":" + port);
120: assertEquals(proto, url.getProtocol());
121: assertEquals(host, url.getHost());
122: assertEquals(port, url.getPort());
123: assertEquals("", url.getURLPath());
124: }
125:
126: public void testValidJMXServiceURLProtocolHostPortPath()
127: throws Exception {
128: String proto = "rmi";
129: String host = "host";
130: int port = 1099;
131: String path = "/path";
132:
133: JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto
134: + "://" + host + ":" + port + path);
135: assertEquals(proto, url.getProtocol());
136: assertEquals(host, url.getHost());
137: assertEquals(port, url.getPort());
138: assertEquals(path, url.getURLPath());
139: }
140:
141: public void testValidJMXServiceURLCaseNotSignificant()
142: throws Exception {
143: JMXServiceURL reference = new JMXServiceURL(
144: "service:jmx:rmi://");
145: JMXServiceURL url = new JMXServiceURL("SERVICE:JMX:RMI://");
146: assertEquals(url, reference);
147:
148: url = new JMXServiceURL("SERVICE:JMX:rmi://");
149: assertEquals(url, reference);
150:
151: url = new JMXServiceURL("Service:JMX:rmi://");
152: assertEquals(url, reference);
153:
154: url = new JMXServiceURL("service:JMX:rmi://");
155: assertEquals(url, reference);
156:
157: url = new JMXServiceURL("service:Jmx:RMI://");
158: assertEquals(url, reference);
159:
160: url = new JMXServiceURL("service:Jmx:rmi://");
161: assertEquals(url, reference);
162: }
163:
164: public void testDifferentConstructorsYieldEqualJMXServiceURL()
165: throws Exception {
166: JMXServiceURL one = new JMXServiceURL("service:jmx:rmi://");
167: JMXServiceURL two = new JMXServiceURL("rmi", null, 0, null);
168: assertEquals(one, two);
169: assertEquals(one.hashCode(), two.hashCode());
170: assertEquals(one.getURLPath(), two.getURLPath());
171:
172: one = new JMXServiceURL("service:jmx:rmi://myhost");
173: two = new JMXServiceURL("rmi", "myhost", 0, null);
174: assertEquals(one, two);
175: assertEquals(one.hashCode(), two.hashCode());
176: assertEquals(one.getURLPath(), two.getURLPath());
177:
178: one = new JMXServiceURL("service:jmx:rmi://myhost/");
179: two = new JMXServiceURL("rmi", "myhost", 0, null);
180: assertEquals(one, two);
181: assertEquals(one.hashCode(), two.hashCode());
182: assertEquals(one.getURLPath(), two.getURLPath());
183:
184: one = new JMXServiceURL("service:jmx:rmi://myhost/mypath");
185: two = new JMXServiceURL("rmi", "myhost", 0, "mypath");
186: assertEquals(one, two);
187: assertEquals(one.hashCode(), two.hashCode());
188: assertEquals(one.getURLPath(), two.getURLPath());
189:
190: one = new JMXServiceURL("service:jmx:rmi://myhost/mypath");
191: two = new JMXServiceURL("rmi", "myhost", 0, "/mypath");
192: assertEquals(one, two);
193: assertEquals(one.hashCode(), two.hashCode());
194: assertEquals(one.getURLPath(), two.getURLPath());
195: }
196: }
|