jdk/test/javax/management/Introspector/LegacyIntrospectorTest.java
changeset 746 b63a896706ee
parent 745 47129a5cacd3
parent 665 bfe4572fd301
child 752 94649cecb251
equal deleted inserted replaced
745:47129a5cacd3 746:b63a896706ee
     1 /*
       
     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 
       
    35 import javax.management.*;
       
    36 import com.sun.management.jmx.*;
       
    37 
       
    38 public 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 }