jdk/test/javax/management/modelmbean/RequiredModelMBeanGetAttributeTest.java
author dbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
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) 2005, 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 5043245
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test the following in RequiredModelMBean.getAttribute():
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * The declared type of the attribute is the String returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * ModelMBeanAttributeInfo.getType(). A value is compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * with this type if one of the following is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * - the value is null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * - the declared name is a primitive type name (such as "int")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *   and the value is an instance of the corresponding wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *   type (such as java.lang.Integer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * - the name of the value's class is identical to the declared name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * - the declared name can be loaded by the value's class loader and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *   produces a class to which the value can be assigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Luis-Miguel Alventosa
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    39
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @run clean RequiredModelMBeanGetAttributeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @run build RequiredModelMBeanGetAttributeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @run main RequiredModelMBeanGetAttributeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.modelmbean.DescriptorSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.management.modelmbean.ModelMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.modelmbean.ModelMBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.management.modelmbean.ModelMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.management.modelmbean.ModelMBeanInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.management.modelmbean.ModelMBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.management.modelmbean.RequiredModelMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class RequiredModelMBeanGetAttributeTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // Resource methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        Method nullGetter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            Resource.class.getMethod("getNull", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        Method integerGetter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            Resource.class.getMethod("getInteger", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Method hashtableGetter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            Resource.class.getMethod("getHashtable", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        Method mapGetter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            Resource.class.getMethod("getMap", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // ModelMBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Descriptor nullOperationDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                "name=getNull",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                "descriptorType=operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                "role=getter"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        ModelMBeanOperationInfo nullOperationInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            new ModelMBeanOperationInfo("Null attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                        nullGetter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                        nullOperationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        Descriptor integerOperationDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                "name=getInteger",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                "descriptorType=operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                "role=getter"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        ModelMBeanOperationInfo integerOperationInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            new ModelMBeanOperationInfo("Integer attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                        integerGetter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                        integerOperationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        Descriptor hashtableOperationDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                "name=getHashtable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                "descriptorType=operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                "role=getter"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ModelMBeanOperationInfo hashtableOperationInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            new ModelMBeanOperationInfo("Hashtable attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                        hashtableGetter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        hashtableOperationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Descriptor mapOperationDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                "name=getMap",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                "descriptorType=operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                "role=getter"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        ModelMBeanOperationInfo mapOperationInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            new ModelMBeanOperationInfo("Map attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                        mapGetter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                        mapOperationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // ModelMBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Descriptor nullAttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                "name=Null",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                "descriptorType=attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                "getMethod=getNull"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        ModelMBeanAttributeInfo nullAttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            new ModelMBeanAttributeInfo("Null",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                        "java.lang.Object",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                        "Null attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                        nullAttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Descriptor integerAttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                "name=Integer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                "descriptorType=attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                "getMethod=getInteger"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        ModelMBeanAttributeInfo integerAttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            new ModelMBeanAttributeInfo("Integer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                        "int",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                        "Integer attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                        integerAttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Descriptor hashtableAttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                "name=Hashtable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                "descriptorType=attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                "getMethod=getHashtable"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        ModelMBeanAttributeInfo hashtableAttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            new ModelMBeanAttributeInfo("Hashtable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                        "java.util.Hashtable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                        "Hashtable attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                        hashtableAttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Descriptor mapAttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                "name=Map",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                "descriptorType=attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                "getMethod=getMap"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        ModelMBeanAttributeInfo mapAttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            new ModelMBeanAttributeInfo("Map",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                        "java.util.Map",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                        "Map attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                        mapAttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Descriptor null2AttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                "name=Null2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                "descriptorType=attribute"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        null2AttributeDescriptor.setField("default", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        ModelMBeanAttributeInfo null2AttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            new ModelMBeanAttributeInfo("Null2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                        "java.lang.Object",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                        "Null2 attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                        null2AttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Descriptor integer2AttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                "name=Integer2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                "descriptorType=attribute"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        integer2AttributeDescriptor.setField("default", 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        ModelMBeanAttributeInfo integer2AttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            new ModelMBeanAttributeInfo("Integer2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                        "int",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                        "Integer2 attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                        integer2AttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Descriptor hashtable2AttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                "name=Hashtable2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                "descriptorType=attribute"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        hashtable2AttributeDescriptor.setField("default", new Hashtable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        ModelMBeanAttributeInfo hashtable2AttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            new ModelMBeanAttributeInfo("Hashtable2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                        "java.util.Hashtable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                        "Hashtable2 attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                        hashtable2AttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Descriptor map2AttributeDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            new DescriptorSupport(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                "name=Map2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                "descriptorType=attribute"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        map2AttributeDescriptor.setField("default", new Hashtable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        ModelMBeanAttributeInfo map2AttributeInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            new ModelMBeanAttributeInfo("Map2",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                        "java.util.Map",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                        "Map2 attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                        map2AttributeDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // ModelMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Resource.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            "Resource MBean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            new ModelMBeanAttributeInfo[] { nullAttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                            integerAttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                            hashtableAttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                            mapAttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                            null2AttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                            integer2AttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                            hashtable2AttributeInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                            map2AttributeInfo },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            new ModelMBeanOperationInfo[] { nullOperationInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                            integerOperationInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                            hashtableOperationInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                            mapOperationInfo },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // RequiredModelMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        ModelMBean mmb = new RequiredModelMBean(mmbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        mmb.setManagedResource(resource, "ObjectReference");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        ObjectName mmbName = new ObjectName(":type=ResourceMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        mbs.registerMBean(mmb, mmbName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // Run tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        System.out.println("\nTesting that we can call getNull()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            Object o = mbs.getAttribute(mmbName, "Null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println("getNull() = " + o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            System.out.println("Attribute's declared type = java.lang.Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            System.out.println("Returned value's type = null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        System.out.println("\nTesting that we can call getInteger()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            Integer i = (Integer) mbs.getAttribute(mmbName, "Integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            System.out.println("getInteger() = " + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            System.out.println("Attribute's declared type = int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                               i.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        System.out.println("\nTesting that we can call getHashtable()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            Hashtable h = (Hashtable) mbs.getAttribute(mmbName, "Hashtable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            System.out.println("getHashtable() = " + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            System.out.println("Attribute's declared type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                               "java.util.Hashtable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                               h.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        System.out.println("\nTesting that we can call getMap()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            Map m = (Map) mbs.getAttribute(mmbName, "Map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            System.out.println("getMap() = " + m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            System.out.println("Attribute's declared type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                               "java.util.Map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                               m.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        System.out.println("\nTesting that we can call getNull2()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            Object o = mbs.getAttribute(mmbName, "Null2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            System.out.println("getNull2() = " + o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            System.out.println("Attribute's declared type = java.lang.Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            System.out.println("Returned value's type = null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        System.out.println("\nTesting that we can call getInteger2()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            Integer i = (Integer) mbs.getAttribute(mmbName, "Integer2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            System.out.println("getInteger2() = " + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            System.out.println("Attribute's declared type = int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                               i.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        System.out.println("\nTesting that we can call getHashtable2()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            Hashtable h = (Hashtable) mbs.getAttribute(mmbName, "Hashtable2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            System.out.println("getHashtable2() = " + h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            System.out.println("Attribute's declared type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                               "java.util.Hashtable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                               h.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        System.out.println("\nTesting that we can call getMap2()... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            Map m = (Map) mbs.getAttribute(mmbName, "Map2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            System.out.println("getMap2() = " + m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            System.out.println("Attribute's declared type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                               "java.util.Map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            System.out.println("Returned value's type = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                               m.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            System.out.println("TEST FAILED: Caught exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            System.out.println("\nTest passed.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            System.out.println("\nTest failed.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public static class Resource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        public Object getNull() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        public int getInteger() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            return 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        public Hashtable getHashtable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        public Map getMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    private static Resource resource = new Resource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}