Path: blob/master/test/jdk/javax/management/MustBeValidMBeanInfo/MustBeValidCommand.java
41152 views
/*1* Copyright (c) 2003, 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 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*31* @run clean MustBeValidCommand32* @run build MustBeValidCommand33* @run main MustBeValidCommand34*/3536import javax.management.MBeanInfo;37import javax.management.MBeanAttributeInfo;38import javax.management.MBeanOperationInfo;39import javax.management.MBeanParameterInfo;40import javax.management.MBeanNotificationInfo;41import javax.management.MBeanConstructorInfo;4243public class MustBeValidCommand {4445private static String[][] attributes = {46{ "Attribute with valid identifiers",47"validType1","validNameAtt1" },48{ "Attribute with invalid type",49"invalid-type", "validNameAtt2" },50{ "Attribute with invalid name", "valid.type2",51"invalid-name-att3" },52{ "Attribute with invalid name and type",53"invalidtype[]","invalid.name.att4" }54};55private static String[][] constructors = {56{ "Constructor with valid name",57"ValidConstructor1" },58{ "Constructor with invalid name",59"invalid.Constructor2"},60{ "Constructor with invalid name",61"invalid-constructor-3" },62{ "Constructor with invalid name",63"invalid constructor" }64};65private static String[][] mbeanclasses = {66{ "MBean with valid class name",67"ValidMBeanClass1" },68{ "MBean with valid class name",69"valid.mbean.Class2" },70{ "MBean with invalid class name",71"invalid.MBeanClass3[]"},72{ "MBean with invalid class name",73"invalid-mbean-class-4" },74{ "MBean with invalid class name",75"invalid mbean class 5" }76};77private static String[][] notificationclasses = {78{ "Notification with valid class name",79"ValidNotificationClass1" },80{ "Notification with valid class name",81"valid.notification.Class2" },82{ "Notification with invalid class name",83"invalid.NotificationClass3[]"},84{ "Notification with invalid class name",85"invalid-notification-class-4" },86{ "Notification with invalid class name",87"invalid notification class 5" }88};89private static String[][] operations = {90{ "Operation with valid identifiers",91"validType1","validNameOp1" },92{ "Operation with invalid type",93"invalid-type", "validNameOp2" },94{ "Operation with invalid name", "valid.type2",95"invalid-name-op3" },96{ "Operation with invalid name and type",97"invalidtype[]","invalid.name.op4" }98};99private static String[][] parameters = {100{ "Parameter with valid identifiers",101"validType1","validNamePar1" },102{ "Parameter with invalid type",103"invalid-type", "validNamePar2" },104{ "Parameter with invalid name", "valid.type2",105"invalid-name-par3" },106{ "Parameter with invalid name and type",107"invalidtype[]","invalid.name.par4" }108};109110static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {111final MBeanAttributeInfo[] result =112new MBeanAttributeInfo[spec.length];113for (int i=0;i<result.length;i++) {114System.out.println("\tCreate an MBeanAttributeInfo: " +115spec[i][0]);116final MBeanAttributeInfo item =117new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],118true,true,false);119result[i]=item;120}121return result;122}123124static private MBeanParameterInfo[] makeParInfos(String[][] spec) {125final MBeanParameterInfo[] result =126new MBeanParameterInfo[spec.length];127for (int i=0;i<result.length;i++) {128System.out.println("\tCreate an MBeanParameterInfo: " +129spec[i][0]);130final MBeanParameterInfo item =131new MBeanParameterInfo(spec[i][2],spec[i][1],spec[i][0]);132result[i]=item;133}134return result;135}136137static private MBeanOperationInfo[] makeOpInfos(String[][] spec) {138final MBeanOperationInfo[] result =139new MBeanOperationInfo[spec.length];140final MBeanParameterInfo[] pars = makeParInfos(parameters);141for (int i=0;i<result.length;i++) {142System.out.println("\tCreate an MBeanOperationInfo: " +143spec[i][0]);144final MBeanOperationInfo item =145new MBeanOperationInfo(spec[i][2],spec[i][0],pars,spec[i][1],146MBeanOperationInfo.ACTION_INFO);147result[i]=item;148}149return result;150}151152static private MBeanConstructorInfo[] makeCtorInfos(String[][] spec) {153final MBeanConstructorInfo[] result =154new MBeanConstructorInfo[spec.length];155final MBeanParameterInfo[] pars = makeParInfos(parameters);156for (int i=0;i<result.length;i++) {157System.out.println("\tCreate an MBeanConstructorInfo: " +158spec[i][0]);159final MBeanConstructorInfo item =160new MBeanConstructorInfo(spec[i][1],spec[i][0],pars);161result[i]=item;162}163return result;164}165166static private MBeanNotificationInfo[] makeNotifInfos(String[][] spec) {167final MBeanNotificationInfo[] result =168new MBeanNotificationInfo[spec.length];169final String[] types = {"valid.type","invalid-type"};170for (int i=0;i<result.length;i++) {171System.out.println("\tCreate an MBeanNotificationInfo: " +172spec[i][0]);173final MBeanNotificationInfo item =174new MBeanNotificationInfo(types,spec[i][1],spec[i][0]);175result[i]=item;176}177return result;178}179180public static void main(String[] args) throws Exception {181// Instantiate the MBean server182//183final MBeanAttributeInfo[] atts = makeAttInfos(attributes);184final MBeanConstructorInfo[] ctors = makeCtorInfos(constructors);185final MBeanOperationInfo[] ops = makeOpInfos(operations);186final MBeanNotificationInfo[] notifs =187makeNotifInfos(notificationclasses);188189for (int i=0; i<mbeanclasses.length;i++) {190System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);191final MBeanInfo mbi =192new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],193atts, ctors, ops, notifs);194}195196// Test OK!197//198System.out.println("All MBeanInfo successfuly created!");199System.out.println("Bye! Bye!");200}201}202203204