Path: blob/master/test/jdk/javax/management/MBeanServerFactory/ReleaseMBeanServerTest.java
41149 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 495522226* @summary Test that the releaseMBeanServer(MBeanServer mbeanServer) method27* throws IllegalArgumentException as expected28* @author Luis-Miguel Alventosa29*30* @run clean ReleaseMBeanServerTest31* @run build ReleaseMBeanServerTest32* @run main ReleaseMBeanServerTest33*/3435/* Check that the releaseMBeanServer(MBeanServer mbeanServer) method throws36IllegalArgumentException if mbeanServer was not generated by one of the37createMBeanServer methods, or if releaseMBeanServer was already called38on it. */3940import javax.management.MBeanServer;41import javax.management.MBeanServerFactory;4243public class ReleaseMBeanServerTest {4445private static final String DOMAIN = "TestDomain";4647public static void main(String[] args) throws Exception {4849System.out.println("--------------------------------------" +50"-----------------------------------------");51System.out.println("- Testing IllegalArgumentException in " +52"MBeanServerFactory.releaseMBeanServer() -");53System.out.println("--------------------------------------" +54"-----------------------------------------");5556System.out.println("TEST_0: Call releaseMBeanServer() with " +57"a null MBeanServer reference.");58try {59MBeanServerFactory.releaseMBeanServer(null);60System.err.println("Didn't get expected IllegalArgumentException!");61System.exit(1);62} catch (IllegalArgumentException e) {63System.out.println("Got expected IllegalArgumentException!");64}6566System.out.println("TEST_1: Call releaseMBeanServer() with an " +67"MBeanServer reference corresponding to an " +68"MBeanServer created using newMBeanServer().");69MBeanServer mbs1 = MBeanServerFactory.newMBeanServer();70try {71MBeanServerFactory.releaseMBeanServer(mbs1);72System.err.println("Didn't get expected IllegalArgumentException!");73System.exit(1);74} catch (IllegalArgumentException e) {75System.out.println("Got expected IllegalArgumentException!");76}7778System.out.println("TEST_2: Call releaseMBeanServer() with an " +79"MBeanServer reference corresponding to an " +80"MBeanServer created using newMBeanServer(String).");81MBeanServer mbs2 = MBeanServerFactory.newMBeanServer(DOMAIN);82try {83MBeanServerFactory.releaseMBeanServer(mbs2);84System.err.println("Didn't get expected IllegalArgumentException!");85System.exit(1);86} catch (IllegalArgumentException e) {87System.out.println("Got expected IllegalArgumentException!");88}8990System.out.println("TEST_3: Call releaseMBeanServer() twice with an " +91"MBeanServer reference corresponding to an MBean" +92"Server created using createMBeanServer().");93MBeanServer mbs3 = MBeanServerFactory.createMBeanServer();94MBeanServerFactory.releaseMBeanServer(mbs3);95try {96MBeanServerFactory.releaseMBeanServer(mbs3);97System.err.println("Didn't get expected IllegalArgumentException!");98System.exit(1);99} catch (IllegalArgumentException e) {100System.out.println("Got expected IllegalArgumentException!");101}102103System.out.println("TEST_4: Call releaseMBeanServer() twice with an " +104"MBeanServer reference corresponding to an MBean" +105"Server created using createMBeanServer(String).");106MBeanServer mbs4 = MBeanServerFactory.createMBeanServer(DOMAIN);107MBeanServerFactory.releaseMBeanServer(mbs4);108try {109MBeanServerFactory.releaseMBeanServer(mbs4);110System.err.println("Didn't get expected IllegalArgumentException!");111System.exit(1);112} catch (IllegalArgumentException e) {113System.out.println("Got expected IllegalArgumentException!");114}115}116}117118119