1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24  /*
  25  * @test
  26  * @bug 8024352
  27  * @modules java.management
  28  * @run main MBeanOperationInfoImpactRangeTest
  29  * @summary Check that MBeanOperationInfo throws an IllegalArgumentException when impact
  30  * value is not among INFO,ACTION,ACTION_INFO,UNKNOWN
  31  */
  32 import javax.management.MBeanOperationInfo;
  33 
  34 public class MBeanOperationInfoImpactRangeTest {
  35 
  36     public static void main(String Args[]) {
  37 
  38         int impactValue;
  39 
  40         // valid range for impact is {INFO=0,ACTION=1,ACTION_INFO=2,UNKNOWN=3}
  41         /* MBeanOperationInfo should throw IllegalArgumentException when impact
  42         value is given out of range*/
  43         System.out.println("checking that no exception is thrown when a "
  44                 + "value in range is passed");
  45         MBeanOperationInfo mbi = new MBeanOperationInfo("IRC", "impact Range"
  46                 + " check", null, null, MBeanOperationInfo.ACTION);
  47         impactValue = mbi.getImpact();
  48         System.out.println("given value is " + impactValue);
  49         System.out.println("Success no exception thrown");
  50 
  51         try {
  52             System.out.println("checking that exception is thrown when a value"
  53                     + " out of range is passed");
  54             mbi = new MBeanOperationInfo("IRC", "impact Range"
  55                     + " check", null, null, 5);
  56             impactValue = mbi.getImpact();
  57             System.out.println("IllegalArgumentException not thrown"
  58                     + " when a value out of range is passed ,"
  59                     + " given value is " + impactValue);
  60             throw new RuntimeException("Test failed !!");
  61             // throwing RuntimeException for notifying the unusual behaviour
  62         } catch (IllegalArgumentException e) {
  63             System.out.println("IllegalArgumentException thrown as expected, "
  64                     + "illegal value given as impact");
  65             System.out.println("success");
  66         }
  67     }
  68 }