123N/A/*
123N/A * @test
123N/A * @bug 6471865 6675768
123N/A * @summary DescriptorSupport constructors throw IAE when traces are enabled;
123N/A * RequiredModelMBean.addAttributeChangeNotificationListener throws exception
123N/A * when traces enabled and no attributes.
123N/A * @author Luis-Miguel Alventosa
123N/A * @author Paul Cheeseman
123N/A */
123N/A
123N/Aimport java.util.logging.ConsoleHandler;
123N/Aimport java.util.logging.Handler;
123N/Aimport java.util.logging.Level;
123N/Aimport java.util.logging.Logger;
123N/Aimport javax.management.Notification;
123N/Aimport javax.management.NotificationListener;
123N/Aimport javax.management.modelmbean.DescriptorSupport;
123N/Aimport javax.management.modelmbean.RequiredModelMBean;
123N/A
123N/Apublic class LoggingExceptionTest {
123N/A private static final String tests[] = new String[] {
123N/A "DescriptorSupport()",
123N/A "DescriptorSupport(int)",
123N/A "DescriptorSupport(String)",
123N/A "DescriptorSupport(String...)",
123N/A "DescriptorSupport(String[], Object[])",
123N/A "DescriptorSupport(DescriptorSupport)",
123N/A "RequiredModelMBean.addAttributeChangeNotificationListener",
123N/A };
123N/A public static void main(String[] args) {
123N/A Handler handler = new ConsoleHandler();
123N/A Logger logger = Logger.getLogger("javax.management.modelmbean");
123N/A logger.addHandler(handler);
123N/A logger.setLevel(Level.FINEST);
123N/A try {
123N/A for (int i = 0; i < tests.length; i++) {
123N/A System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
123N/A DescriptorSupport ds;
123N/A String msg = "Instantiate " + tests[i];
123N/A System.out.println(msg);
123N/A switch (i) {
123N/A case 0:
123N/A ds = new DescriptorSupport();
123N/A break;
123N/A case 1:
123N/A ds = new DescriptorSupport(10);
123N/A break;
123N/A case 2:
123N/A ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
123N/A break;
123N/A case 3:
123N/A ds = new DescriptorSupport("name1=value1", "name2=value2");
123N/A break;
123N/A case 4:
123N/A ds = new DescriptorSupport(new String[] {"name"}, new Object[] {"value"});
123N/A break;
123N/A case 5:
123N/A ds = new DescriptorSupport(new DescriptorSupport());
123N/A break;
123N/A case 6:
123N/A RequiredModelMBean mbean = new RequiredModelMBean();
123N/A NotificationListener nl = new NotificationListener() {
123N/A public void handleNotification(Notification notification,
123N/A Object handback) {}
123N/A };
123N/A mbean.addAttributeChangeNotificationListener(nl, null, null);
123N/A break;
123N/A default:
123N/A throw new AssertionError();
123N/A }
123N/A System.out.println(msg + " OK");
123N/A }
123N/A } catch (Exception e) {
123N/A System.out.println("Got unexpected exception = " + e);
123N/A String msg = "Test FAILED!";
123N/A System.out.println(msg);
123N/A throw new IllegalArgumentException(msg);
123N/A }
123N/A System.out.println("Test PASSED!");
123N/A }
123N/A}