test/jdk/javax/management/MBeanInfo/MBeanInfoEqualsTest.java
author herrick
Mon, 28 Oct 2019 11:21:43 -0400
branchJDK-8200758-branch
changeset 58818 a9316bb4c0e8
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
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) 2003, 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 4719923
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that MBeanInfo.equals works even for mutable subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean MBeanInfoEqualsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build MBeanInfoEqualsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main MBeanInfoEqualsTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/* Test that MBeanInfo and its referenced classes implement the equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
   and hashCode methods correctly.  These classes include some magic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
   to improve performance based on the classes' immutability.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
   logic checks that any subclasses encountered remain immutable, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
   falls back on less performant code if not.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class MBeanInfoEqualsTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    // Class just used for reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static class Toy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        public Toy() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        public Toy(int a, String b) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        public int getA() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        public void setA(int a) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        public boolean isB() {return false;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        public void setB(boolean b) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        public void run() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        public void blah(int a, String b) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final Class toy = Toy.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static final Constructor con1, con2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static final Method getA, setA, isB, setB, run, blah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            con1 = toy.getConstructor(new Class[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            con2 = toy.getConstructor(new Class[] {Integer.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                                   String.class});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            getA = toy.getMethod("getA", new Class[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            setA = toy.getMethod("setA", new Class[] {Integer.TYPE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            isB  = toy.getMethod("isB",  new Class[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            setB = toy.getMethod("setB", new Class[] {Boolean.TYPE});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            run  = toy.getMethod("run",  new Class[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            blah = toy.getMethod("blah", new Class[] {Integer.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                                      String.class});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            throw new Error(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final MBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        newMBeanAttributeInfo(String name, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                              Method getter, Method setter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return new MBeanAttributeInfo(name, description, getter, setter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (IntrospectionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            throw new Error(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    static final MBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        a1a = new MBeanAttributeInfo("thing", "java.foo.bar", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                     true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        a1b = new MBeanAttributeInfo("thing", "java.foo.bar", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                     true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        a2a = new MBeanAttributeInfo("splob", "java.foo.bar", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                     true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        a2b = new MBeanAttributeInfo(a2a.getName(), a2a.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                     a2a.getDescription(), a2a.isReadable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                     a2a.isWritable(), a2a.isIs()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        a3  = new MBeanAttributeInfo("splob", "java.foo.bar", "a whatsit",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                     true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        a4  = new MBeanAttributeInfo("splob", "java.foo.bar", "a whatsit",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                     false, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        a5a = newMBeanAttributeInfo("a", "an attribute", getA, setA),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        a5b = new MBeanAttributeInfo("a", "int", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                     true, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        a6a = newMBeanAttributeInfo("a", "an attribute", getA, null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        a6b = new MBeanAttributeInfo("a", "int", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                     true, false, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        a7a = newMBeanAttributeInfo("a", "an attribute", null, setA),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        a7b = new MBeanAttributeInfo("a", "int", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                     false, true, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        a8a = newMBeanAttributeInfo("b", "an attribute", isB, setB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        a8b = new MBeanAttributeInfo("b", "boolean", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                     true, true, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        a9a = newMBeanAttributeInfo("b", "an attribute", isB, null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        a9b = new MBeanAttributeInfo("b", "boolean", "an attribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                     true, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    static final MBeanParameterInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        p1a = new MBeanParameterInfo("thing", "java.foo.bar", "a parameter"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        p1b = new MBeanParameterInfo("thing", "java.foo.bar", "a parameter"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        p2  = new MBeanParameterInfo("splob", "java.foo.bar", "a parameter"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        p3  = new MBeanParameterInfo("thing", "java.foo.bax", "a parameter"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        p4  = new MBeanParameterInfo("thing", "java.foo.bar", "a whatsit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static final MBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        c1a = new MBeanConstructorInfo("a constructor", con1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        c1b = new MBeanConstructorInfo(c1a.getName(), "a constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                       new MBeanParameterInfo[0]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        c1c = new MBeanConstructorInfo(c1a.getName(), c1a.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                       c1a.getSignature()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        c1d = new MBeanConstructorInfo(c1a.getName(), c1a.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                       null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        c2a = new MBeanConstructorInfo("another constructor", con2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        c2b = new MBeanConstructorInfo(c2a.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                       c2a.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                       c2a.getSignature()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        c3a = new MBeanConstructorInfo("conName", "a constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                       new MBeanParameterInfo[] {p2, p3}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        c3b = new MBeanConstructorInfo("conName", "a constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                       new MBeanParameterInfo[] {p2, p3}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        c4  = new MBeanConstructorInfo("conName", "a constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                       new MBeanParameterInfo[] {p3, p2}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        c5  = new MBeanConstructorInfo("otherName", "a constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                       new MBeanParameterInfo[] {p3, p2}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        c6  = new MBeanConstructorInfo("otherName", "another constructor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                       new MBeanParameterInfo[] {p3, p2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    static final MBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        o1a = new MBeanOperationInfo("an operation", run),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        o1b = new MBeanOperationInfo("an operation", run),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        o1c = new MBeanOperationInfo("run", "an operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                     o1a.getSignature(), "void",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                     o1a.getImpact()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        o1d = new MBeanOperationInfo("run", "an operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                     new MBeanParameterInfo[0], "void",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                     o1a.getImpact()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        o1e = new MBeanOperationInfo("run", "an operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                     null, "void",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                     o1a.getImpact()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        o2a = new MBeanOperationInfo("another operation", blah),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        o2b = new MBeanOperationInfo(o2a.getName(), o2a.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                     o2a.getSignature(), o2a.getReturnType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                     o2a.getImpact());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    static final MBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        n1a = new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                        "x.y.z",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                        "a notification info"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        n1b = new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                        "x.y.z",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                        "a notification info"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        n2a = new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                        "x.y.z",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                        "another notification info"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        n2b = new MBeanNotificationInfo(n2a.getNotifTypes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                        n2a.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                        n2a.getDescription()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        n3  = new MBeanNotificationInfo(new String[] {"a.b", "c.d"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                        "x.y.zz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                        "a notification info"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        n4  = new MBeanNotificationInfo(new String[] {"c.d", "a.b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                        "x.y.z",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                        "a notification info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    static final MBeanAttributeInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        xa1a = {a1a, a2a},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        xa1b = {a1b, a2b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        xa2a = {a2a, a1a};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    static final MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        xc1a = {c1a, c2a},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        xc1b = {c1b, c2b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        xc2a = {c2a, c1a};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    static final MBeanOperationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        xo1a = {o1a, o2a},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        xo1b = {o1b, o2b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        xo2a = {o2a, o1a};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    static final MBeanNotificationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        xn1a = {n1a, n2a},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        xn1b = {n1b, n2b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        xn2a = {n2a, n1a};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    static final MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        i1a = new MBeanInfo("a.b.c", "an MBean info", xa1a, xc1a, xo1a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        i1b = new MBeanInfo("a.b.c", "an MBean info", xa1a, xc1a, xo1a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        i1c = new MBeanInfo("a.b.c", "an MBean info", xa1b, xc1b, xo1b, xn1b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        i1d = new MutableMBeanInfo("a.b.c", "an MBean info", xa1b, xc1b, xo1b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                   xn1b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        i1e = new ImmutableMBeanInfo("a.b.c", "an MBean info", xa1b, xc1b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                     xo1b, xn1b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        i1f = new ImmutableMBeanInfo("a.b.c", "an MBean info", xa1b, xc1b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                     xo1b, xn1b),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        i2a = new MBeanInfo("a.b.cc", "an MBean info", xa1a, xc1a, xo1a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        i2b = new MBeanInfo(i2a.getClassName(), i2a.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                            i2a.getAttributes(), i2a.getConstructors(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                            i2a.getOperations(), i2a.getNotifications()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        i3  = new MBeanInfo("a.b.c", "another MBean info", xa1a, xc1a, xo1a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                            xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        i4  = new MBeanInfo("a.b.c", "an MBean info", xa2a, xc1a, xo1a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        i5  = new MBeanInfo("a.b.c", "an MBean info", xa1a, xc2a, xo1a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        i6  = new MBeanInfo("a.b.c", "an MBean info", xa1a, xc1a, xo2a, xn1a),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        i7  = new MBeanInfo("a.b.c", "an MBean info", xa1a, xc1a, xo1a, xn2a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static final Object[][] equivalenceClasses = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        {a1a, a1b}, {a2a, a2b}, {a3}, {a4}, {a5a, a5b}, {a6a, a6b}, {a7a, a7b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        {a8a, a8b}, {a9a, a9b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        {c1a, c1b, c1c, c1d}, {c2a, c2b}, {c3a, c3b}, {c4}, {c5}, {c6},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        {o1a, o1b, o1c, o1d, o1e}, {o2a, o2b},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        {p1a, p1b}, {p2}, {p3}, {p4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        {n1a, n1b}, {n2a, n2b}, {n3}, {n4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        {i1a, i1b, i1c, i1d, i1e, i1f}, {i2a, i2b}, {i3}, {i4}, {i5}, {i6},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        {i7},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private static class ImmutableMBeanInfo extends MBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        ImmutableMBeanInfo(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                           String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                           MBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                           MBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                           MBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                           MBeanNotificationInfo[] notifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            super(className, description, attributes, constructors, operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                  notifications);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /* This class checks that the MBeanInfo.equals() method really
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
       does call getClassName() etc rather than referring to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
       private fields.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private static class MutableMBeanInfo extends MBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        private final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        private final String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        private final MBeanAttributeInfo[] attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        private final MBeanOperationInfo[] operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        private final MBeanConstructorInfo[] constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        private final MBeanNotificationInfo[] notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        MutableMBeanInfo(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                         String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                         MBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                         MBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                         MBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                         MBeanNotificationInfo[] notifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            super("bogus", null, null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            this.attributes = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            this.constructors = constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            this.operations = operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            this.notifications = notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        public MBeanAttributeInfo[] getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        public MBeanOperationInfo[] getOperations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        public MBeanConstructorInfo[] getConstructors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        public MBeanNotificationInfo[] getNotifications() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private static boolean checkEquals(String what, Object[][] equivs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        /* The equivs array is an array of equivalence classes.  The members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
           of each equivalence class must be equal among themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
           Each member of each equivalence class must be different from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
           each member of each other equivalence class.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        for (int ei = 0; ei < equivs.length; ei++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            Object[] ec1 = equivs[ei];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            ok &= checkSame(what + " equivalence class " + ei, ec1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            for (int ej = 0; ej < equivs.length; ej++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                if (ei == ej)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                Object[] ec2 = equivs[ej];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                ok &= checkDifferent(what + " equivalence classes " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                     ei + " and " + ej, ec1, ec2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            System.out.println("equals test for " + what + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /* We could simplify this test to compare every element with every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
       other and choose whether they are supposed to be the same based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
       on whether they are in the same equivalence class.  A bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
       simpler, but so what.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private static boolean checkSame(String what, Object[] equiv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        for (int i = 0; i < equiv.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            final Object o1 = equiv[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            for (int j = 0; j < equiv.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                final Object o2 = equiv[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (!o1.equals(o2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    System.out.println("equals test: " + what +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                       ": !obj[" + i +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                       "].equals(obj[" + j + "])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    System.out.println("..." + o1 + "  " + o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                if (o1.hashCode() != o2.hashCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    System.out.println("equals test: " + what +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                       ": obj[" + i +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                       "].hashCode() != obj[" + j +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                       "].hashCode()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    System.out.println("..." + o1 + "  " + o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private static boolean checkDifferent(String what, Object[] equiv1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                          Object[] equiv2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        for (int i = 0; i < equiv1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            final Object o1 = equiv1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            for (int j = 0; j < equiv2.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                final Object o2 = equiv2[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if (o1.equals(o2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    System.out.println("equals test " + what + ": obj[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                       i + "].equals(obj[" + j + "])");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    System.out.println("..." + o1 + "  " + o2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        ok &= checkEquals("equivalence", equivalenceClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            System.out.println("all tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            System.out.println("at least one test failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}