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