blob: bb958eaf3e978e2a8b2f49f16ec95a42e3a1411c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4955222
27 * @summary Test that the releaseMBeanServer(MBeanServer mbeanServer) method
28 * throws IllegalArgumentException as expected
29 * @author Luis-Miguel Alventosa
30 * @run clean ReleaseMBeanServerTest
31 * @run build ReleaseMBeanServerTest
32 * @run main ReleaseMBeanServerTest
33 */
34
35/* Check that the releaseMBeanServer(MBeanServer mbeanServer) method throws
36 IllegalArgumentException if mbeanServer was not generated by one of the
37 createMBeanServer methods, or if releaseMBeanServer was already called
38 on it. */
39
40import javax.management.MBeanServer;
41import javax.management.MBeanServerFactory;
42
43public class ReleaseMBeanServerTest {
44
45 private static final String DOMAIN = "TestDomain";
46
47 public static void main(String[] args) throws Exception {
48
49 System.out.println("--------------------------------------" +
50 "-----------------------------------------");
51 System.out.println("- Testing IllegalArgumentException in " +
52 "MBeanServerFactory.releaseMBeanServer() -");
53 System.out.println("--------------------------------------" +
54 "-----------------------------------------");
55
56 System.out.println("TEST_0: Call releaseMBeanServer() with " +
57 "a null MBeanServer reference.");
58 try {
59 MBeanServerFactory.releaseMBeanServer(null);
60 System.err.println("Didn't get expected IllegalArgumentException!");
61 System.exit(1);
62 } catch (IllegalArgumentException e) {
63 System.out.println("Got expected IllegalArgumentException!");
64 }
65
66 System.out.println("TEST_1: Call releaseMBeanServer() with an " +
67 "MBeanServer reference corresponding to an " +
68 "MBeanServer created using newMBeanServer().");
69 MBeanServer mbs1 = MBeanServerFactory.newMBeanServer();
70 try {
71 MBeanServerFactory.releaseMBeanServer(mbs1);
72 System.err.println("Didn't get expected IllegalArgumentException!");
73 System.exit(1);
74 } catch (IllegalArgumentException e) {
75 System.out.println("Got expected IllegalArgumentException!");
76 }
77
78 System.out.println("TEST_2: Call releaseMBeanServer() with an " +
79 "MBeanServer reference corresponding to an " +
80 "MBeanServer created using newMBeanServer(String).");
81 MBeanServer mbs2 = MBeanServerFactory.newMBeanServer(DOMAIN);
82 try {
83 MBeanServerFactory.releaseMBeanServer(mbs2);
84 System.err.println("Didn't get expected IllegalArgumentException!");
85 System.exit(1);
86 } catch (IllegalArgumentException e) {
87 System.out.println("Got expected IllegalArgumentException!");
88 }
89
90 System.out.println("TEST_3: Call releaseMBeanServer() twice with an " +
91 "MBeanServer reference corresponding to an MBean" +
92 "Server created using createMBeanServer().");
93 MBeanServer mbs3 = MBeanServerFactory.createMBeanServer();
94 MBeanServerFactory.releaseMBeanServer(mbs3);
95 try {
96 MBeanServerFactory.releaseMBeanServer(mbs3);
97 System.err.println("Didn't get expected IllegalArgumentException!");
98 System.exit(1);
99 } catch (IllegalArgumentException e) {
100 System.out.println("Got expected IllegalArgumentException!");
101 }
102
103 System.out.println("TEST_4: Call releaseMBeanServer() twice with an " +
104 "MBeanServer reference corresponding to an MBean" +
105 "Server created using createMBeanServer(String).");
106 MBeanServer mbs4 = MBeanServerFactory.createMBeanServer(DOMAIN);
107 MBeanServerFactory.releaseMBeanServer(mbs4);
108 try {
109 MBeanServerFactory.releaseMBeanServer(mbs4);
110 System.err.println("Didn't get expected IllegalArgumentException!");
111 System.exit(1);
112 } catch (IllegalArgumentException e) {
113 System.out.println("Got expected IllegalArgumentException!");
114 }
115 }
116}