0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6335337
0N/A * @summary Test correctness of mxbean flag in descriptor.
0N/A * @author Luis-Miguel Alventosa
0N/A * @run clean MXBeanFlagTest
0N/A * @run build MXBeanFlagTest
0N/A * @run main MXBeanFlagTest
0N/A */
0N/A
0N/Aimport javax.management.*;
0N/A
0N/Apublic class MXBeanFlagTest {
0N/A
0N/A public interface Compliant1MXBean {}
0N/A public static class Compliant1 implements Compliant1MXBean {}
0N/A
0N/A public interface Compliant2MXBean {}
0N/A public static class Compliant2 implements Compliant2MXBean {}
0N/A
0N/A public interface Compliant3MBean {}
0N/A public static class Compliant3 implements Compliant3MBean {}
0N/A
0N/A public interface Compliant4MBean {}
0N/A public static class Compliant4 implements Compliant4MBean {}
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A MBeanServer mbs = MBeanServerFactory.newMBeanServer();
0N/A ObjectName on1 = new ObjectName(":type=Compliant1");
0N/A ObjectName on2 = new ObjectName(":type=Compliant2");
0N/A ObjectName on3 = new ObjectName(":type=Compliant3");
0N/A ObjectName on4 = new ObjectName(":type=Compliant4");
0N/A Compliant1 compliant1 = new Compliant1();
0N/A StandardMBean compliant2 =
0N/A new StandardMBean(new Compliant2(), Compliant2MXBean.class, true);
0N/A Compliant3 compliant3 = new Compliant3();
0N/A StandardMBean compliant4 =
0N/A new StandardMBean(new Compliant4(), Compliant4MBean.class, false);
0N/A mbs.registerMBean(compliant1, on1);
0N/A mbs.registerMBean(compliant2, on2);
0N/A mbs.registerMBean(compliant3, on3);
0N/A mbs.registerMBean(compliant4, on4);
0N/A String flag1 = (String)
0N/A mbs.getMBeanInfo(on1).getDescriptor().getFieldValue("mxbean");
0N/A String flag2 = (String)
0N/A mbs.getMBeanInfo(on2).getDescriptor().getFieldValue("mxbean");
0N/A String flag3 = (String)
0N/A mbs.getMBeanInfo(on3).getDescriptor().getFieldValue("mxbean");
0N/A String flag4 = (String)
0N/A mbs.getMBeanInfo(on4).getDescriptor().getFieldValue("mxbean");
0N/A System.out.println("MXBean compliant1:\n" +
0N/A "\t[Expected: mxbean=true] [Got: mxbean=" + flag1 + "]");
0N/A System.out.println("MXBean compliant2:\n" +
0N/A "\t[Expected: mxbean=true] [Got: mxbean=" + flag2 + "]");
0N/A System.out.println("Standard MBean compliant3:\n" +
0N/A "\t[Expected: mxbean=false] [Got: mxbean=" + flag3 + "]");
0N/A System.out.println("Standard MBean compliant4:\n" +
0N/A "\t[Expected: mxbean=false] [Got: mxbean=" + flag4 + "]");
0N/A if (flag1 != null && flag1.equals("true") &&
0N/A flag2 != null && flag2.equals("true") &&
0N/A flag3 != null && flag3.equals("false") &&
0N/A flag4 != null && flag4.equals("false"))
0N/A System.out.println("Test PASSED");
0N/A else {
0N/A System.out.println("Test FAILED");
0N/A throw new Exception("invalid flags");
0N/A }
0N/A }
0N/A}