1 8 9 package test.javax.management.remote; 10 11 import java.net.MalformedURLException ; 12 import javax.management.remote.JMXServiceURL ; 13 14 import junit.framework.TestCase; 15 16 19 public class JMXServiceURLTest extends TestCase 20 { 21 public JMXServiceURLTest(String s) 22 { 23 super(s); 24 } 25 26 public void testInvalidJMXServiceURLNull() throws Exception 27 { 28 try 29 { 30 new JMXServiceURL (null); 31 } 32 catch (NullPointerException x) 33 { 34 } 35 } 36 37 public void testInvalidJMXServiceURLEmpty() throws Exception 38 { 39 try 40 { 41 new JMXServiceURL (""); 42 } 43 catch (MalformedURLException e) 44 { 45 } 46 } 47 48 public void testInvalidJMXServiceURLWhiteSpace() throws Exception 49 { 50 try 51 { 52 new JMXServiceURL (" "); 53 } 54 catch (MalformedURLException e) 55 { 56 } 57 } 58 59 public void testInvalidJMXServiceURLNoServiceJMX() throws Exception 60 { 61 try 62 { 63 new JMXServiceURL ("dummy"); 65 } 66 catch (MalformedURLException e) 67 { 68 } 69 } 70 71 public void testInvalidJMXServiceURLNoProtocol1() throws Exception 72 { 73 try 74 { 75 new JMXServiceURL ("service:jmx: "); 77 } 78 catch (MalformedURLException e) 79 { 80 } 81 } 82 83 public void testInvalidJMXServiceURLNoProtocol2() throws Exception 84 { 85 try 86 { 87 new JMXServiceURL ("service:jmx: :// "); 89 } 90 catch (MalformedURLException e) 91 { 92 } 93 } 94 95 public void testInvalidJMXServiceURLNoHost() throws Exception 96 { 97 try 98 { 99 new JMXServiceURL ("service:jmx:rmi:// "); 101 } 102 catch (MalformedURLException e) 103 { 104 } 105 } 106 107 public void testInvalidJMXServiceURLBadPort() throws Exception 108 { 109 try 110 { 111 new JMXServiceURL ("service:jmx:rmi://host:port"); 113 } 114 catch (MalformedURLException e) 115 { 116 } 117 } 118 119 public void testInvalidJMXServiceURLWrongPath() throws Exception 120 { 121 try 122 { 123 new JMXServiceURL ("service:jmx:rmi://host//path"); 125 } 126 catch (MalformedURLException e) 127 { 128 } 129 } 130 131 public void testValidJMXServiceURLProtocolOnly() throws Exception 132 { 133 String proto = "rmi"; 134 JMXServiceURL url = new JMXServiceURL ("service:jmx:" + proto + "://"); 135 assertEquals(proto, url.getProtocol()); 136 } 137 138 public void testValidJMXServiceURLProtocolHost() throws Exception 139 { 140 String proto = "rmi"; 141 String host = "host"; 142 143 JMXServiceURL url = new JMXServiceURL ("service:jmx:" + proto + "://" + host); 144 assertEquals(proto, url.getProtocol()); 145 assertEquals(host, url.getHost()); 146 assertEquals(0, url.getPort()); 147 assertEquals("", url.getURLPath()); 148 } 149 150 public void testValidJMXServiceURLProtocolHostPort() throws Exception 151 { 152 String proto = "rmi"; 153 String host = "host"; 154 int port = 1099; 155 156 JMXServiceURL url = new JMXServiceURL ("service:jmx:" + proto + "://" + host + ":" + port); 157 assertEquals(proto, url.getProtocol()); 158 assertEquals(host, url.getHost()); 159 assertEquals(port, url.getPort()); 160 assertEquals("", url.getURLPath()); 161 } 162 163 public void testValidJMXServiceURLProtocolHostPortPath() throws Exception 164 { 165 String proto = "rmi"; 166 String host = "host"; 167 int port = 1099; 168 String path = "/path"; 169 170 JMXServiceURL url = new JMXServiceURL ("service:jmx:" + proto + "://" + host + ":" + port + path); 171 assertEquals(proto, url.getProtocol()); 172 assertEquals(host, url.getHost()); 173 assertEquals(port, url.getPort()); 174 assertEquals(path, url.getURLPath()); 175 } 176 177 public void testValidJMXServiceURLCaseNotSignificant() throws Exception 178 { 179 JMXServiceURL reference = new JMXServiceURL ("service:jmx:rmi://"); 180 JMXServiceURL url = new JMXServiceURL ("SERVICE:JMX:RMI://"); 181 assertEquals(url, reference); 182 183 url = new JMXServiceURL ("SERVICE:JMX:rmi://"); 184 assertEquals(url, reference); 185 186 url = new JMXServiceURL ("Service:JMX:rmi://"); 187 assertEquals(url, reference); 188 189 url = new JMXServiceURL ("service:JMX:rmi://"); 190 assertEquals(url, reference); 191 192 url = new JMXServiceURL ("service:Jmx:RMI://"); 193 assertEquals(url, reference); 194 195 url = new JMXServiceURL ("service:Jmx:rmi://"); 196 assertEquals(url, reference); 197 } 198 199 public void testDifferentConstructorsYieldEqualJMXServiceURL() throws Exception 200 { 201 JMXServiceURL one = new JMXServiceURL ("service:jmx:rmi://"); 202 JMXServiceURL two = new JMXServiceURL ("rmi", null, 0, null); 203 assertEquals(one, two); 204 assertEquals(one.hashCode(), two.hashCode()); 205 assertEquals(one.getURLPath(), two.getURLPath()); 206 207 one = new JMXServiceURL ("service:jmx:rmi://myhost"); 208 two = new JMXServiceURL ("rmi", "myhost", 0, null); 209 assertEquals(one, two); 210 assertEquals(one.hashCode(), two.hashCode()); 211 assertEquals(one.getURLPath(), two.getURLPath()); 212 213 one = new JMXServiceURL ("service:jmx:rmi://myhost/"); 214 two = new JMXServiceURL ("rmi", "myhost", 0, null); 215 assertEquals(one, two); 216 assertEquals(one.hashCode(), two.hashCode()); 217 assertEquals(one.getURLPath(), two.getURLPath()); 218 219 one = new JMXServiceURL ("service:jmx:rmi://myhost/mypath"); 220 two = new JMXServiceURL ("rmi", "myhost", 0, "mypath"); 221 assertEquals(one, two); 222 assertEquals(one.hashCode(), two.hashCode()); 223 assertEquals(one.getURLPath(), two.getURLPath()); 224 225 one = new JMXServiceURL ("service:jmx:rmi://myhost/mypath"); 226 two = new JMXServiceURL ("rmi", "myhost", 0, "/mypath"); 227 assertEquals(one, two); 228 assertEquals(one.hashCode(), two.hashCode()); 229 assertEquals(one.getURLPath(), two.getURLPath()); 230 } 231 } 232 | Popular Tags |