Path: blob/master/test/jdk/javax/management/remote/mandatory/connection/CloseableTest.java
41159 views
/*1* Copyright (c) 2005, 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 623188826* @summary Test that all the JMX Remote API classes that define27* the method "void close() throws IOException;" extend28* or implement the java.io.Closeable interface.29* @author Luis-Miguel Alventosa30*31* @run clean CloseableTest32* @run build CloseableTest33* @run main CloseableTest34*/3536import java.io.Closeable;37import javax.management.remote.JMXConnector;38import javax.management.remote.rmi.RMIConnection;39import javax.management.remote.rmi.RMIConnectionImpl;40import javax.management.remote.rmi.RMIConnectionImpl_Stub;41import javax.management.remote.rmi.RMIConnector;42import javax.management.remote.rmi.RMIJRMPServerImpl;43import javax.management.remote.rmi.RMIServerImpl;4445public class CloseableTest {46private static final Class closeArray[] = {47JMXConnector.class,48RMIConnector.class,49RMIConnection.class,50RMIConnectionImpl.class,51RMIConnectionImpl_Stub.class,52RMIServerImpl.class,53RMIJRMPServerImpl.class54};5556static int error;5758static void test(Class<?> c) {59System.out.println("\nTest " + c);60if (Closeable.class.isAssignableFrom(c)) {61System.out.println("Test passed!");62} else {63error++;64System.out.println("Test failed!");65}66}6768static void test(String cn) {69try {70test(Class.forName(cn));71} catch (ClassNotFoundException ignore) {72System.out.println("\n" + cn + " not tested.");73}74}7576public static void main(String[] args) throws Exception {77System.out.println("Test that all the JMX Remote API classes that " +78"define\nthe method \"void close() throws " +79"IOException;\" extend\nor implement the " +80"java.io.Closeable interface.");81for (Class<?> c : closeArray) {82test(c);83}8485// Stub classes not present if RMI-IIOP not supported86test("org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub");8788if (error > 0) {89final String msg = "\nTest FAILED! Got " + error + " error(s)";90System.out.println(msg);91throw new IllegalArgumentException(msg);92} else {93System.out.println("\nTest PASSED!");94}95}96}979899