Path: blob/master/test/jdk/javax/management/remote/mandatory/connection/GetConnectionTest.java
41159 views
/*1* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 495141426* @summary Try to get an IOException.27* @author Shanliang JIANG28*29* @run clean GetConnectionTest30* @run build GetConnectionTest31* @run main GetConnectionTest32*/3334import java.io.IOException;35import java.net.MalformedURLException;3637import javax.management.MBeanServer;38import javax.management.MBeanServerConnection;39import javax.management.MBeanServerFactory;40import javax.management.Notification;41import javax.management.NotificationListener;42import javax.management.ObjectName;4344import javax.management.remote.JMXConnector;45import javax.management.remote.JMXConnectorFactory;4647import javax.management.remote.JMXServiceURL;484950public class GetConnectionTest {51public static void main(String[] args) {52System.out.println("Verify whether getting an IOException when "+53"calling getMBeanServerConnection to a unconnected connector.");5455boolean ok = true;56String[] protocols = {"rmi", "iiop", "jmxmp"};5758for (int i = 0; i < protocols.length; i++) {59final String proto = protocols[i];60System.out.println("Testing for protocol " + proto);61try {62ok &= test(proto);63} catch (Exception e) {64System.err.println("Unexpected exception: " + e);65e.printStackTrace();66ok = false;67}68}6970if (ok)71System.out.println("All Tests passed");72else {73System.out.println("TEST FAILED");74System.exit(1);75}76}7778private static boolean test(String proto) throws Exception {79JMXConnector client;80try {81JMXServiceURL url = new JMXServiceURL(proto, null, 0);82client = JMXConnectorFactory.newJMXConnector(url, null);83} catch (MalformedURLException e) {84System.out.println("Protocol " + proto +85" not supported, ignoring");86return true;87}8889// IOException is expected90try {91MBeanServerConnection connection =92client.getMBeanServerConnection();9394System.out.println("FAILED: Expected IOException is not thrown.");95return false;96} catch (IOException e) {97System.out.println("PASSED");98return true;99}100}101}102103104