blob: 19499dde08adebf432a52b93962436523e5acc13 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 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 6316460
27 * @summary Test that the legacy com.sun.management.jmx.Introspector
28 * methods work.
29 * @author Eamonn McManus
30 * @run clean LegacyIntrospectorTest
31 * @run build LegacyIntrospectorTest
32 * @run main LegacyIntrospectorTest
33 */
34
35import javax.management.*;
36import com.sun.management.jmx.*;
37
38public class LegacyIntrospectorTest {
39 public static interface TestMBean {
40 public int getWhatever();
41 }
42 public static class Test implements TestMBean {
43 public int getWhatever() {return 0;}
44 }
45
46 @SuppressWarnings("deprecation")
47 public static void main(String[] args) throws Exception {
48 MBeanInfo mbi = Introspector.testCompliance(Test.class);
49 MBeanAttributeInfo mbai = mbi.getAttributes()[0];
50 if (!mbai.getName().equals("Whatever"))
51 throw new Exception("Wrong attribute name: " + mbai.getName());
52 Class c = Introspector.getMBeanInterface(Test.class);
53 if (c != TestMBean.class)
54 throw new Exception("Wrong interface: " + c);
55
56 MBeanServer mbs1 = new MBeanServerImpl();
57 if (!mbs1.getDefaultDomain().equals("DefaultDomain"))
58 throw new Exception("Wrong default domain: " + mbs1.getDefaultDomain());
59
60 MBeanServer mbs2 = new MBeanServerImpl("Foo");
61 if (!mbs2.getDefaultDomain().equals("Foo"))
62 throw new Exception("Wrong default domain: " + mbs2.getDefaultDomain());
63
64 ObjectName delegateName =
65 new ObjectName("JMImplementation:type=MBeanServerDelegate");
66 MBeanInfo delegateInfo = mbs2.getMBeanInfo(delegateName);
67 MBeanInfo refDelegateInfo =
68 MBeanServerFactory.newMBeanServer().getMBeanInfo(delegateName);
69 if (!delegateInfo.equals(refDelegateInfo))
70 throw new Exception("Wrong delegate info from MBeanServerImpl: " +
71 delegateInfo);
72
73 System.out.println("TEST PASSED");
74 }
75}