Path: blob/master/test/jdk/javax/management/mxbean/MBeanOperationInfoImpactRangeTest.java
41149 views
/*1* Copyright (c) 2017, 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 802435226* @modules java.management27* @run main MBeanOperationInfoImpactRangeTest28* @summary Check that MBeanOperationInfo throws an IllegalArgumentException when impact29* value is not among INFO,ACTION,ACTION_INFO,UNKNOWN30*/31import javax.management.MBeanOperationInfo;3233public class MBeanOperationInfoImpactRangeTest {3435private void checkInRange(int impact) {36int impactValue;3738System.out.println("checking that no exception is thrown when a "39+ "value in range is passed, impact value is :" + impact );40MBeanOperationInfo mbi = new MBeanOperationInfo("IRC", "impact Range"41+ " check", null, null, impact);42impactValue = mbi.getImpact();43if(impactValue != impact)44throw new RuntimeException("unexpected impact value :" + impactValue);45System.out.println("given value is :" + impactValue);46System.out.println("Success no exception thrown");47System.out.println(mbi.toString());4849}5051private void checkOutOfRange(int impact) {52int impactValue;5354try {55System.out.println("checking that exception is thrown when a value"56+ " out of range is passed, impact value is :" + impact);57MBeanOperationInfo mbi = new MBeanOperationInfo("IRC", "impact Range"58+ " check", null, null, impact);59impactValue = mbi.getImpact();60System.out.println("IllegalArgumentException not thrown"61+ " when a value out of range is passed ,"62+ " given value is :" + impactValue);63throw new RuntimeException("Test failed !!");64// throwing RuntimeException for notifying the unusual behaviour65} catch (IllegalArgumentException e) {66System.out.println("IllegalArgumentException thrown as expected, "67+ "illegal value given as impact :" + impact);68System.out.println("success");69}7071}7273public static void main(String Args[]) {7475// valid range for impact is {INFO=0,ACTION=1,ACTION_INFO=2,UNKNOWN=3}76/* MBeanOperationInfo should throw IllegalArgumentException when impact77value is given out of range*/78MBeanOperationInfoImpactRangeTest impactRangeTest = new MBeanOperationInfoImpactRangeTest();7980impactRangeTest.checkInRange(MBeanOperationInfo.INFO);81impactRangeTest.checkInRange(MBeanOperationInfo.ACTION);82impactRangeTest.checkInRange(MBeanOperationInfo.ACTION_INFO);83impactRangeTest.checkInRange(MBeanOperationInfo.UNKNOWN);84impactRangeTest.checkOutOfRange(-1);85impactRangeTest.checkOutOfRange(4);8687System.out.println("Test Passed");888990}91}9293