Path: blob/master/test/jdk/javax/management/modelmbean/LoggingExceptionTest.java
41152 views
/*1* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6471865 667576826* @summary DescriptorSupport constructors throw IAE when traces are enabled;27* RequiredModelMBean.addAttributeChangeNotificationListener throws exception28* when traces enabled and no attributes.29* @author Luis-Miguel Alventosa30* @author Paul Cheeseman31*32* @modules java.logging33* java.management34*/3536import java.util.logging.ConsoleHandler;37import java.util.logging.Handler;38import java.util.logging.Level;39import java.util.logging.Logger;40import javax.management.Notification;41import javax.management.NotificationListener;42import javax.management.modelmbean.DescriptorSupport;43import javax.management.modelmbean.RequiredModelMBean;4445public class LoggingExceptionTest {46private static final String tests[] = new String[] {47"DescriptorSupport()",48"DescriptorSupport(int)",49"DescriptorSupport(String)",50"DescriptorSupport(String...)",51"DescriptorSupport(String[], Object[])",52"DescriptorSupport(DescriptorSupport)",53"RequiredModelMBean.addAttributeChangeNotificationListener",54};55public static void main(String[] args) {56Handler handler = new ConsoleHandler();57Logger logger = Logger.getLogger("javax.management.modelmbean");58logger.addHandler(handler);59logger.setLevel(Level.FINEST);60try {61for (int i = 0; i < tests.length; i++) {62System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);63DescriptorSupport ds;64String msg = "Instantiate " + tests[i];65System.out.println(msg);66switch (i) {67case 0:68ds = new DescriptorSupport();69break;70case 1:71ds = new DescriptorSupport(10);72break;73case 2:74ds = new DescriptorSupport(new DescriptorSupport().toXMLString());75break;76case 3:77ds = new DescriptorSupport("name1=value1", "name2=value2");78break;79case 4:80ds = new DescriptorSupport(new String[] {"name"}, new Object[] {"value"});81break;82case 5:83ds = new DescriptorSupport(new DescriptorSupport());84break;85case 6:86RequiredModelMBean mbean = new RequiredModelMBean();87NotificationListener nl = new NotificationListener() {88public void handleNotification(Notification notification,89Object handback) {}90};91mbean.addAttributeChangeNotificationListener(nl, null, null);92break;93default:94throw new AssertionError();95}96System.out.println(msg + " OK");97}98} catch (Exception e) {99System.out.println("Got unexpected exception = " + e);100String msg = "Test FAILED!";101System.out.println(msg);102throw new IllegalArgumentException(msg);103}104System.out.println("Test PASSED!");105}106}107108109