Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/modelmbean/LoggingExceptionTest.java
38840 views
/*1* Copyright (c) 2008, 2013, 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*/3233import java.util.logging.ConsoleHandler;34import java.util.logging.Handler;35import java.util.logging.Level;36import java.util.logging.Logger;37import javax.management.Notification;38import javax.management.NotificationListener;39import javax.management.modelmbean.DescriptorSupport;40import javax.management.modelmbean.RequiredModelMBean;4142public class LoggingExceptionTest {43private static final String tests[] = new String[] {44"DescriptorSupport()",45"DescriptorSupport(int)",46"DescriptorSupport(String)",47"DescriptorSupport(String...)",48"DescriptorSupport(String[], Object[])",49"DescriptorSupport(DescriptorSupport)",50"RequiredModelMBean.addAttributeChangeNotificationListener",51};52public static void main(String[] args) {53Handler handler = new ConsoleHandler();54Logger logger = Logger.getLogger("javax.management.modelmbean");55logger.addHandler(handler);56logger.setLevel(Level.FINEST);57try {58for (int i = 0; i < tests.length; i++) {59System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);60DescriptorSupport ds;61String msg = "Instantiate " + tests[i];62System.out.println(msg);63switch (i) {64case 0:65ds = new DescriptorSupport();66break;67case 1:68ds = new DescriptorSupport(10);69break;70case 2:71ds = new DescriptorSupport(new DescriptorSupport().toXMLString());72break;73case 3:74ds = new DescriptorSupport("name1=value1", "name2=value2");75break;76case 4:77ds = new DescriptorSupport(new String[] {"name"}, new Object[] {"value"});78break;79case 5:80ds = new DescriptorSupport(new DescriptorSupport());81break;82case 6:83RequiredModelMBean mbean = new RequiredModelMBean();84NotificationListener nl = new NotificationListener() {85public void handleNotification(Notification notification,86Object handback) {}87};88mbean.addAttributeChangeNotificationListener(nl, null, null);89break;90default:91throw new AssertionError();92}93System.out.println(msg + " OK");94}95} catch (Exception e) {96System.out.println("Got unexpected exception = " + e);97String msg = "Test FAILED!";98System.out.println(msg);99throw new IllegalArgumentException(msg);100}101System.out.println("Test PASSED!");102}103}104105106