Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/MXBeanFlagTest.java
38841 views
/*1* Copyright (c) 2005, 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 633533726* @summary Test correctness of mxbean flag in descriptor.27* @author Luis-Miguel Alventosa28* @run clean MXBeanFlagTest29* @run build MXBeanFlagTest30* @run main MXBeanFlagTest31*/3233import javax.management.*;3435public class MXBeanFlagTest {3637public interface Compliant1MXBean {}38public static class Compliant1 implements Compliant1MXBean {}3940public interface Compliant2MXBean {}41public static class Compliant2 implements Compliant2MXBean {}4243public interface Compliant3MBean {}44public static class Compliant3 implements Compliant3MBean {}4546public interface Compliant4MBean {}47public static class Compliant4 implements Compliant4MBean {}4849public static void main(String[] args) throws Exception {50MBeanServer mbs = MBeanServerFactory.newMBeanServer();51ObjectName on1 = new ObjectName(":type=Compliant1");52ObjectName on2 = new ObjectName(":type=Compliant2");53ObjectName on3 = new ObjectName(":type=Compliant3");54ObjectName on4 = new ObjectName(":type=Compliant4");55Compliant1 compliant1 = new Compliant1();56StandardMBean compliant2 =57new StandardMBean(new Compliant2(), Compliant2MXBean.class, true);58Compliant3 compliant3 = new Compliant3();59StandardMBean compliant4 =60new StandardMBean(new Compliant4(), Compliant4MBean.class, false);61mbs.registerMBean(compliant1, on1);62mbs.registerMBean(compliant2, on2);63mbs.registerMBean(compliant3, on3);64mbs.registerMBean(compliant4, on4);65String flag1 = (String)66mbs.getMBeanInfo(on1).getDescriptor().getFieldValue("mxbean");67String flag2 = (String)68mbs.getMBeanInfo(on2).getDescriptor().getFieldValue("mxbean");69String flag3 = (String)70mbs.getMBeanInfo(on3).getDescriptor().getFieldValue("mxbean");71String flag4 = (String)72mbs.getMBeanInfo(on4).getDescriptor().getFieldValue("mxbean");73System.out.println("MXBean compliant1:\n" +74"\t[Expected: mxbean=true] [Got: mxbean=" + flag1 + "]");75System.out.println("MXBean compliant2:\n" +76"\t[Expected: mxbean=true] [Got: mxbean=" + flag2 + "]");77System.out.println("Standard MBean compliant3:\n" +78"\t[Expected: mxbean=false] [Got: mxbean=" + flag3 + "]");79System.out.println("Standard MBean compliant4:\n" +80"\t[Expected: mxbean=false] [Got: mxbean=" + flag4 + "]");81if (flag1 != null && flag1.equals("true") &&82flag2 != null && flag2.equals("true") &&83flag3 != null && flag3.equals("false") &&84flag4 != null && flag4.equals("false"))85System.out.println("Test PASSED");86else {87System.out.println("Test FAILED");88throw new Exception("invalid flags");89}90}91}929394