Path: blob/master/test/jdk/javax/management/mxbean/OperationImpactTest.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 632010426* @summary Check that MXBean operations have impact UNKNOWN.27* @author Eamonn McManus28*29* @run clean OperationImpactTest30* @run build OperationImpactTest31* @run main OperationImpactTest32*/3334import javax.management.*;35import javax.management.openmbean.*;3637public class OperationImpactTest {38public static interface ThingMXBean {39void thing();40}41public static class Thing implements ThingMXBean {42public void thing() {}43}4445public static void main(String[] args) throws Exception {46MBeanServer mbs = MBeanServerFactory.newMBeanServer();47ObjectName on = new ObjectName("a:b=c");48Thing thing = new Thing();49mbs.registerMBean(thing, on);50MBeanInfo mbi = mbs.getMBeanInfo(on);51MBeanOperationInfo[] ops = mbi.getOperations();52if (ops.length != 1)53throw new Exception("TEST FAILED: several ops: " + mbi);54MBeanOperationInfo op = ops[0];55if (!op.getName().equals("thing"))56throw new Exception("TEST FAILED: wrong op name: " + op);57if (op.getImpact() != MBeanOperationInfo.UNKNOWN)58throw new Exception("TEST FAILED: wrong impact: " + op);5960// Also check that constructing an OpenMBeanOperationInfo with an61// UNKNOWN impact works62op = new OpenMBeanOperationInfoSupport("name", "descr", null,63SimpleType.VOID,64MBeanOperationInfo.UNKNOWN);65if (op.getImpact() != MBeanOperationInfo.UNKNOWN)66throw new Exception("TEST FAILED: wrong impact: " + op);6768System.out.println("TEST PASSED");69}70}717273