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