File: DefaultDescriptorTest.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (328 lines) | stat: -rw-r--r-- 14,732 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @bug 6204469
 * @summary Test that MBean*Info can be constructed with default descriptor
 * @author Eamonn McManus
 *
 * @run clean DefaultDescriptorTest
 * @run build DefaultDescriptorTest
 * @run main DefaultDescriptorTest
 */

import java.lang.reflect.*;
import javax.management.*;
import javax.management.modelmbean.*;
import javax.management.openmbean.*;

public class DefaultDescriptorTest {
    public static void main(String[] args) throws Exception {
        final Descriptor empty =
            ImmutableDescriptor.EMPTY_DESCRIPTOR;

        final Class thisClass = DefaultDescriptorTest.class;

        final Method getWhatever = thisClass.getMethod("getWhatever");
        final Method setWhatever = thisClass.getMethod("setWhatever",
                                                       int.class);
        final Method doWhatever = thisClass.getMethod("doWhatever",
                                                      String.class);

        final Constructor<?> con = thisClass.getConstructor();

        final OpenMBeanParameterInfoSupport ombpi1 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING);
        final OpenMBeanParameterInfoSupport ombpi2 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
                                              (Descriptor) null);
        final OpenMBeanParameterInfoSupport ombpi3 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
                                              empty);
        final OpenMBeanParameterInfoSupport ombpi4 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
                                              "defaultString");
        final OpenMBeanParameterInfoSupport ombpi5 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.INTEGER,
                                              null, 3, 5);
        final OpenMBeanParameterInfoSupport ombpi6 =
            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.LONG,
                                              53L, new Long[] {28L, 53L});

        final ModelMBeanInfoSupport mmbi1 =
            new ModelMBeanInfoSupport("yo", "yo", null, null, null, null);
        final ModelMBeanInfoSupport mmbi2 =
            new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,
                                      (Descriptor) null);
//      final ModelMBeanInfoSupport mmbi3 =
//          new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,
//                                    empty);
        // an empty descriptor is currently illegal for MMBIS

        final ModelMBeanAttributeInfo mmbai1 =
            new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever);
        final ModelMBeanAttributeInfo mmbai2 =
            new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever,
                                        (Descriptor) null);
        final ModelMBeanAttributeInfo mmbai3 =
            new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false);
        final ModelMBeanAttributeInfo mmbai4 =
            new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false,
                                        (Descriptor) null);

        final ModelMBeanConstructorInfo mmbci1 =
            new ModelMBeanConstructorInfo("yo", con);
        final ModelMBeanConstructorInfo mmbci2 =
            new ModelMBeanConstructorInfo("yo", con, (Descriptor) null);
        final ModelMBeanConstructorInfo mmbci3 =
            new ModelMBeanConstructorInfo("yo", "yo", null);
        final ModelMBeanConstructorInfo mmbci4 =
            new ModelMBeanConstructorInfo("yo", "yo", null, (Descriptor) null);

        final ModelMBeanNotificationInfo mmbni1 =
            new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo");
        final ModelMBeanNotificationInfo mmbni2 =
            new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo",
                                           (Descriptor) null);

        final ModelMBeanOperationInfo mmboi1 =
            new ModelMBeanOperationInfo("yo", doWhatever);
        final ModelMBeanOperationInfo mmboi2 =
            new ModelMBeanOperationInfo("yo", doWhatever, (Descriptor) null);
        final ModelMBeanOperationInfo mmboi3 =
            new ModelMBeanOperationInfo("yo", "yo", null, "typo",
                                        MBeanOperationInfo.ACTION);
        final ModelMBeanOperationInfo mmboi4 =
            new ModelMBeanOperationInfo("yo", "yo", null, "typo",
                                        MBeanOperationInfo.ACTION,
                                        (Descriptor) null);

        final DescriptorRead[] infos = {
            new MBeanInfo("a.b.c", "blah", null, null, null, null),
            new MBeanInfo("a.b.c", "blah", null, null, null, null,
                          (Descriptor) null),
            new MBeanInfo("a.b.c", "blah", null, null, null, null,
                          empty),

            new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever),
// Following constructor deleted because Method has implicit Descriptor
// from annotations
//          new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,
//                                 (Descriptor) null),
//          new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,
//                                 empty),

            new MBeanAttributeInfo("blah", "a.b.c", "blah",
                                   true, true, false),
            new MBeanAttributeInfo("blah", "a.b.c", "blah",
                                   true, true, false, (Descriptor) null),
            new MBeanAttributeInfo("blah", "a.b.c", "blah",
                                   true, true, false, empty),

            new MBeanConstructorInfo("blah", con),
// Following constructor deleted because Constructor has implicit Descriptor
// from annotations
//          new MBeanConstructorInfo("blah", con, (Descriptor) null),
//          new MBeanConstructorInfo("blah", con, empty),

            new MBeanConstructorInfo("blah", "blah", null),
            new MBeanConstructorInfo("blah", "blah", null, (Descriptor) null),
            new MBeanConstructorInfo("blah", "blah", null, empty),

            // this class should be abstract but isn't
            new MBeanFeatureInfo("blah", "blah"),
            new MBeanFeatureInfo("blah", "blah", (Descriptor) null),
            new MBeanFeatureInfo("blah", "blah", empty),

            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah"),
            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",
                                      (Descriptor) null),
            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",
                                      empty),


            new MBeanOperationInfo("blah", doWhatever),
// Following constructor deleted because Method has implicit Descriptor
// from annotations
//          new MBeanOperationInfo("blah", doWhatever, (Descriptor) null),
//          new MBeanOperationInfo("blah", doWhatever, empty),

            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
                                   MBeanOperationInfo.ACTION_INFO),
            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
                                   MBeanOperationInfo.ACTION,
                                   (Descriptor) null),
            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
                                   MBeanOperationInfo.INFO,
                                   empty),

            new MBeanParameterInfo("blah", "a.b.c", "blah"),
            new MBeanParameterInfo("blah", "a.b.c", "blah", (Descriptor) null),
            new MBeanParameterInfo("blah", "a.b.c", "blah", empty),

            new OpenMBeanInfoSupport("x", "y", null, null, null, null),
            new OpenMBeanInfoSupport("x", "y", null, null, null, null,
                                     (Descriptor) null),
            new OpenMBeanInfoSupport("x", "y", null, null, null, null,
                                     empty),

            ombpi1,
            ombpi2,
            ombpi3,
            ombpi4,
            ombpi5,
            ombpi6,

            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
                                              true, true, false),
            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
                                              true, true, false,
                                              (Descriptor) null),
            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
                                              true, true, false,
                                              empty),
            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
                                              true, true, false,
                                              "defaultString"),
            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.INTEGER,
                                              true, true, false,
                                              null, 3, 5),
            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.LONG,
                                              true, true, false,
                                              53L, new Long[] {28L, 53L}),

            new OpenMBeanConstructorInfoSupport("x", "y",
                                                new OpenMBeanParameterInfo[] {
                                                    ombpi1, ombpi2
                                                }),
            new OpenMBeanConstructorInfoSupport("x", "y",
                                                new OpenMBeanParameterInfo[] {
                                                    ombpi1, ombpi2
                                                }, (Descriptor) null),
            new OpenMBeanConstructorInfoSupport("x", "y",
                                                new OpenMBeanParameterInfo[] {
                                                    ombpi1, ombpi2
                                                }, empty),

            new OpenMBeanOperationInfoSupport("x", "y",
                                              new OpenMBeanParameterInfo[] {
                                                  ombpi1, ombpi2
                                              }, SimpleType.DATE,
                                              MBeanOperationInfo.ACTION),
            new OpenMBeanOperationInfoSupport("x", "y",
                                              new OpenMBeanParameterInfo[] {
                                                  ombpi1, ombpi2
                                              }, SimpleType.DATE,
                                              MBeanOperationInfo.ACTION,
                                              (Descriptor) null),
            new OpenMBeanOperationInfoSupport("x", "y",
                                              new OpenMBeanParameterInfo[] {
                                                  ombpi1, ombpi2
                                              }, SimpleType.DATE,
                                              MBeanOperationInfo.ACTION,
                                              empty),

            mmbi1,
            mmbi2,

            new ModelMBeanInfoSupport(mmbi1),
            new ModelMBeanInfoSupport(mmbi2),

            (DescriptorRead) mmbi1.clone(),
            (DescriptorRead) mmbi2.clone(),

            mmbai1,
            mmbai2,
            mmbai3,
            mmbai4,

            new ModelMBeanAttributeInfo(mmbai1),
            new ModelMBeanAttributeInfo(mmbai2),
            new ModelMBeanAttributeInfo(mmbai3),
            new ModelMBeanAttributeInfo(mmbai4),

            (DescriptorRead) mmbai1.clone(),
            (DescriptorRead) mmbai2.clone(),
            (DescriptorRead) mmbai3.clone(),
            (DescriptorRead) mmbai4.clone(),

            mmbci1,
            mmbci2,
            mmbci3,
            mmbci4,

            // Oddly enough there's no public copy constructor for this class

            (DescriptorRead) mmbci1.clone(),
            (DescriptorRead) mmbci2.clone(),
            (DescriptorRead) mmbci3.clone(),
            (DescriptorRead) mmbci4.clone(),

            mmbni1,
            mmbni2,

            new ModelMBeanNotificationInfo(mmbni1),
            new ModelMBeanNotificationInfo(mmbni2),

            (DescriptorRead) mmbni1.clone(),
            (DescriptorRead) mmbni2.clone(),

            mmboi1,
            mmboi2,
            mmboi3,
            mmboi4,

            new ModelMBeanOperationInfo(mmboi1),
            new ModelMBeanOperationInfo(mmboi2),
            new ModelMBeanOperationInfo(mmboi3),
            new ModelMBeanOperationInfo(mmboi4),

            (DescriptorRead) mmboi1.clone(),
            (DescriptorRead) mmboi2.clone(),
            (DescriptorRead) mmboi3.clone(),
            (DescriptorRead) mmboi4.clone(),

        };

        System.out.println("Testing that a default descriptor is always " +
                           "supplied");
        for (DescriptorRead info : infos) {
            System.out.println(info);
            Descriptor d = info.getDescriptor();
            if (d == null)
                throw new Exception("getDescriptor returned null: " + info);
        }
        System.out.println("Test passed");
    }

    public int getWhatever() {
        return 0;
    }

    public void setWhatever(int x) {
    }

    public void doWhatever(String x) {
    }
}