jdk/test/javax/management/modelmbean/InfoSupportTest.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 2004 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 4967769 4980655 4980668 4981214
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that ModelMBeanInfoSupport.setDescriptor rejects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * null descriptor, that empty arrays are handled correctly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * that getDescriptors("mbean") works, and that default values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * MBean descriptors are correctly assigned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run clean InfoSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run build InfoSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @run main InfoSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.modelmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class InfoSupportTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        ok &= testSetDescriptorNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        ok &= testEmptyArrayParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        ok &= testGetDescriptorsForMBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            System.out.println("TEST FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static boolean testSetDescriptorNull() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.out.println("Testing that " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                           "ModelMBeanInfoSupport.setDescriptor(null, \"x\")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                           " throws an exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        ModelMBeanAttributeInfo mmbai =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            new ModelMBeanAttributeInfo("attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                        "java.lang.String",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                        "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                        true, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        ModelMBeanInfo mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            new ModelMBeanInfoSupport("bogus.class.name",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                      "an MBean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                      new ModelMBeanAttributeInfo[] {mmbai},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                      null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            mmbi.setDescriptor(null, "attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } catch (RuntimeOperationsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            if (e.getTargetException() instanceof IllegalArgumentException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                System.out.println("Test passes: got a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                   "RuntimeOperationsException wrapping an " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                   "IllegalArgumentException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                System.out.println("TEST FAILS: wrong exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            System.out.println("TEST FAILS: wrong exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        System.out.println("TEST FAILS: exception not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static boolean testEmptyArrayParameters()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        System.out.println("Test that empty and null array parameters " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                           "produce the right type from getters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        ModelMBeanInfoSupport mmbi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                      null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ok &= checkMMBI(mmbi, "null parameters, no descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                      null, null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        ok &= checkMMBI(mmbi, "null parameters, null descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                      new ModelMBeanAttributeInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                      new ModelMBeanConstructorInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                      new ModelMBeanOperationInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                      new ModelMBeanNotificationInfo[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        ok &= checkMMBI(mmbi, "empty parameters, no descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                      new ModelMBeanAttributeInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                      new ModelMBeanConstructorInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                      new ModelMBeanOperationInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                      new ModelMBeanNotificationInfo[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ok &= checkMMBI(mmbi, "empty parameters, null descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static boolean checkMMBI(ModelMBeanInfoSupport mmbi, String what)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        String bad = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (!(mmbi.getAttributes() instanceof ModelMBeanAttributeInfo[]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            bad += " attributes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!(mmbi.getConstructors() instanceof ModelMBeanConstructorInfo[]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            bad += " constructors";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (!(mmbi.getOperations() instanceof ModelMBeanOperationInfo[]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            bad += " operations";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!(mmbi.getNotifications() instanceof ModelMBeanNotificationInfo[]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            bad += " notifications";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (bad.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            System.out.println("..." + what + ": OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.out.println("..." + what + ": FAILS for:" + bad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private static boolean testGetDescriptorsForMBean()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        System.out.println("Test getDescriptors(\"mbean\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        ModelMBeanInfo mmbi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Descriptor[] mbeanDescrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        mmbi = new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                         null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            mbeanDescrs = mmbi.getDescriptors("mbean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (mbeanDescrs.length == 1 && mbeanDescrs[0] != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                System.out.println("...default MBean descriptor: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                System.out.println("...default MBean descriptor: bad array: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                   Arrays.asList(mbeanDescrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            System.out.println("...default MBean descriptor: got exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        String[] fields = new String[] {"descriptorType", "name"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        String[] values = new String[] {"mbean", "whatsit"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        String[] defaultFields = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            "displayName", "persistPolicy", "log", "visibility",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        String[] defaultValues = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            "bogus.class.name", "never", "F", "1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Descriptor d = new DescriptorSupport(fields, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        mmbi = new ModelMBeanInfoSupport("bogus.class.name", "description",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                         null, null, null, null, d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            mbeanDescrs = mmbi.getDescriptors("mbean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            System.out.println("...explicit MBean descriptor: got exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            mbeanDescrs = new Descriptor[] {mmbi.getMBeanDescriptor()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (mbeanDescrs.length == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            Descriptor dd = mbeanDescrs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            boolean thisok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // Check that the fields we supplied survived in the copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // and were not changed in the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                String field = fields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                value = (String) dd.getFieldValue(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                if (!values[i].equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    System.out.println("...explicit MBean descriptor: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                       "value of " + field + " mutated: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                       value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    thisok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                value = (String) d.getFieldValue(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                if (!values[i].equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    System.out.println("...explicit MBean descriptor: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                       "value of " + field + " changed in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                       "original: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    thisok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // Check that the default fields were added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            for (int i = 0; i < defaultFields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                String field = defaultFields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                String value = (String) dd.getFieldValue(field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                if (!defaultValues[i].equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    System.out.println("...explicit MBean descriptor: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                       "default value of " + field +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                       " wrong: " + value + " should be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                       defaultValues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    thisok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            // Check that the original did not acquire new fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (d.getFieldNames().length != fields.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                Collection c = new TreeSet(Arrays.asList(d.getFieldNames()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                c.removeAll(Arrays.asList(fields));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                System.out.println("...explicit MBean descriptor: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                   "acquired new fields: " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                thisok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (thisok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                System.out.println("...explicit MBean descriptor: OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            System.out.println("...explicit MBean descriptor: bad array: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                               Arrays.asList(mbeanDescrs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}