2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 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 6295859
|
|
27 |
* @summary Check that a StandardMBean has immutableInfo=true if it is
|
|
28 |
* a NotificationBroadcasterSupport that doesn't override getNotificationInfo()
|
|
29 |
* @author Eamonn McManus
|
|
30 |
* @run clean ImmutableNotificationInfoTest
|
|
31 |
* @run build ImmutableNotificationInfoTest
|
|
32 |
* @run main ImmutableNotificationInfoTest
|
|
33 |
*/
|
|
34 |
import javax.management.Descriptor;
|
|
35 |
import javax.management.MBeanInfo;
|
|
36 |
import javax.management.MBeanNotificationInfo;
|
|
37 |
import javax.management.MBeanServer;
|
|
38 |
import javax.management.MBeanServerFactory;
|
|
39 |
import javax.management.NotificationBroadcaster;
|
|
40 |
import javax.management.NotificationBroadcasterSupport;
|
|
41 |
import javax.management.NotificationFilter;
|
|
42 |
import javax.management.NotificationListener;
|
|
43 |
import javax.management.ObjectName;
|
|
44 |
|
|
45 |
public class ImmutableNotificationInfoTest {
|
|
46 |
public interface UserBroadcasterMBean {}
|
|
47 |
public interface NoOverrideNBSMBean {}
|
|
48 |
public interface OverrideNBSMBean {}
|
|
49 |
|
|
50 |
public static class UserBroadcaster
|
|
51 |
implements UserBroadcasterMBean, NotificationBroadcaster {
|
|
52 |
public void removeNotificationListener(NotificationListener listener) {
|
|
53 |
}
|
|
54 |
|
|
55 |
public void addNotificationListener(NotificationListener listener,
|
|
56 |
NotificationFilter filter, Object handback) {
|
|
57 |
}
|
|
58 |
|
|
59 |
public MBeanNotificationInfo[] getNotificationInfo() {
|
|
60 |
return new MBeanNotificationInfo[0];
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
public static class NoOverrideNBS extends NotificationBroadcasterSupport
|
|
65 |
implements NoOverrideNBSMBean {
|
|
66 |
}
|
|
67 |
|
|
68 |
public static class OverrideNBS extends NotificationBroadcasterSupport
|
|
69 |
implements OverrideNBSMBean {
|
|
70 |
public MBeanNotificationInfo[] getNotificationInfo() {
|
|
71 |
return new MBeanNotificationInfo[0];
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
public static void main(String[] args) throws Exception {
|
|
76 |
boolean ok;
|
|
77 |
ok = test(new UserBroadcaster(), false);
|
|
78 |
ok &= test(new NoOverrideNBS(), true);
|
|
79 |
ok &= test(new OverrideNBS(), false);
|
|
80 |
if (!ok)
|
|
81 |
throw new Exception("TEST FAILED: immutability incorrect");
|
|
82 |
}
|
|
83 |
|
|
84 |
private static boolean test(Object mbean, boolean expectImmutable)
|
|
85 |
throws Exception {
|
|
86 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
|
|
87 |
ObjectName on = new ObjectName("a:b=c");
|
|
88 |
mbs.registerMBean(mbean, on);
|
|
89 |
MBeanInfo mbi = mbs.getMBeanInfo(on);
|
|
90 |
Descriptor d = mbi.getDescriptor();
|
|
91 |
String immutableValue = (String) d.getFieldValue("immutableInfo");
|
|
92 |
boolean immutable = ("true".equals(immutableValue));
|
|
93 |
if (immutable != expectImmutable) {
|
|
94 |
System.out.println("FAILED: " + mbean.getClass().getName() +
|
|
95 |
" -> " + immutableValue);
|
|
96 |
return false;
|
|
97 |
} else {
|
|
98 |
System.out.println("OK: " + mbean.getClass().getName());
|
|
99 |
return true;
|
|
100 |
}
|
|
101 |
}
|
|
102 |
}
|