jdk/test/javax/management/MustBeValidMBeanInfo/MustBeValidCommand.java
author xuelei
Thu, 18 Oct 2012 01:14:00 -0700
changeset 14194 971f46db533d
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server Reviewed-by: mullan, weijun, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main MustBeValidCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class MustBeValidCommand {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static String[][] attributes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        { "Attribute with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
          "validType1","validNameAtt1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        { "Attribute with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
          "invalid-type",   "validNameAtt2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        { "Attribute with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
          "invalid-name-att3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        { "Attribute with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
          "invalidtype[]","invalid.name.att4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static String[][] constructors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        { "Constructor with valid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
          "ValidConstructor1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
          "invalid.Constructor2"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
          "invalid-constructor-3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        { "Constructor with invalid name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
          "invalid constructor" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static String[][] mbeanclasses = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        { "MBean with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
          "ValidMBeanClass1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        { "MBean with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
          "valid.mbean.Class2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
          "invalid.MBeanClass3[]"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
          "invalid-mbean-class-4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        { "MBean with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
          "invalid mbean class 5" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static String[][] notificationclasses = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        { "Notification with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
          "ValidNotificationClass1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        { "Notification with valid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
          "valid.notification.Class2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
          "invalid.NotificationClass3[]"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
          "invalid-notification-class-4" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        { "Notification with invalid class name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
          "invalid notification class 5" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static String[][] operations = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        { "Operation with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
          "validType1","validNameOp1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        { "Operation with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
          "invalid-type",   "validNameOp2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        { "Operation with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
          "invalid-name-op3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        { "Operation with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
          "invalidtype[]","invalid.name.op4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static String[][] parameters = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        { "Parameter with valid identifiers",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
          "validType1","validNamePar1" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        { "Parameter with invalid type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          "invalid-type",   "validNamePar2" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        { "Parameter with invalid name", "valid.type2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
          "invalid-name-par3" },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        { "Parameter with invalid name and type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
          "invalidtype[]","invalid.name.par4" }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    static private MBeanAttributeInfo[] makeAttInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        final MBeanAttributeInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            new MBeanAttributeInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            System.out.println("\tCreate an MBeanAttributeInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            final MBeanAttributeInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                new MBeanAttributeInfo(spec[i][2],spec[i][1],spec[i][0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                       true,true,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static private MBeanParameterInfo[] makeParInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        final MBeanParameterInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            new MBeanParameterInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            System.out.println("\tCreate an MBeanParameterInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            final MBeanParameterInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                new MBeanParameterInfo(spec[i][2],spec[i][1],spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static private MBeanOperationInfo[] makeOpInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        final MBeanOperationInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            new MBeanOperationInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        final MBeanParameterInfo[] pars = makeParInfos(parameters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            System.out.println("\tCreate an MBeanOperationInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            final MBeanOperationInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                new MBeanOperationInfo(spec[i][2],spec[i][0],pars,spec[i][1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                       MBeanOperationInfo.ACTION_INFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    static private MBeanConstructorInfo[] makeCtorInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        final MBeanConstructorInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            new MBeanConstructorInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        final MBeanParameterInfo[] pars = makeParInfos(parameters);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            System.out.println("\tCreate an MBeanConstructorInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            final MBeanConstructorInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                new MBeanConstructorInfo(spec[i][1],spec[i][0],pars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    static private MBeanNotificationInfo[] makeNotifInfos(String[][] spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        final MBeanNotificationInfo[] result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            new MBeanNotificationInfo[spec.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        final String[] types = {"valid.type","invalid-type"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        for (int i=0;i<result.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            System.out.println("\tCreate an MBeanNotificationInfo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                               spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            final MBeanNotificationInfo item =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                new MBeanNotificationInfo(types,spec[i][1],spec[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            result[i]=item;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // Instantiate the MBean server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        final MBeanAttributeInfo[]    atts   = makeAttInfos(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        final MBeanConstructorInfo[]  ctors  = makeCtorInfos(constructors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        final MBeanOperationInfo[]    ops    = makeOpInfos(operations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        final MBeanNotificationInfo[] notifs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            makeNotifInfos(notificationclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        for (int i=0; i<mbeanclasses.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            System.out.println("Create an MBeanInfo: " + mbeanclasses[i][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            final MBeanInfo mbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                new MBeanInfo(mbeanclasses[i][1],mbeanclasses[i][0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                              atts, ctors, ops, notifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // Test OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        System.out.println("All MBeanInfo successfuly created!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.out.println("Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}