Path: blob/master/test/jdk/javax/management/loading/GetMBeansFromURLTest.java
41149 views
/*1* Copyright (c) 2004, 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 501859326* @summary Test that calling getMBeansFromURL(url) with a bogus URL on a27* given MLet instance throws a ServiceNotFoundException exception28* with a non null cause.29* @author Luis-Miguel Alventosa30*31* @run clean GetMBeansFromURLTest32* @run build GetMBeansFromURLTest33* @run main GetMBeansFromURLTest34*/3536import javax.management.MBeanServer;37import javax.management.MBeanServerFactory;38import javax.management.ObjectName;39import javax.management.ServiceNotFoundException;40import javax.management.loading.MLet;4142public class GetMBeansFromURLTest {4344public static void main(String[] args) throws Exception {4546boolean error = false;4748// Instantiate the MBean server49//50System.out.println("Create the MBean server");51MBeanServer mbs = MBeanServerFactory.createMBeanServer();5253// Instantiate an MLet54//55System.out.println("Create the MLet");56MLet mlet = new MLet();5758// Register the MLet MBean with the MBeanServer59//60System.out.println("Register the MLet MBean");61ObjectName mletObjectName = new ObjectName("Test:type=MLet");62mbs.registerMBean(mlet, mletObjectName);6364// Call getMBeansFromURL65//66System.out.println("Call mlet.getMBeansFromURL(<url>)");67try {68mlet.getMBeansFromURL("bogus://whatever");69System.out.println("TEST FAILED: Expected " +70ServiceNotFoundException.class +71" exception not thrown.");72error = true;73} catch (ServiceNotFoundException e) {74if (e.getCause() == null) {75System.out.println("TEST FAILED: Got null cause in " +76ServiceNotFoundException.class +77" exception.");78error = true;79} else {80System.out.println("TEST PASSED: Got non-null cause in " +81ServiceNotFoundException.class +82" exception.");83error = false;84}85e.printStackTrace(System.out);86}8788// Unregister the MLet MBean89//90System.out.println("Unregister the MLet MBean");91mbs.unregisterMBean(mletObjectName);9293// Release MBean server94//95System.out.println("Release the MBean server");96MBeanServerFactory.releaseMBeanServer(mbs);9798// End Test99//100System.out.println("Bye! Bye!");101if (error) System.exit(1);102}103}104105106