Path: blob/master/test/jdk/javax/management/security/AvoidGetMBeanInfoCallsTest.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 633178326* @summary Test that MBeanServer.queryNames doesn't call getMBeanInfo on every27* resultant MBean when there is no security manager installed.28* @author Luis-Miguel Alventosa29*30* @run clean AvoidGetMBeanInfoCallsTest31* @run build AvoidGetMBeanInfoCallsTest32* @run main AvoidGetMBeanInfoCallsTest33*/3435import java.util.Set;36import javax.management.Attribute;37import javax.management.AttributeList;38import javax.management.AttributeNotFoundException;39import javax.management.DynamicMBean;40import javax.management.InvalidAttributeValueException;41import javax.management.MBeanException;42import javax.management.MBeanInfo;43import javax.management.MBeanServer;44import javax.management.MBeanServerFactory;45import javax.management.ObjectName;46import javax.management.ReflectionException;4748public class AvoidGetMBeanInfoCallsTest {4950/**51* Test DynamicMBean class52*/53public static class Test implements DynamicMBean {5455public Object getAttribute(String attribute)56throws AttributeNotFoundException,57MBeanException,58ReflectionException {59return null;60}6162public void setAttribute(Attribute attribute)63throws AttributeNotFoundException,64InvalidAttributeValueException,65MBeanException,66ReflectionException {67}6869public AttributeList getAttributes(String[] attributes) {70return null;71}7273public AttributeList setAttributes(AttributeList attributes) {74return null;75}7677public Object invoke(String actionName,78Object params[],79String signature[])80throws MBeanException,81ReflectionException {82return null;83}8485public MBeanInfo getMBeanInfo() {86entered = true;87return new MBeanInfo(Test.class.getName(),88"Test description",89null, null, null, null);90}9192public boolean entered;93}9495/*96* Print message97*/98private static void echo(String message) {99System.out.println(message);100}101102/**103* Standalone entry point.104*105* Run the test and report to stdout.106*/107public static void main(String args[]) throws Exception {108109echo(">>> Create MBeanServer");110MBeanServer server = MBeanServerFactory.newMBeanServer();111112echo(">>> Default Domain: " + server.getDefaultDomain());113114echo(">>> Create and register Test MBean");115Test mbean = new Test();116ObjectName name = ObjectName.getInstance(":type=Test");117server.registerMBean(mbean, name);118119echo(">>> Set entered flag to false in Test MBean");120mbean.entered = false;121122echo(">>> Query Names:");123Set<ObjectName> names = server.queryNames(null, null);124for (ObjectName on : names) {125echo("\t" + on.toString());126}127128echo(">>> Entered flag = " + mbean.entered);129130if (mbean.entered) {131echo(">>> Test FAILED!");132throw new IllegalArgumentException("getMBeanInfo got called");133} else {134echo(">>> Test PASSED!");135}136}137}138139140