jdk/test/javax/management/modelmbean/DescriptorSupportTest.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 2003-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 4883712 4869006 4894856 5016685
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that DescriptorSupport correctly validates fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run clean DescriptorSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run build DescriptorSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main DescriptorSupportTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.modelmbean.DescriptorSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.modelmbean.ModelMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.modelmbean.ModelMBeanInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class DescriptorSupportTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final Object[] goodFields = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        "value", "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        "severity", "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        "severity", "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final Object[] badFields = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        "name", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        "name", "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        "descriptorType", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "descriptorType", "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        "setMethod", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "getMethod", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "role", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "class", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        "visibility", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        "visibility", new Integer(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        "visibility", "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        "visibility", new Integer(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        "visibility", "5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        "severity", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        "severity", new Integer(-1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        "severity", "-1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        "severity", new Integer(7),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        "severity", "7",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        "persistPolicy", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        "persistPolicy", "bogusPersistPolicy",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        "persistPeriod", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        "persistPeriod", "not a number",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        "currencyTimeLimit", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        "currencyTimeLimit", "not a number",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        "lastUpdatedTimeStamp", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        "lastUpdatedTimeStamp", "not a number",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        "lastReturnedTimeStamp", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        "lastReturnedTimeStamp", "not a number",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "log", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        "log", "not T or F or true or false",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        "log", new Object[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        System.out.println("Checking that name and descriptorType are " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                           "mandatory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Try omitting name and/or descriptorType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        for (int i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            final boolean addName = ((i & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            final boolean addDescriptorType = ((i & 2) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            final List fields = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (addName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                fields.add("name=something");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (addDescriptorType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                fields.add("descriptorType=something-else");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            final String[] fs = (String[]) fields.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            final String what =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    "DescriptorSupport with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    (addName ? "" : "no ") + "name and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    (addDescriptorType ? "" : "no ") + "descriptorType";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            DescriptorSupport ds = new DescriptorSupport(fs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (ds.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                System.out.println("INCORRECTLY ACCEPTED: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                System.out.println("OK: rejected " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        for (int pass = 0; pass < 2; pass++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            boolean shouldAccept = (pass == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            System.out.println("Trying out " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                               (shouldAccept ? "correct" : "bogus") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                               " DescriptorSupport fields");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            Object[] fields = shouldAccept ? goodFields : badFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            for (int i = 0; i < fields.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                String[] names = {"name", "descriptorType"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                String[] values = {"some-name", "some-type"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                DescriptorSupport d = new DescriptorSupport(names, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                final String name = (String) fields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                final Object value = fields[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                final String valueS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    (value instanceof String) ? ("\"" + value + "\"") :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    (value == null) ? "null" : value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                final String what =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    "DescriptorSupport with " + name + " = " + valueS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    d.setField(name, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    if (shouldAccept)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        System.out.println("OK: accepted " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        System.out.println("INCORRECTLY ACCEPTED: " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                } catch (RuntimeOperationsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    if (shouldAccept) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        System.out.println("INCORRECTLY REJECTED: " + what +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                           ": " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        System.out.println("OK: rejected " + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        // OK: this is what should happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    System.out.println("WRONG EXCEPTION: " + what + ": " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // 4894856: ModelMBeanInfoSupport.setDescriptor(d, "mbean") fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        System.out.println("Checking that setDescriptor(d, \"mbean\") works");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        ModelMBeanInfo mmbi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            new ModelMBeanInfoSupport("x", "descr", null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Descriptor d = mmbi.getDescriptor("x", "mbean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            mmbi.setDescriptor(d, "mbean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.out.println("Unexpected exception:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        // 5016685: DescriptorSupport forces field names to lower case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        System.out.println("Checking that field name case is ignored " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                           "but preserved");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        ok &= caseTest(new DescriptorSupport(new String[] {"NAME=blah"}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                       "DescriptorSupport(String[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        ok &= caseTest(new DescriptorSupport(new String[] {"NAME"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                             new String[] {"blah"}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                       "DescriptorSupport(String[], Object[])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        DescriptorSupport d1 = new DescriptorSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        d1.setField("NAME", "blah");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        ok &= caseTest(d1, "DescriptorSupport.setField");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        d1 = new DescriptorSupport(new String[] {"NAME=blah"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        ok &= caseTest(new DescriptorSupport(d1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                       "DescriptorSupport(Descriptor)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        d1 = new DescriptorSupport(new String[] {"NAME=blah"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        ok &= caseTest(new DescriptorSupport(d1.toXMLString()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                       "DescriptorSupport(String)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        d1 = new DescriptorSupport(new String[] {"NAME=blah"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        ObjectOutputStream oos = new ObjectOutputStream(bos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        oos.writeObject(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        oos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        bos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        ObjectInputStream ois = new ObjectInputStream(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        d1 = (DescriptorSupport) ois.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        ok &= caseTest(d1, "serialized DescriptorSupport");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            System.out.println("TEST FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private static boolean caseTest(Descriptor d, String what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        System.out.println("..." + what);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        String[] names = d.getFieldNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (names.length != 1 || !names[0].equals("NAME")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.out.println("...getFieldNames() fails: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                               Arrays.asList(names));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        String[] fields = d.getFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (fields.length != 1 || !fields[0].equals("NAME=blah")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            System.out.println("...getFields() fails: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                               Arrays.asList(fields));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        Object value = d.getFieldValue("namE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (!"blah".equals(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            System.out.println("...getFieldValue(\"namE\") fails: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Object[] values = d.getFieldValues(new String[] {"namE"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (values.length != 1 || !"blah".equals(values[0])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            System.out.println("...getFieldValues({\"namE\"}) fails: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                               Arrays.asList(values));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        d.setField("namE", "newblah");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Object newblah = d.getFieldValue("Name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (!"newblah".equals(newblah)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            System.out.println("...setField value not returned: " + newblah);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        d.setFields(new String[] {"NaMe"}, new Object[] {"newerblah"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        Object newerblah = d.getFieldValue("naMe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (!"newerblah".equals(newerblah)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            System.out.println("...setFields value not returned: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                               newerblah);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        Descriptor d1 = (Descriptor) d.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        newerblah = d1.getFieldValue("NAMe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (!"newerblah".equals(newerblah)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            System.out.println("...clone incorrect: " + newerblah);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        d.removeField("NAme");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        names = d.getFieldNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (names.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            System.out.println("...removeField failed: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                               Arrays.asList(names));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            System.out.println("...succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}