jdk/test/javax/management/Introspector/AnnotationTest.java
author emcmanus
Wed, 21 Oct 2009 17:33:18 +0200
changeset 4156 acaa49a2768a
parent 1639 a97859015238
child 5506 202f599c92aa
permissions -rw-r--r--
6851617: Remove JSR 255 (JMX API 2.0) from JDK 7 Summary: See http://weblogs.java.net/blog/2009/06/16/jsr-255-jmx-api-20-postponed Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1639
a97859015238 6785258: Update copyright year
xdono
parents: 1570
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  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
 *
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 6221321 6295867
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that annotations in Standard MBean interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * correctly produce Descriptor entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main AnnotationTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    35
import java.lang.annotation.Retention;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    36
import java.lang.annotation.RetentionPolicy;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    37
import javax.management.Descriptor;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    38
import javax.management.DescriptorRead;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    39
import javax.management.DescriptorKey;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    40
import javax.management.ImmutableDescriptor;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    41
import javax.management.MBeanAttributeInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    42
import javax.management.MBeanConstructorInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    43
import javax.management.MBeanInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    44
import javax.management.MBeanOperationInfo;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    45
import javax.management.MBeanServer;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    46
import javax.management.ObjectName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  This test checks that annotations produce Descriptor entries as
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
    50
  specified in javax.management.DescriptorKey.  It does two things:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  - An annotation consisting of an int and a String, each with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    appropriate @DescriptorKey annotation, is placed on every program
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    element where it can map to a Descriptor, namely:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    . on an MBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    . on a getter for a read-only attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    . on a setter for a write-only attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    . on the getter but not the setter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    . on the setter but not the getter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    . on both the getter and the setter for a read/write attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    . on an operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    . on each parameter of an operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    . on a public constructor with no parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    . on a public constructor with a parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    . on the parameter of that public constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    . on all of the above for an MXBean instead of an MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    The test checks that in each case the corresponding Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    appears in the appropriate place inside the MBean's MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  - An annotation consisting of enough other types to ensure coverage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    is placed on a getter.  The test checks that the generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    MBeanAttributeInfo contains the corresponding Descriptor.  The tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    types are the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    . Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    . an enumeration type (java.lang.annotation.RetentionPolicy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    . boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    . String[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    . Class[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    . int[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    . an array of enumeration type (RetentionPolicy[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    . boolean[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public class AnnotationTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static String failed = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    @Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static @interface Pair {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        @DescriptorKey("x")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        int x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        @DescriptorKey("y")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        String y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    @Retention(RetentionPolicy.RUNTIME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static @interface Full {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        @DescriptorKey("class")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Class classValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        @DescriptorKey("enum")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        RetentionPolicy enumValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        @DescriptorKey("boolean")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        boolean booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        @DescriptorKey("stringArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        String[] stringArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        @DescriptorKey("classArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Class[] classArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        @DescriptorKey("intArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int[] intArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        @DescriptorKey("enumArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        RetentionPolicy[] enumArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        @DescriptorKey("booleanArray")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        boolean[] booleanArrayValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   117
    /* We use the annotation @Pair(x = 3, y = "foo") everywhere, and this is
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   118
       the Descriptor that it should produce: */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static Descriptor expectedDescriptor =
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   120
        new ImmutableDescriptor(new String[] {"x", "y"},
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   121
                                new Object[] {3, "foo"});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static Descriptor expectedFullDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        new ImmutableDescriptor(new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                    "class", "enum", "boolean", "stringArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                    "classArray", "intArray", "enumArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                    "booleanArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                    Full.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                    RetentionPolicy.RUNTIME.name(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                    false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                    new String[] {"foo", "bar"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                    new String[] {Full.class.getName()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                    new int[] {1, 2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                    new String[] {RetentionPolicy.RUNTIME.name()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                    new boolean[] {false, true},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static interface ThingMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        @Full(classValue=Full.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              enumValue=RetentionPolicy.RUNTIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              booleanValue=false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
              stringArrayValue={"foo", "bar"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
              classArrayValue={Full.class},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
              intArrayValue={1, 2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
              enumArrayValue={RetentionPolicy.RUNTIME},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              booleanArrayValue={false, true})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int getReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        void setWriteOnly(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        int getReadWrite1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        void setReadWrite1(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int getReadWrite2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        void setReadWrite2(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        int getReadWrite3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        void setReadWrite3(int x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   170
        int operation(@Pair(x = 3, y = "foo") int p1,
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   171
                      @Pair(x = 3, y = "foo") int p2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public static class Thing implements ThingMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public Thing() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   179
        public Thing(@Pair(x = 3, y = "foo") int p1) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        public int getReadOnly() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public void setWriteOnly(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public int getReadWrite1() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        public void setReadWrite1(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public int getReadWrite2() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public void setReadWrite2(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        public int getReadWrite3() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public void setReadWrite3(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        public int operation(int p1, int p2) {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static interface ThingMXBean extends ThingMBean {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public static class ThingImpl implements ThingMXBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        @Pair(x = 3, y = "foo")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        public ThingImpl() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        @Pair(x = 3, y = "foo")
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1639
diff changeset
   205
        public ThingImpl(@Pair(x = 3, y = "foo") int p1) {}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public int getReadOnly() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        public void setWriteOnly(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        public int getReadWrite1() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public void setReadWrite1(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        public int getReadWrite2() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public void setReadWrite2(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        public int getReadWrite3() {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public void setReadWrite3(int x) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public int operation(int p1, int p2) {return 0;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.out.println("Testing that annotations are correctly " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                           "reflected in Descriptor entries");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        MBeanServer mbs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            java.lang.management.ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        ObjectName on = new ObjectName("a:b=c");
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   230
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Thing thing = new Thing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        mbs.registerMBean(thing, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        check(mbs, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        mbs.unregisterMBean(on);
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   235
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        ThingImpl thingImpl = new ThingImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        mbs.registerMBean(thingImpl, on);
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   238
        Descriptor d = mbs.getMBeanInfo(on).getDescriptor();
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   239
        if (!d.getFieldValue("mxbean").equals("true")) {
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   240
            System.out.println("NOT OK: expected MXBean");
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   241
            failed = "Expected MXBean";
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   242
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        check(mbs, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (failed == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            System.out.println("Test passed");
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 2
diff changeset
   247
        else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throw new Exception("TEST FAILED: " + failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private static void check(MBeanServer mbs, ObjectName on) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        MBeanInfo mbi = mbs.getMBeanInfo(on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // check the MBean itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        check(mbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // check attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        MBeanAttributeInfo[] attrs = mbi.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        for (MBeanAttributeInfo attr : attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            check(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (attr.getName().equals("ReadOnly"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                check("@Full", attr.getDescriptor(), expectedFullDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // check operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        MBeanOperationInfo[] ops = mbi.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        for (MBeanOperationInfo op : ops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            check(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            check(op.getSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        MBeanConstructorInfo[] constrs = mbi.getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        for (MBeanConstructorInfo constr : constrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            check(constr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            check(constr.getSignature());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private static void check(DescriptorRead x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        check(x, x.getDescriptor(), expectedDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static void check(Object x, Descriptor d, Descriptor expect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        String fail = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Descriptor u = ImmutableDescriptor.union(d, expect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if (!u.equals(d))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                fail = "should contain " + expect + "; is " + d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            fail = e.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (fail == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            System.out.println("OK: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            failed = "NOT OK: Incorrect descriptor for: " + x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            System.out.println(failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            System.out.println("..." + fail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    private static void check(DescriptorRead[] xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        for (DescriptorRead x : xx)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            check(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}