1/*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6204469
27 * @summary Test that MBean*Info can be constructed with default descriptor
28 * @author Eamonn McManus
29 *
30 * @run clean DefaultDescriptorTest
31 * @run build DefaultDescriptorTest
32 * @run main DefaultDescriptorTest
33 */
34
35import java.lang.reflect.*;
36import javax.management.*;
37import javax.management.modelmbean.*;
38import javax.management.openmbean.*;
39
40public class DefaultDescriptorTest {
41    public static void main(String[] args) throws Exception {
42        final Descriptor empty =
43            ImmutableDescriptor.EMPTY_DESCRIPTOR;
44
45        final Class thisClass = DefaultDescriptorTest.class;
46
47        final Method getWhatever = thisClass.getMethod("getWhatever");
48        final Method setWhatever = thisClass.getMethod("setWhatever",
49                                                       int.class);
50        final Method doWhatever = thisClass.getMethod("doWhatever",
51                                                      String.class);
52
53        final Constructor<?> con = thisClass.getConstructor();
54
55        final OpenMBeanParameterInfoSupport ombpi1 =
56            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING);
57        final OpenMBeanParameterInfoSupport ombpi2 =
58            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
59                                              (Descriptor) null);
60        final OpenMBeanParameterInfoSupport ombpi3 =
61            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
62                                              empty);
63        final OpenMBeanParameterInfoSupport ombpi4 =
64            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,
65                                              "defaultString");
66        final OpenMBeanParameterInfoSupport ombpi5 =
67            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.INTEGER,
68                                              null, 3, 5);
69        final OpenMBeanParameterInfoSupport ombpi6 =
70            new OpenMBeanParameterInfoSupport("x", "y", SimpleType.LONG,
71                                              53L, new Long[] {28L, 53L});
72
73        final ModelMBeanInfoSupport mmbi1 =
74            new ModelMBeanInfoSupport("yo", "yo", null, null, null, null);
75        final ModelMBeanInfoSupport mmbi2 =
76            new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,
77                                      (Descriptor) null);
78//      final ModelMBeanInfoSupport mmbi3 =
79//          new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,
80//                                    empty);
81        // an empty descriptor is currently illegal for MMBIS
82
83        final ModelMBeanAttributeInfo mmbai1 =
84            new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever);
85        final ModelMBeanAttributeInfo mmbai2 =
86            new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever,
87                                        (Descriptor) null);
88        final ModelMBeanAttributeInfo mmbai3 =
89            new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false);
90        final ModelMBeanAttributeInfo mmbai4 =
91            new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false,
92                                        (Descriptor) null);
93
94        final ModelMBeanConstructorInfo mmbci1 =
95            new ModelMBeanConstructorInfo("yo", con);
96        final ModelMBeanConstructorInfo mmbci2 =
97            new ModelMBeanConstructorInfo("yo", con, (Descriptor) null);
98        final ModelMBeanConstructorInfo mmbci3 =
99            new ModelMBeanConstructorInfo("yo", "yo", null);
100        final ModelMBeanConstructorInfo mmbci4 =
101            new ModelMBeanConstructorInfo("yo", "yo", null, (Descriptor) null);
102
103        final ModelMBeanNotificationInfo mmbni1 =
104            new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo");
105        final ModelMBeanNotificationInfo mmbni2 =
106            new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo",
107                                           (Descriptor) null);
108
109        final ModelMBeanOperationInfo mmboi1 =
110            new ModelMBeanOperationInfo("yo", doWhatever);
111        final ModelMBeanOperationInfo mmboi2 =
112            new ModelMBeanOperationInfo("yo", doWhatever, (Descriptor) null);
113        final ModelMBeanOperationInfo mmboi3 =
114            new ModelMBeanOperationInfo("yo", "yo", null, "typo",
115                                        MBeanOperationInfo.ACTION);
116        final ModelMBeanOperationInfo mmboi4 =
117            new ModelMBeanOperationInfo("yo", "yo", null, "typo",
118                                        MBeanOperationInfo.ACTION,
119                                        (Descriptor) null);
120
121        final DescriptorRead[] infos = {
122            new MBeanInfo("a.b.c", "blah", null, null, null, null),
123            new MBeanInfo("a.b.c", "blah", null, null, null, null,
124                          (Descriptor) null),
125            new MBeanInfo("a.b.c", "blah", null, null, null, null,
126                          empty),
127
128            new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever),
129// Following constructor deleted because Method has implicit Descriptor
130// from annotations
131//          new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,
132//                                 (Descriptor) null),
133//          new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,
134//                                 empty),
135
136            new MBeanAttributeInfo("blah", "a.b.c", "blah",
137                                   true, true, false),
138            new MBeanAttributeInfo("blah", "a.b.c", "blah",
139                                   true, true, false, (Descriptor) null),
140            new MBeanAttributeInfo("blah", "a.b.c", "blah",
141                                   true, true, false, empty),
142
143            new MBeanConstructorInfo("blah", con),
144// Following constructor deleted because Constructor has implicit Descriptor
145// from annotations
146//          new MBeanConstructorInfo("blah", con, (Descriptor) null),
147//          new MBeanConstructorInfo("blah", con, empty),
148
149            new MBeanConstructorInfo("blah", "blah", null),
150            new MBeanConstructorInfo("blah", "blah", null, (Descriptor) null),
151            new MBeanConstructorInfo("blah", "blah", null, empty),
152
153            // this class should be abstract but isn't
154            new MBeanFeatureInfo("blah", "blah"),
155            new MBeanFeatureInfo("blah", "blah", (Descriptor) null),
156            new MBeanFeatureInfo("blah", "blah", empty),
157
158            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah"),
159            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",
160                                      (Descriptor) null),
161            new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",
162                                      empty),
163
164
165            new MBeanOperationInfo("blah", doWhatever),
166// Following constructor deleted because Method has implicit Descriptor
167// from annotations
168//          new MBeanOperationInfo("blah", doWhatever, (Descriptor) null),
169//          new MBeanOperationInfo("blah", doWhatever, empty),
170
171            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
172                                   MBeanOperationInfo.ACTION_INFO),
173            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
174                                   MBeanOperationInfo.ACTION,
175                                   (Descriptor) null),
176            new MBeanOperationInfo("blah", "blah", null, "a.b.c",
177                                   MBeanOperationInfo.INFO,
178                                   empty),
179
180            new MBeanParameterInfo("blah", "a.b.c", "blah"),
181            new MBeanParameterInfo("blah", "a.b.c", "blah", (Descriptor) null),
182            new MBeanParameterInfo("blah", "a.b.c", "blah", empty),
183
184            new OpenMBeanInfoSupport("x", "y", null, null, null, null),
185            new OpenMBeanInfoSupport("x", "y", null, null, null, null,
186                                     (Descriptor) null),
187            new OpenMBeanInfoSupport("x", "y", null, null, null, null,
188                                     empty),
189
190            ombpi1,
191            ombpi2,
192            ombpi3,
193            ombpi4,
194            ombpi5,
195            ombpi6,
196
197            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
198                                              true, true, false),
199            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
200                                              true, true, false,
201                                              (Descriptor) null),
202            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
203                                              true, true, false,
204                                              empty),
205            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,
206                                              true, true, false,
207                                              "defaultString"),
208            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.INTEGER,
209                                              true, true, false,
210                                              null, 3, 5),
211            new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.LONG,
212                                              true, true, false,
213                                              53L, new Long[] {28L, 53L}),
214
215            new OpenMBeanConstructorInfoSupport("x", "y",
216                                                new OpenMBeanParameterInfo[] {
217                                                    ombpi1, ombpi2
218                                                }),
219            new OpenMBeanConstructorInfoSupport("x", "y",
220                                                new OpenMBeanParameterInfo[] {
221                                                    ombpi1, ombpi2
222                                                }, (Descriptor) null),
223            new OpenMBeanConstructorInfoSupport("x", "y",
224                                                new OpenMBeanParameterInfo[] {
225                                                    ombpi1, ombpi2
226                                                }, empty),
227
228            new OpenMBeanOperationInfoSupport("x", "y",
229                                              new OpenMBeanParameterInfo[] {
230                                                  ombpi1, ombpi2
231                                              }, SimpleType.DATE,
232                                              MBeanOperationInfo.ACTION),
233            new OpenMBeanOperationInfoSupport("x", "y",
234                                              new OpenMBeanParameterInfo[] {
235                                                  ombpi1, ombpi2
236                                              }, SimpleType.DATE,
237                                              MBeanOperationInfo.ACTION,
238                                              (Descriptor) null),
239            new OpenMBeanOperationInfoSupport("x", "y",
240                                              new OpenMBeanParameterInfo[] {
241                                                  ombpi1, ombpi2
242                                              }, SimpleType.DATE,
243                                              MBeanOperationInfo.ACTION,
244                                              empty),
245
246            mmbi1,
247            mmbi2,
248
249            new ModelMBeanInfoSupport(mmbi1),
250            new ModelMBeanInfoSupport(mmbi2),
251
252            (DescriptorRead) mmbi1.clone(),
253            (DescriptorRead) mmbi2.clone(),
254
255            mmbai1,
256            mmbai2,
257            mmbai3,
258            mmbai4,
259
260            new ModelMBeanAttributeInfo(mmbai1),
261            new ModelMBeanAttributeInfo(mmbai2),
262            new ModelMBeanAttributeInfo(mmbai3),
263            new ModelMBeanAttributeInfo(mmbai4),
264
265            (DescriptorRead) mmbai1.clone(),
266            (DescriptorRead) mmbai2.clone(),
267            (DescriptorRead) mmbai3.clone(),
268            (DescriptorRead) mmbai4.clone(),
269
270            mmbci1,
271            mmbci2,
272            mmbci3,
273            mmbci4,
274
275            // Oddly enough there's no public copy constructor for this class
276
277            (DescriptorRead) mmbci1.clone(),
278            (DescriptorRead) mmbci2.clone(),
279            (DescriptorRead) mmbci3.clone(),
280            (DescriptorRead) mmbci4.clone(),
281
282            mmbni1,
283            mmbni2,
284
285            new ModelMBeanNotificationInfo(mmbni1),
286            new ModelMBeanNotificationInfo(mmbni2),
287
288            (DescriptorRead) mmbni1.clone(),
289            (DescriptorRead) mmbni2.clone(),
290
291            mmboi1,
292            mmboi2,
293            mmboi3,
294            mmboi4,
295
296            new ModelMBeanOperationInfo(mmboi1),
297            new ModelMBeanOperationInfo(mmboi2),
298            new ModelMBeanOperationInfo(mmboi3),
299            new ModelMBeanOperationInfo(mmboi4),
300
301            (DescriptorRead) mmboi1.clone(),
302            (DescriptorRead) mmboi2.clone(),
303            (DescriptorRead) mmboi3.clone(),
304            (DescriptorRead) mmboi4.clone(),
305
306        };
307
308        System.out.println("Testing that a default descriptor is always " +
309                           "supplied");
310        for (DescriptorRead info : infos) {
311            System.out.println(info);
312            Descriptor d = info.getDescriptor();
313            if (d == null)
314                throw new Exception("getDescriptor returned null: " + info);
315        }
316        System.out.println("Test passed");
317    }
318
319    public int getWhatever() {
320        return 0;
321    }
322
323    public void setWhatever(int x) {
324    }
325
326    public void doWhatever(String x) {
327    }
328}
329