Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/loading/GetMBeansFromURLTest.java
38839 views
/*1* Copyright (c) 2004, 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* @run clean GetMBeansFromURLTest31* @run build GetMBeansFromURLTest32* @run main GetMBeansFromURLTest33*/3435import javax.management.MBeanServer;36import javax.management.MBeanServerFactory;37import javax.management.ObjectName;38import javax.management.ServiceNotFoundException;39import javax.management.loading.MLet;4041public class GetMBeansFromURLTest {4243public static void main(String[] args) throws Exception {4445boolean error = false;4647// Instantiate the MBean server48//49System.out.println("Create the MBean server");50MBeanServer mbs = MBeanServerFactory.createMBeanServer();5152// Instantiate an MLet53//54System.out.println("Create the MLet");55MLet mlet = new MLet();5657// Register the MLet MBean with the MBeanServer58//59System.out.println("Register the MLet MBean");60ObjectName mletObjectName = new ObjectName("Test:type=MLet");61mbs.registerMBean(mlet, mletObjectName);6263// Call getMBeansFromURL64//65System.out.println("Call mlet.getMBeansFromURL(<url>)");66try {67mlet.getMBeansFromURL("bogus://whatever");68System.out.println("TEST FAILED: Expected " +69ServiceNotFoundException.class +70" exception not thrown.");71error = true;72} catch (ServiceNotFoundException e) {73if (e.getCause() == null) {74System.out.println("TEST FAILED: Got null cause in " +75ServiceNotFoundException.class +76" exception.");77error = true;78} else {79System.out.println("TEST PASSED: Got non-null cause in " +80ServiceNotFoundException.class +81" exception.");82error = false;83}84e.printStackTrace(System.out);85}8687// Unregister the MLet MBean88//89System.out.println("Unregister the MLet MBean");90mbs.unregisterMBean(mletObjectName);9192// Release MBean server93//94System.out.println("Release the MBean server");95MBeanServerFactory.releaseMBeanServer(mbs);9697// End Test98//99System.out.println("Bye! Bye!");100if (error) System.exit(1);101}102}103104105