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