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