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 6331783
0N/A * @summary Test that MBeanServer.queryNames doesn't call getMBeanInfo on every
0N/A * resultant MBean when there is no security manager installed.
0N/A * @author Luis-Miguel Alventosa
0N/A * @run clean AvoidGetMBeanInfoCallsTest
0N/A * @run build AvoidGetMBeanInfoCallsTest
0N/A * @run main AvoidGetMBeanInfoCallsTest
0N/A */
0N/A
0N/Aimport java.util.Set;
0N/Aimport javax.management.Attribute;
0N/Aimport javax.management.AttributeList;
0N/Aimport javax.management.AttributeNotFoundException;
0N/Aimport javax.management.DynamicMBean;
0N/Aimport javax.management.InvalidAttributeValueException;
0N/Aimport javax.management.MBeanException;
0N/Aimport javax.management.MBeanInfo;
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.MBeanServerFactory;
0N/Aimport javax.management.ObjectName;
0N/Aimport javax.management.ReflectionException;
0N/A
0N/Apublic class AvoidGetMBeanInfoCallsTest {
0N/A
0N/A /**
0N/A * Test DynamicMBean class
0N/A */
0N/A public static class Test implements DynamicMBean {
0N/A
0N/A public Object getAttribute(String attribute)
0N/A throws AttributeNotFoundException,
0N/A MBeanException,
0N/A ReflectionException {
0N/A return null;
0N/A }
0N/A
0N/A public void setAttribute(Attribute attribute)
0N/A throws AttributeNotFoundException,
0N/A InvalidAttributeValueException,
0N/A MBeanException,
0N/A ReflectionException {
0N/A }
0N/A
0N/A public AttributeList getAttributes(String[] attributes) {
0N/A return null;
0N/A }
0N/A
0N/A public AttributeList setAttributes(AttributeList attributes) {
0N/A return null;
0N/A }
0N/A
0N/A public Object invoke(String actionName,
0N/A Object params[],
0N/A String signature[])
0N/A throws MBeanException,
0N/A ReflectionException {
0N/A return null;
0N/A }
0N/A
0N/A public MBeanInfo getMBeanInfo() {
0N/A entered = true;
0N/A return new MBeanInfo(Test.class.getName(),
0N/A "Test description",
0N/A null, null, null, null);
0N/A }
0N/A
0N/A public boolean entered;
0N/A }
0N/A
0N/A /*
0N/A * Print message
0N/A */
0N/A private static void echo(String message) {
0N/A System.out.println(message);
0N/A }
0N/A
0N/A /**
0N/A * Standalone entry point.
0N/A *
0N/A * Run the test and report to stdout.
0N/A */
0N/A public static void main(String args[]) throws Exception {
0N/A
0N/A echo(">>> Create MBeanServer");
0N/A MBeanServer server = MBeanServerFactory.newMBeanServer();
0N/A
0N/A echo(">>> Default Domain: " + server.getDefaultDomain());
0N/A
0N/A echo(">>> Create and register Test MBean");
0N/A Test mbean = new Test();
0N/A ObjectName name = ObjectName.getInstance(":type=Test");
0N/A server.registerMBean(mbean, name);
0N/A
0N/A echo(">>> Set entered flag to false in Test MBean");
0N/A mbean.entered = false;
0N/A
0N/A echo(">>> Query Names:");
0N/A Set<ObjectName> names = server.queryNames(null, null);
0N/A for (ObjectName on : names) {
0N/A echo("\t" + on.toString());
0N/A }
0N/A
0N/A echo(">>> Entered flag = " + mbean.entered);
0N/A
0N/A if (mbean.entered) {
0N/A echo(">>> Test FAILED!");
0N/A throw new IllegalArgumentException("getMBeanInfo got called");
0N/A } else {
0N/A echo(">>> Test PASSED!");
0N/A }
0N/A }
0N/A}