1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6320104 27 * @summary Check that MXBean operations have impact UNKNOWN. 28 * @author Eamonn McManus 29 * @run clean OperationImpactTest 30 * @run build OperationImpactTest 31 * @run main OperationImpactTest 32 */ 33 34 import javax.management.*; 35 import javax.management.openmbean.*; 36 37 public class OperationImpactTest { 38 public static interface ThingMXBean { 39 void thing(); 40 } 41 public static class Thing implements ThingMXBean { 42 public void thing() {} 43 } 44 45 public static void main(String[] args) throws Exception { 46 MBeanServer mbs = MBeanServerFactory.newMBeanServer(); 47 ObjectName on = new ObjectName("a:b=c"); 48 Thing thing = new Thing(); 49 mbs.registerMBean(thing, on); 50 MBeanInfo mbi = mbs.getMBeanInfo(on); 51 MBeanOperationInfo[] ops = mbi.getOperations(); 52 if (ops.length != 1) 53 throw new Exception("TEST FAILED: several ops: " + mbi); 54 MBeanOperationInfo op = ops[0]; 55 if (!op.getName().equals("thing")) 56 throw new Exception("TEST FAILED: wrong op name: " + op); 57 if (op.getImpact() != MBeanOperationInfo.UNKNOWN) 58 throw new Exception("TEST FAILED: wrong impact: " + op); 59 60 // Also check that constructing an OpenMBeanOperationInfo with an 61 // UNKNOWN impact works 62 op = new OpenMBeanOperationInfoSupport("name", "descr", null, 63 SimpleType.VOID, 64 MBeanOperationInfo.UNKNOWN); 65 if (op.getImpact() != MBeanOperationInfo.UNKNOWN) 66 throw new Exception("TEST FAILED: wrong impact: " + op); 67 68 System.out.println("TEST PASSED"); 69 } 70 }