Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MustBeValidMBeanInfo/MustBeValidCommand.java
38841 views
/*1* Copyright (c) 2003, 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 487481926* @summary Test that MBeanInfo classes no longer throw an27* IllegalArgumentException when attribute names, operation names, and28* Java type names do not strictly follow the expected Java syntax.29* @author Daniel Fuchs30* @run clean MustBeValidCommand31* @run build MustBeValidCommand32* @run main MustBeValidCommand33*/3435import javax.management.MBeanInfo;36import javax.management.MBeanAttributeInfo;37import javax.management.MBeanOperationInfo;38import javax.management.MBeanParameterInfo;39import javax.management.MBeanNotificationInfo;40import javax.management.MBeanConstructorInfo;4142public class MustBeValidCommand {4344private static String[][] attributes = {45{ "Attribute with valid identifiers",46"validType1","validNameAtt1" },47{ "Attribute with invalid type",48"invalid-type", "validNameAtt2" },49{ "Attribute with invalid name", "valid.type2",50"invalid-name-att3" },51{ "Attribute with invalid name and type",52"invalidtype[]","invalid.name.att4" }53};54private static String[][] constructors = {55{ "Constructor with valid name",56"ValidConstructor1" },57{ "Constructor with invalid name",58"invalid.Constructor2"},59{ "Constructor with invalid name",60"invalid-constructor-3" },61{ "Constructor with invalid name",62"invalid constructor" }63};64private static String[][] mbeanclasses = {65{ "MBean with valid class name",66"ValidMBeanClass1" },67{ "MBean with valid class name",68"valid.mbean.Class2" },69{ "MBean with invalid class name",70"invalid.MBeanClass3[]"},71{ "MBean with invalid class name",72"invalid-mbean-class-4" },73{ "MBean with invalid class name",74"invalid mbean class 5" }75};76private static String[][] notificationclasses = {77{ "Notification with valid class name",78"ValidNotificationClass1" },79{ "Notification with valid class name",80"valid.notification.Class2" },81{ "Notification with invalid class name",82"invalid.NotificationClass3[]"},83{ "Notification with invalid class name",84"invalid-notification-class-4" },85{ "Notification with invalid class name",86"invalid notification class 5" }87};88private static String[][] operations = {89{ "Operation with valid identifiers",90"validType1","validNameOp1" },91{ "Operation with invalid type",92"invalid-type", "validNameOp2" },93{ "Operation with invalid name", "valid.type2",94"invalid-name-op3" },95{ "Operation with invalid name and type",96"invalidtype[]","invalid.name.op4" }97};98private static String[][] parameters = {99{ "Parameter with valid identifiers",100"validType1","validNamePar1" },101{ "Parameter with invalid type",102"invalid-type", "validNamePar2" },103{ "Parameter with invalid name", "valid.type2",104"invalid-name-par3" },105{ "Parameter with invalid name and type",106"invalidtype[]","invalid.name.par4" }107};108109static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {110final MBeanAttributeInfo[] result =111new MBeanAttributeInfo[spec.length];112for (int i=0;i<result.length;i++) {113System.out.println("\tCreate an MBeanAttributeInfo: " +114spec[i][0]);115final MBeanAttributeInfo item =116new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],117true,true,false);118result[i]=item;119}120return result;121}122123static private MBeanParameterInfo[] makeParInfos(String[][] spec) {124final MBeanParameterInfo[] result =125new MBeanParameterInfo[spec.length];126for (int i=0;i<result.length;i++) {127System.out.println("\tCreate an MBeanParameterInfo: " +128spec[i][0]);129final MBeanParameterInfo item =130new MBeanParameterInfo(spec[i][2],spec[i][1],spec[i][0]);131result[i]=item;132}133return result;134}135136static private MBeanOperationInfo[] makeOpInfos(String[][] spec) {137final MBeanOperationInfo[] result =138new MBeanOperationInfo[spec.length];139final MBeanParameterInfo[] pars = makeParInfos(parameters);140for (int i=0;i<result.length;i++) {141System.out.println("\tCreate an MBeanOperationInfo: " +142spec[i][0]);143final MBeanOperationInfo item =144new MBeanOperationInfo(spec[i][2],spec[i][0],pars,spec[i][1],145MBeanOperationInfo.ACTION_INFO);146result[i]=item;147}148return result;149}150151static private MBeanConstructorInfo[] makeCtorInfos(String[][] spec) {152final MBeanConstructorInfo[] result =153new MBeanConstructorInfo[spec.length];154final MBeanParameterInfo[] pars = makeParInfos(parameters);155for (int i=0;i<result.length;i++) {156System.out.println("\tCreate an MBeanConstructorInfo: " +157spec[i][0]);158final MBeanConstructorInfo item =159new MBeanConstructorInfo(spec[i][1],spec[i][0],pars);160result[i]=item;161}162return result;163}164165static private MBeanNotificationInfo[] makeNotifInfos(String[][] spec) {166final MBeanNotificationInfo[] result =167new MBeanNotificationInfo[spec.length];168final String[] types = {"valid.type","invalid-type"};169for (int i=0;i<result.length;i++) {170System.out.println("\tCreate an MBeanNotificationInfo: " +171spec[i][0]);172final MBeanNotificationInfo item =173new MBeanNotificationInfo(types,spec[i][1],spec[i][0]);174result[i]=item;175}176return result;177}178179public static void main(String[] args) throws Exception {180// Instantiate the MBean server181//182final MBeanAttributeInfo[] atts = makeAttInfos(attributes);183final MBeanConstructorInfo[] ctors = makeCtorInfos(constructors);184final MBeanOperationInfo[] ops = makeOpInfos(operations);185final MBeanNotificationInfo[] notifs =186makeNotifInfos(notificationclasses);187188for (int i=0; i<mbeanclasses.length;i++) {189System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);190final MBeanInfo mbi =191new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],192atts, ctors, ops, notifs);193}194195// Test OK!196//197System.out.println("All MBeanInfo successfuly created!");198System.out.println("Bye! Bye!");199}200}201202203