author | lfoltan |
Tue, 20 Feb 2018 07:46:40 -0500 | |
changeset 49026 | 844bf1deff1a |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6335337 |
|
27 |
* @summary Test correctness of mxbean flag in descriptor. |
|
28 |
* @author Luis-Miguel Alventosa |
|
44423 | 29 |
* |
2 | 30 |
* @run clean MXBeanFlagTest |
31 |
* @run build MXBeanFlagTest |
|
32 |
* @run main MXBeanFlagTest |
|
33 |
*/ |
|
34 |
||
35 |
import javax.management.*; |
|
36 |
||
37 |
public class MXBeanFlagTest { |
|
38 |
||
39 |
public interface Compliant1MXBean {} |
|
40 |
public static class Compliant1 implements Compliant1MXBean {} |
|
41 |
||
42 |
public interface Compliant2MXBean {} |
|
43 |
public static class Compliant2 implements Compliant2MXBean {} |
|
44 |
||
45 |
public interface Compliant3MBean {} |
|
46 |
public static class Compliant3 implements Compliant3MBean {} |
|
47 |
||
48 |
public interface Compliant4MBean {} |
|
49 |
public static class Compliant4 implements Compliant4MBean {} |
|
50 |
||
51 |
public static void main(String[] args) throws Exception { |
|
52 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); |
|
53 |
ObjectName on1 = new ObjectName(":type=Compliant1"); |
|
54 |
ObjectName on2 = new ObjectName(":type=Compliant2"); |
|
55 |
ObjectName on3 = new ObjectName(":type=Compliant3"); |
|
56 |
ObjectName on4 = new ObjectName(":type=Compliant4"); |
|
57 |
Compliant1 compliant1 = new Compliant1(); |
|
58 |
StandardMBean compliant2 = |
|
59 |
new StandardMBean(new Compliant2(), Compliant2MXBean.class, true); |
|
60 |
Compliant3 compliant3 = new Compliant3(); |
|
61 |
StandardMBean compliant4 = |
|
62 |
new StandardMBean(new Compliant4(), Compliant4MBean.class, false); |
|
63 |
mbs.registerMBean(compliant1, on1); |
|
64 |
mbs.registerMBean(compliant2, on2); |
|
65 |
mbs.registerMBean(compliant3, on3); |
|
66 |
mbs.registerMBean(compliant4, on4); |
|
67 |
String flag1 = (String) |
|
68 |
mbs.getMBeanInfo(on1).getDescriptor().getFieldValue("mxbean"); |
|
69 |
String flag2 = (String) |
|
70 |
mbs.getMBeanInfo(on2).getDescriptor().getFieldValue("mxbean"); |
|
71 |
String flag3 = (String) |
|
72 |
mbs.getMBeanInfo(on3).getDescriptor().getFieldValue("mxbean"); |
|
73 |
String flag4 = (String) |
|
74 |
mbs.getMBeanInfo(on4).getDescriptor().getFieldValue("mxbean"); |
|
75 |
System.out.println("MXBean compliant1:\n" + |
|
76 |
"\t[Expected: mxbean=true] [Got: mxbean=" + flag1 + "]"); |
|
77 |
System.out.println("MXBean compliant2:\n" + |
|
78 |
"\t[Expected: mxbean=true] [Got: mxbean=" + flag2 + "]"); |
|
79 |
System.out.println("Standard MBean compliant3:\n" + |
|
80 |
"\t[Expected: mxbean=false] [Got: mxbean=" + flag3 + "]"); |
|
81 |
System.out.println("Standard MBean compliant4:\n" + |
|
82 |
"\t[Expected: mxbean=false] [Got: mxbean=" + flag4 + "]"); |
|
83 |
if (flag1 != null && flag1.equals("true") && |
|
84 |
flag2 != null && flag2.equals("true") && |
|
85 |
flag3 != null && flag3.equals("false") && |
|
86 |
flag4 != null && flag4.equals("false")) |
|
87 |
System.out.println("Test PASSED"); |
|
88 |
else { |
|
89 |
System.out.println("Test FAILED"); |
|
90 |
throw new Exception("invalid flags"); |
|
91 |
} |
|
92 |
} |
|
93 |
} |