Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/CloseableTest.java
38867 views
/*1* Copyright (c) 2005, 2012, 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* @run clean CloseableTest31* @run build CloseableTest32* @run main CloseableTest33*/3435import java.io.Closeable;36import javax.management.remote.JMXConnector;37import javax.management.remote.rmi.RMIConnection;38import javax.management.remote.rmi.RMIConnectionImpl;39import javax.management.remote.rmi.RMIConnectionImpl_Stub;40import javax.management.remote.rmi.RMIConnector;41import javax.management.remote.rmi.RMIIIOPServerImpl;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,53RMIIIOPServerImpl.class,54RMIJRMPServerImpl.class55};5657static int error;5859static void test(Class<?> c) {60System.out.println("\nTest " + c);61if (Closeable.class.isAssignableFrom(c)) {62System.out.println("Test passed!");63} else {64error++;65System.out.println("Test failed!");66}67}6869static void test(String cn) {70try {71test(Class.forName(cn));72} catch (ClassNotFoundException ignore) {73System.out.println("\n" + cn + " not tested.");74}75}7677public static void main(String[] args) throws Exception {78System.out.println("Test that all the JMX Remote API classes that " +79"define\nthe method \"void close() throws " +80"IOException;\" extend\nor implement the " +81"java.io.Closeable interface.");82for (Class<?> c : closeArray) {83test(c);84}8586// Stub classes not present if RMI-IIOP not supported87test("org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub");8889if (error > 0) {90final String msg = "\nTest FAILED! Got " + error + " error(s)";91System.out.println(msg);92throw new IllegalArgumentException(msg);93} else {94System.out.println("\nTest PASSED!");95}96}97}9899100