Path: blob/master/test/jdk/javax/management/proxy/JMXProxyFallbackTest.java
41149 views
/*1* Copyright (c) 2013, 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*/2223import javax.management.JMX;24import javax.management.MBeanServer;25import javax.management.MBeanServerFactory;26import javax.management.NotCompliantMBeanException;27import javax.management.ObjectName;2829/*30* @test31* @bug 801028532* @summary Tests the fallback for creating JMX proxies for private interfaces33* It needs to be a separate class because the "jdk.jmx.mbeans.allowNonPublic"34* system property must be set before c.s.j.m.MBeanAnalyzer has been loaded.35* @author Jaroslav Bachorik36*37* @run clean JMXProxyFallbackTest38* @run build JMXProxyFallbackTest39* @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true JMXProxyFallbackTest40*/41public class JMXProxyFallbackTest {42private static interface PrivateMBean {43public int[] getInts();44}4546private static interface PrivateMXBean {47public int[] getInts();48}4950public static class Private implements PrivateMXBean, PrivateMBean {51public int[] getInts() {52return new int[]{1,2,3};53}54}5556private static int failures = 0;5758public static void main(String[] args) throws Exception {59testPrivate(PrivateMBean.class);60testPrivate(PrivateMXBean.class);6162if (failures == 0)63System.out.println("Test passed");64else65throw new Exception("TEST FAILURES: " + failures);66}6768private static void fail(String msg) {69failures++;70System.out.println("FAIL: " + msg);71}7273private static void success(String msg) {74System.out.println("OK: " + msg);75}7677private static void testPrivate(Class<?> iface) throws Exception {78try {79System.out.println("Creating a proxy for private M(X)Bean " +80iface.getName() + " ...");8182MBeanServer mbs = MBeanServerFactory.newMBeanServer();83ObjectName on = new ObjectName("test:type=Proxy");8485JMX.newMBeanProxy(mbs, on, iface);86success("Created a proxy for private M(X)Bean - " + iface.getName());87} catch (Exception e) {88Throwable t = e;89while (t != null && !(t instanceof NotCompliantMBeanException)) {90t = t.getCause();91}92if (t != null) {93fail("Proxy not created");94} else {95throw e;96}97}98}99}100101102