jdk/test/javax/management/Introspector/FeatureOrderTest.java
author ohair
Tue, 12 Apr 2011 18:36:42 -0700
changeset 9064 63c8767f5915
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, 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 6486655
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that attributes and operations appear in the same order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * in MBeanInfo as they did in the Standard MBean or MXBean Interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * For more background on this test, see:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * http://weblogs.java.net/blog/emcmanus/archive/2006/11/notes_on_unspec.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.management.ManagementFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.StandardMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class FeatureOrderTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static boolean failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static interface OrderMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        public int getMercury();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        public String getVenus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        public void setVenus(String x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        public BigInteger getEarth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        public void setEarth(BigInteger x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        public boolean isMars();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        public double getJupiter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        public byte getSaturn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        public short getUranus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public void setUranus(short x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        public long getNeptune();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        // No more Pluto!  Yay!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        public void neptune();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public void uranus(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public int saturn(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        public short jupiter(int x, long y, double z);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        public void mars(boolean x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        public BigInteger earth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        public double earth(double x);  // http://www.imdb.com/title/tt0064519/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        public String venus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public int mercury();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static interface OrderMBean extends OrderMXBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static class OrderImpl implements OrderMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public int getMercury() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        public String getVenus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public void setVenus(String x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public BigInteger getEarth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        public void setEarth(BigInteger x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public boolean isMars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        public double getJupiter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        public byte getSaturn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public short getUranus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        public void setUranus(short x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        public long getNeptune() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        public void neptune() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        public void uranus(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        public int saturn(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        public short jupiter(int x, long y, double z) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        public void mars(boolean x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        public BigInteger earth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        public double earth(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        public String venus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public int mercury() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static class Order extends OrderImpl implements OrderMBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static final boolean[] booleans = {false, true};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // Build the lists of attributes and operations that we would expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        // if they are derived by reflection and preserve the reflection order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        List<String> expectedAttributeNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        List<String> expectedOperationNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        for (Method m : OrderMXBean.class.getMethods()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            String name = m.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            String attrName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (name.startsWith("get") && !name.equals("get") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    m.getParameterTypes().length == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    m.getReturnType() != void.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                attrName = name.substring(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            else if (name.startsWith("is") && !name.equals("is") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    m.getParameterTypes().length == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    m.getReturnType() == boolean.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                attrName = name.substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            else if (name.startsWith("set") && !name.equals("set") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    m.getReturnType() == void.class &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    m.getParameterTypes().length == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                attrName = name.substring(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (attrName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if (!expectedAttributeNames.contains(attrName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    expectedAttributeNames.add(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                expectedOperationNames.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        for (boolean mxbean : booleans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            for (boolean withStandardMBean : booleans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                String testName = "MXBean: " + mxbean + "; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        "using javax.management.StandardMBean: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        withStandardMBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                System.out.println("Test case: " + testName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                Object mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if (mxbean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    if (withStandardMBean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        mbean = new StandardMBean(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                new OrderImpl(), OrderMXBean.class, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                        mbean = new OrderImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    if (withStandardMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        mbean = new StandardMBean(new Order(), OrderMBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                        mbean = new Order();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                ObjectName name = new ObjectName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        ":mxbean=" + mxbean + "," + "withStandardMBean=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        withStandardMBean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                mbs.registerMBean(mbean, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                /* Make sure we are testing what we think. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                MBeanInfo mbi = mbs.getMBeanInfo(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                boolean isWithStandardMBean =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        mbs.isInstanceOf(name, StandardMBean.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                System.out.println("classname " +mbi.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                String mxbeanField =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                        (String) mbi.getDescriptor().getFieldValue("mxbean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                boolean isMXBean = "true".equalsIgnoreCase(mxbeanField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (mxbean != isMXBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    throw new Exception("Test error: MXBean mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (withStandardMBean != isWithStandardMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    throw new Exception("Test error: StandardMBean mismatch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                // Check that order of attributes and operations matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                MBeanAttributeInfo[] mbais = mbi.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                checkEqual(expectedAttributeNames.size(), mbais.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        "number of attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                List<String> attributeNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                for (MBeanAttributeInfo mbai : mbais)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    attributeNames.add(mbai.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                checkEqual(expectedAttributeNames, attributeNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        "order of attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                MBeanOperationInfo[] mbois = mbi.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                checkEqual(expectedOperationNames.size(), mbois.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        "number of operations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                List<String> operationNames = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                for (MBeanOperationInfo mboi : mbois)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    operationNames.add(mboi.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                checkEqual(expectedOperationNames, operationNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        "order of operations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (failed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new Exception("TEST FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        System.out.println("TEST PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static void checkEqual(Object expected, Object actual, String what) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (expected.equals(actual))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            System.out.println("OK: " + what + " matches");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            System.out.println("FAILED: " + what + " differs:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            System.out.println("  expected: " + expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            System.out.println("  actual:   " + actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}