jdk/test/javax/management/openmbean/ConstraintTest.java
author dbuck
Tue, 18 Aug 2015 04:29:28 -0700
changeset 32417 6859107fc6c3
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux Reviewed-by: sla, mgronlun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6204469
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that Open MBean attributes and parameters check constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    29
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean ConstraintTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build ConstraintTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main ConstraintTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class ConstraintTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static String failure;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        for (Object[][] test : tests) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            if (test.length != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                throw new Exception("Test element has wrong length: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                                    Arrays.deepToString(test));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            if (test[0].length != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                throw new Exception("Test constraints should have size 4: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                    Arrays.deepToString(test[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            Object defaultValue = test[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            Comparable<?> minValue = (Comparable<?>) test[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            Comparable<?> maxValue = (Comparable<?>) test[0][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            Object[] legalValues = (Object[]) test[0][3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            System.out.println("test: defaultValue=" + defaultValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                               "; minValue=" + minValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                               "; maxValue=" + maxValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                               "; legalValues=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                               Arrays.deepToString(legalValues));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            if (test[1].length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                throw new Exception("OpenType list should have size 1: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                    Arrays.deepToString(test[1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            OpenType<?> openType = (OpenType<?>) test[1][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            Object[] valid = test[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            Object[] invalid = test[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            System.out.println("...valid=" + Arrays.deepToString(valid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            System.out.println("...invalid=" + Arrays.deepToString(invalid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            test(openType, defaultValue, minValue, maxValue, legalValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (failure == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new Exception("TEST FAILED: " + failure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static <T> void test(OpenType<T> openType, Object defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                 Comparable<?> minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                 Comparable<?> maxValue, Object[] legalValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                 Object[] valid, Object[] invalid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        /* This hack is needed to avoid grief from the parameter checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
           in the OpenMBean*InfoSupport constructors.  Since they are defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
           to check that the defaultValue etc are of the same type as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
           OpenType<T>, there is no way to pass a defaultValue etc when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
           the type is OpenType<?>.  So either you have to write plain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
           OpenType, and get unchecked warnings for every constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
           invocation, or you do this, and get the unchecked warnings just
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
           here.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        test1(openType, (T) defaultValue, (Comparable<T>) minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
              (Comparable<T>) maxValue, (T[]) legalValues, valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static <T> void test1(OpenType<T> openType, T defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                  Comparable<T> minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                  Comparable<T> maxValue, T[] legalValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                  Object[] valid, Object[] invalid)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (legalValues != null && (minValue != null || maxValue != null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new Exception("Test case has both legals and min/max");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (defaultValue == null && minValue == null && maxValue == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            legalValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                                   true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                   true, true, false, nullD),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                                   true, true, false, emptyD),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                                   nullD),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                                   emptyD),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (minValue == null && maxValue == null && legalValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            Descriptor d = descriptor("defaultValue", defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            test(new OpenMBeanAttributeInfoSupport("blah", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                                   true, true, false, d),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            test(new OpenMBeanAttributeInfoSupport("blah", "descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                                   openType, true, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                                   false, defaultValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            test(new OpenMBeanParameterInfoSupport("blah", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                                   d),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            test(new OpenMBeanParameterInfoSupport("blah", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                                   defaultValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (legalValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            Descriptor d = descriptor("defaultValue", defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                      "minValue", minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                      "maxValue", maxValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                                   true, true, false, d),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                   true, true, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                                   defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                                   minValue, maxValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                                   d),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                   defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                                   minValue, maxValue),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (minValue == null && maxValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            // Legal values in descriptor can be either an array or a set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            Descriptor d1 = descriptor("defaultValue", defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                       "legalValues", legalValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Descriptor d2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (legalValues == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                d2 = d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                d2 = descriptor("defaultValue", defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                "legalValues", arraySet(legalValues));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                                   true, true, false, d1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                   true, true, false, d2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            test(new OpenMBeanAttributeInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                                   true, true, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                                   defaultValue, legalValues),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                                   d1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                                   d2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            test(new OpenMBeanParameterInfoSupport("name", "descr", openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                                   defaultValue, legalValues),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                 valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /* Test one of the objects.  Note that OpenMBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
       extends OpenMBeanParameterInfo, so OpenMBeanAttributeInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
       is-an OpenMBeanParameterInfo.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private static void test(OpenMBeanParameterInfo info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                             Object[] valid, Object[] invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        test1(info, valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // Check that the constraints can be specified as strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // rather than objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (info.getOpenType() instanceof SimpleType<?>) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            Descriptor d = ((DescriptorRead) info).getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            String[] names = d.getFieldNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            Object[] values = d.getFieldValues(names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            for (int i = 0; i < values.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                if (values[i] == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (names[i].equals("legalValues")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    Collection<?> legals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    if (values[i] instanceof Collection<?>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                        legals = (Collection<?>) values[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        legals = Arrays.asList((Object[]) values[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    List<String> strings = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    for (Object legal : legals)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                        strings.add(legal.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    values[i] = strings.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                } else if (!(values[i] instanceof OpenType<?>))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    values[i] = values[i].toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            d = new ImmutableDescriptor(names, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            OpenType<?> ot = info.getOpenType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (info instanceof OpenMBeanAttributeInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                OpenMBeanAttributeInfo ai = (OpenMBeanAttributeInfo) info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                info = new OpenMBeanAttributeInfoSupport(info.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                                         info.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                                         info.getOpenType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                                         ai.isReadable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                                                         ai.isWritable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                                                         ai.isIs(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                                         d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                info = new OpenMBeanParameterInfoSupport(info.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                                         info.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                                         info.getOpenType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                                         d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            test1(info, valid, invalid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private static void test1(OpenMBeanParameterInfo info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                              Object[] valid, Object[] invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        for (Object x : valid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (!info.isValue(x)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                fail("Object should be valid but is not: " + x + " for: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                     info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        for (Object x : invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (info.isValue(x)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                fail("Object should not be valid but is: " + x + " for: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                     info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        /* If you specify e.g. minValue in a descriptor, then we arrange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
           for getMinValue() to return the same value, and if you specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
           a minValue as a constructor parameter then we arrange for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
           descriptor to have a minValue entry.  Check that these values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
           do in fact match.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        Descriptor d = ((DescriptorRead) info).getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        checkSameValue("defaultValue", info.getDefaultValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                       d.getFieldValue("defaultValue"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        checkSameValue("minValue", info.getMinValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                       d.getFieldValue("minValue"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        checkSameValue("maxValue", info.getMaxValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                       d.getFieldValue("maxValue"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        checkSameValues("legalValues", info.getLegalValues(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        d.getFieldValue("legalValues"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private static void checkSameValue(String what, Object getterValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                       Object descriptorValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (getterValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (descriptorValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                fail("Getter returned null but descriptor has entry for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                     what + ": " + descriptorValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        } else if (descriptorValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            fail("Getter returned value but descriptor has no entry for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                 what + ": " + getterValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        } else if (!getterValue.equals(descriptorValue) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                   !getterValue.toString().equals(descriptorValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            fail("For " + what + " getter returned " + getterValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                 " but descriptor entry is " + descriptorValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private static void checkSameValues(String what, Set<?> getterValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                        Object descriptorValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (getterValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (descriptorValues != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                fail("Getter returned null but descriptor has entry for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                     what + ": " + descriptorValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        } else if (descriptorValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            fail("Getter returned value but descriptor has no entry for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                 what + ": " + getterValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            Set<?> descriptorValueSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (descriptorValues instanceof Set<?>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                descriptorValueSet = (Set<?>) descriptorValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                descriptorValueSet = arraySet((Object[]) descriptorValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            boolean same = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (getterValues.size() != descriptorValueSet.size())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                same = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                for (Object x : getterValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    if (!descriptorValueSet.contains(x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        && !descriptorValueSet.contains(x.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        same = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (!same) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                fail("For " + what + " getter returned " + getterValues +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                     " but descriptor entry is " + descriptorValueSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private static void fail(String why) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        System.out.println("FAILED: " + why);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        failure = why;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private static Descriptor descriptor(Object... entries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (entries.length % 2 != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            throw new RuntimeException("Odd length descriptor entries");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        String[] names = new String[entries.length / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        Object[] values = new Object[entries.length / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        for (int i = 0; i < entries.length; i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            names[i / 2] = (String) entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            values[i / 2] = entries[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return new ImmutableDescriptor(names, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    private static <T> Set<T> arraySet(T[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return new HashSet<T>(Arrays.asList(array));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private static final OpenType<?>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        ostring = SimpleType.STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        oint = SimpleType.INTEGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        obool = SimpleType.BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        olong = SimpleType.LONG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        obyte = SimpleType.BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        ofloat = SimpleType.FLOAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        odouble = SimpleType.DOUBLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        ostringarray, ostringarray2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    private static final CompositeType ocomposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static final CompositeData compositeData, compositeData2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            ostringarray = new ArrayType<String[]>(1, ostring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            ostringarray2 = new ArrayType<String[][]>(2, ostring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            ocomposite =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                new CompositeType("name", "descr",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                                  new String[] {"s", "i"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                                  new String[] {"sdesc", "idesc"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                                  new OpenType[] {ostring, oint});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            compositeData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                new CompositeDataSupport(ocomposite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                         new String[] {"s", "i"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                         new Object[] {"foo", 23});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            compositeData2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                new CompositeDataSupport(ocomposite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                                         new String[] {"s", "i"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                         new Object[] {"bar", -23});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } catch (OpenDataException e) { // damn checked exceptions...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new IllegalArgumentException(e.toString(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private static final Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        nullD = null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        emptyD = ImmutableDescriptor.EMPTY_DESCRIPTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /* The elements of this array are grouped as follows.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
       element contains four Object[]s.  The first one is a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
       four values: default value, min value, max value, legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
       (an Object[]), some of which can be null.  These will be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
       to derive the OpenMBean*Info values to be tested.  The second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
       is an array with one element that is the OpenType that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
       given to the constructors of the OpenMBean*Infos.  The third
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
       element is a set of values that should be valid according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
       the constraints in the OpenMBean*Info.  The fourth is a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
       values that should be invalid according to those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
       constraints.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    private static final Object[][][] tests = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Test cases when there are no constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // Validity checking is limited to type of object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         {-1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         {null, "noddy", 1.3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         {obool},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         {true, false},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         {null, "noddy", 1.3, 3, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         {ostring},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         {"", "yes!"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         {null, 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         {obyte},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte) 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         {null, "noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         {ostringarray},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         {new String[0], new String[] {"hello", "world"}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         {null, "noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         {ostringarray2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         {new String[0][0], new String[][] {{"hello", "world"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                            {"goodbye", "cruel", "world"}}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         {null, "noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        {{null, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         {ocomposite},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         {compositeData, compositeData2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         {null, "noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // Test cases where there is a default value, so null is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        {{23, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         {null, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         {"noddy", 1.3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        {{true, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
         {obool},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         {null, true, false},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         {"noddy", 1.3, 3, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        {{"foo", null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
         {ostring},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
         {null, "", "yes!"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         {1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        {{(byte) 23, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         {obyte},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         {null, Byte.MIN_VALUE, Byte.MAX_VALUE, (byte) 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         {"noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        {{compositeData, null, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         {ocomposite},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         {null, compositeData, compositeData2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         {"noddy", 1.3, 3, false, 3L, Long.MAX_VALUE, emptyD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
          new int[2], new Integer[2], new Integer[] {3}, new Integer[0]}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        // Test cases where there is a min and/or max, with or without default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        {{23, 0, 50, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         {null, 0, 25, 50},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         {"noddy", -1, 51, Integer.MIN_VALUE, Integer.MAX_VALUE, 25L}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        {{null, 0, 50, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
         {0, 25, 50},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
         {null, "noddy", -1, 51, Integer.MIN_VALUE, Integer.MAX_VALUE, 25L}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        {{null, 0, null, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         {0, 25, 50, Integer.MAX_VALUE},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         {null, "noddy", -1, Integer.MIN_VALUE, 25L}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        {{null, null, 50, null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         {Integer.MIN_VALUE, -1, 0, 25, 50},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         {null, "noddy", 51, Integer.MAX_VALUE, 25L}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        {{"go", "a", "z~", null},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         {ostring},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         {null, "a", "z~", "zzzz", "z!"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         {"A", "~", "", -1}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        // Test cases where there is a set of legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        {{23, null, null, new Integer[] {2, 3, 5, 7, 11, 13, 17, 23}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         {oint},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         {null, 2, 11, 23},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         {"noddy", -1, 1, 51, Integer.MIN_VALUE, Integer.MAX_VALUE, 25L}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        {{null, null, null, new CompositeData[] {compositeData}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         {ocomposite},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         {compositeData},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         {null, compositeData2, "noddy"}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        {{null, null, null, new Long[0]},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         {olong},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         {}, // constraint is impossible to satisfy!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         {null, 23L, "x", 23}},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
}