jdk/test/javax/management/MustBeValidMBeanInfo/MustBeValidCommand.java
author rprotacio
Wed, 02 Mar 2016 15:10:38 -0500
changeset 36396 26a241a959de
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8145098: JNI GetVersion should return JNI_VERSION_9 Summary: Updated JNI_VERSION for current version to be JNI_VERSION_9 Reviewed-by: hseigel, gtriantafill, dholmes, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4874819
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that MBeanInfo classes no longer throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * IllegalArgumentException when attribute names, operation names, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Java type names do not strictly follow the expected Java syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @author Daniel Fuchs
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    31
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run clean MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run build MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class MustBeValidCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static String[][] attributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        { "Attribute with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
          "validType1","validNameAtt1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        { "Attribute with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
          "invalid-type",   "validNameAtt2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        { "Attribute with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
          "invalid-name-att3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        { "Attribute with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
          "invalidtype[]","invalid.name.att4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static String[][] constructors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        { "Constructor with valid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
          "ValidConstructor1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
          "invalid.Constructor2"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
          "invalid-constructor-3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
          "invalid constructor" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static String[][] mbeanclasses = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        { "MBean with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
          "ValidMBeanClass1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        { "MBean with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
          "valid.mbean.Class2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
          "invalid.MBeanClass3[]"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
          "invalid-mbean-class-4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
          "invalid mbean class 5" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static String[][] notificationclasses = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        { "Notification with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
          "ValidNotificationClass1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        { "Notification with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
          "valid.notification.Class2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
          "invalid.NotificationClass3[]"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
          "invalid-notification-class-4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
          "invalid notification class 5" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static String[][] operations = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        { "Operation with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
          "validType1","validNameOp1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        { "Operation with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
          "invalid-type",   "validNameOp2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        { "Operation with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
          "invalid-name-op3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        { "Operation with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
          "invalidtype[]","invalid.name.op4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static String[][] parameters = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        { "Parameter with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          "validType1","validNamePar1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        { "Parameter with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
          "invalid-type",   "validNamePar2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        { "Parameter with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
          "invalid-name-par3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        { "Parameter with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
          "invalidtype[]","invalid.name.par4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        final MBeanAttributeInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            new MBeanAttributeInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            System.out.println("\tCreate an MBeanAttributeInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            final MBeanAttributeInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                       true,true,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static private MBeanParameterInfo[] makeParInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        final MBeanParameterInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            new MBeanParameterInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            System.out.println("\tCreate an MBeanParameterInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            final MBeanParameterInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                new MBeanParameterInfo(spec[i][2],spec[i][1],spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    static private MBeanOperationInfo[] makeOpInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        final MBeanOperationInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            new MBeanOperationInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        final MBeanParameterInfo[] pars = makeParInfos(parameters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            System.out.println("\tCreate an MBeanOperationInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            final MBeanOperationInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                new MBeanOperationInfo(spec[i][2],spec[i][0],pars,spec[i][1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                       MBeanOperationInfo.ACTION_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    static private MBeanConstructorInfo[] makeCtorInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        final MBeanConstructorInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            new MBeanConstructorInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        final MBeanParameterInfo[] pars = makeParInfos(parameters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            System.out.println("\tCreate an MBeanConstructorInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            final MBeanConstructorInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                new MBeanConstructorInfo(spec[i][1],spec[i][0],pars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    static private MBeanNotificationInfo[] makeNotifInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        final MBeanNotificationInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            new MBeanNotificationInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        final String[] types = {"valid.type","invalid-type"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            System.out.println("\tCreate an MBeanNotificationInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            final MBeanNotificationInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                new MBeanNotificationInfo(types,spec[i][1],spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Instantiate the MBean server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        final MBeanAttributeInfo[]    atts   = makeAttInfos(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        final MBeanConstructorInfo[]  ctors  = makeCtorInfos(constructors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        final MBeanOperationInfo[]    ops    = makeOpInfos(operations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        final MBeanNotificationInfo[] notifs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            makeNotifInfos(notificationclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        for (int i=0; i<mbeanclasses.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            final MBeanInfo mbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                              atts, ctors, ops, notifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // Test OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.out.println("All MBeanInfo successfuly created!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        System.out.println("Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
}