Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/query/InstanceOfExpTest.java
38839 views
/*1* Copyright (c) 2005, 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 5072174 633584826* @summary test the new method javax.management.Query.isInstanceOf("className")27* @author Shanliang JIANG28* @run clean InstanceOfExpTest29* @run build InstanceOfExpTest30* @run main InstanceOfExpTest31*/3233import java.util.*;34import java.lang.management.ManagementFactory;3536import javax.management.*;3738public class InstanceOfExpTest {3940public static class Simple implements SimpleMBean {}41public static interface SimpleMBean {}4243public static void main(String[] args) throws Exception {44System.out.println(">>> Test the method javax.management.Query.isInstanceOf");4546MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();47final String className = "javax.management.NotificationBroadcaster";4849final ObjectName name1 = new ObjectName("test:simple=1");50mbs.createMBean(Simple.class.getName(), name1);5152final ObjectName name2 = new ObjectName("test:timer=1");53mbs.createMBean("javax.management.timer.Timer", name2);5455QueryExp exp = Query.isInstanceOf(Query.value(className));56Set<ObjectName> list = mbs.queryNames(new ObjectName("*:*"), exp);5758if (list.contains(name1) || !list.contains(name2)) {59throw new RuntimeException("InstanceOfExp does not work.");60}6162for (ObjectName on : list) {63if (!mbs.isInstanceOf(on, className)) {64throw new RuntimeException("InstanceOfQueryExp does not work.");65}66}6768Set<ObjectName> all = mbs.queryNames(null, null);69for (ObjectName n : all) {70if (mbs.isInstanceOf(n, className) != list.contains(n))71throw new RuntimeException("InstanceOfExp does not work.");72}7374try {75QueryExp exp1 = Query.isInstanceOf(null);76throw new RuntimeException("Not got an exception with a null class name.");77} catch (IllegalArgumentException iae) {78// OK. Good79}80}81}828384