Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/descriptor/DefaultDescriptorTest.java
38838 views
/*1* Copyright (c) 2005, 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 620446926* @summary Test that MBean*Info can be constructed with default descriptor27* @author Eamonn McManus28* @run clean DefaultDescriptorTest29* @run build DefaultDescriptorTest30* @run main DefaultDescriptorTest31*/3233import java.lang.reflect.*;34import javax.management.*;35import javax.management.modelmbean.*;36import javax.management.openmbean.*;3738public class DefaultDescriptorTest {39public static void main(String[] args) throws Exception {40final Descriptor empty =41ImmutableDescriptor.EMPTY_DESCRIPTOR;4243final Class thisClass = DefaultDescriptorTest.class;4445final Method getWhatever = thisClass.getMethod("getWhatever");46final Method setWhatever = thisClass.getMethod("setWhatever",47int.class);48final Method doWhatever = thisClass.getMethod("doWhatever",49String.class);5051final Constructor<?> con = thisClass.getConstructor();5253final OpenMBeanParameterInfoSupport ombpi1 =54new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING);55final OpenMBeanParameterInfoSupport ombpi2 =56new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,57(Descriptor) null);58final OpenMBeanParameterInfoSupport ombpi3 =59new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,60empty);61final OpenMBeanParameterInfoSupport ombpi4 =62new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,63"defaultString");64final OpenMBeanParameterInfoSupport ombpi5 =65new OpenMBeanParameterInfoSupport("x", "y", SimpleType.INTEGER,66null, 3, 5);67final OpenMBeanParameterInfoSupport ombpi6 =68new OpenMBeanParameterInfoSupport("x", "y", SimpleType.LONG,6953L, new Long[] {28L, 53L});7071final ModelMBeanInfoSupport mmbi1 =72new ModelMBeanInfoSupport("yo", "yo", null, null, null, null);73final ModelMBeanInfoSupport mmbi2 =74new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,75(Descriptor) null);76// final ModelMBeanInfoSupport mmbi3 =77// new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,78// empty);79// an empty descriptor is currently illegal for MMBIS8081final ModelMBeanAttributeInfo mmbai1 =82new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever);83final ModelMBeanAttributeInfo mmbai2 =84new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever,85(Descriptor) null);86final ModelMBeanAttributeInfo mmbai3 =87new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false);88final ModelMBeanAttributeInfo mmbai4 =89new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false,90(Descriptor) null);9192final ModelMBeanConstructorInfo mmbci1 =93new ModelMBeanConstructorInfo("yo", con);94final ModelMBeanConstructorInfo mmbci2 =95new ModelMBeanConstructorInfo("yo", con, (Descriptor) null);96final ModelMBeanConstructorInfo mmbci3 =97new ModelMBeanConstructorInfo("yo", "yo", null);98final ModelMBeanConstructorInfo mmbci4 =99new ModelMBeanConstructorInfo("yo", "yo", null, (Descriptor) null);100101final ModelMBeanNotificationInfo mmbni1 =102new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo");103final ModelMBeanNotificationInfo mmbni2 =104new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo",105(Descriptor) null);106107final ModelMBeanOperationInfo mmboi1 =108new ModelMBeanOperationInfo("yo", doWhatever);109final ModelMBeanOperationInfo mmboi2 =110new ModelMBeanOperationInfo("yo", doWhatever, (Descriptor) null);111final ModelMBeanOperationInfo mmboi3 =112new ModelMBeanOperationInfo("yo", "yo", null, "typo",113MBeanOperationInfo.ACTION);114final ModelMBeanOperationInfo mmboi4 =115new ModelMBeanOperationInfo("yo", "yo", null, "typo",116MBeanOperationInfo.ACTION,117(Descriptor) null);118119final DescriptorRead[] infos = {120new MBeanInfo("a.b.c", "blah", null, null, null, null),121new MBeanInfo("a.b.c", "blah", null, null, null, null,122(Descriptor) null),123new MBeanInfo("a.b.c", "blah", null, null, null, null,124empty),125126new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever),127// Following constructor deleted because Method has implicit Descriptor128// from annotations129// new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,130// (Descriptor) null),131// new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,132// empty),133134new MBeanAttributeInfo("blah", "a.b.c", "blah",135true, true, false),136new MBeanAttributeInfo("blah", "a.b.c", "blah",137true, true, false, (Descriptor) null),138new MBeanAttributeInfo("blah", "a.b.c", "blah",139true, true, false, empty),140141new MBeanConstructorInfo("blah", con),142// Following constructor deleted because Constructor has implicit Descriptor143// from annotations144// new MBeanConstructorInfo("blah", con, (Descriptor) null),145// new MBeanConstructorInfo("blah", con, empty),146147new MBeanConstructorInfo("blah", "blah", null),148new MBeanConstructorInfo("blah", "blah", null, (Descriptor) null),149new MBeanConstructorInfo("blah", "blah", null, empty),150151// this class should be abstract but isn't152new MBeanFeatureInfo("blah", "blah"),153new MBeanFeatureInfo("blah", "blah", (Descriptor) null),154new MBeanFeatureInfo("blah", "blah", empty),155156new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah"),157new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",158(Descriptor) null),159new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",160empty),161162163new MBeanOperationInfo("blah", doWhatever),164// Following constructor deleted because Method has implicit Descriptor165// from annotations166// new MBeanOperationInfo("blah", doWhatever, (Descriptor) null),167// new MBeanOperationInfo("blah", doWhatever, empty),168169new MBeanOperationInfo("blah", "blah", null, "a.b.c",170MBeanOperationInfo.ACTION_INFO),171new MBeanOperationInfo("blah", "blah", null, "a.b.c",172MBeanOperationInfo.ACTION,173(Descriptor) null),174new MBeanOperationInfo("blah", "blah", null, "a.b.c",175MBeanOperationInfo.INFO,176empty),177178new MBeanParameterInfo("blah", "a.b.c", "blah"),179new MBeanParameterInfo("blah", "a.b.c", "blah", (Descriptor) null),180new MBeanParameterInfo("blah", "a.b.c", "blah", empty),181182new OpenMBeanInfoSupport("x", "y", null, null, null, null),183new OpenMBeanInfoSupport("x", "y", null, null, null, null,184(Descriptor) null),185new OpenMBeanInfoSupport("x", "y", null, null, null, null,186empty),187188ombpi1,189ombpi2,190ombpi3,191ombpi4,192ombpi5,193ombpi6,194195new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,196true, true, false),197new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,198true, true, false,199(Descriptor) null),200new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,201true, true, false,202empty),203new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,204true, true, false,205"defaultString"),206new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.INTEGER,207true, true, false,208null, 3, 5),209new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.LONG,210true, true, false,21153L, new Long[] {28L, 53L}),212213new OpenMBeanConstructorInfoSupport("x", "y",214new OpenMBeanParameterInfo[] {215ombpi1, ombpi2216}),217new OpenMBeanConstructorInfoSupport("x", "y",218new OpenMBeanParameterInfo[] {219ombpi1, ombpi2220}, (Descriptor) null),221new OpenMBeanConstructorInfoSupport("x", "y",222new OpenMBeanParameterInfo[] {223ombpi1, ombpi2224}, empty),225226new OpenMBeanOperationInfoSupport("x", "y",227new OpenMBeanParameterInfo[] {228ombpi1, ombpi2229}, SimpleType.DATE,230MBeanOperationInfo.ACTION),231new OpenMBeanOperationInfoSupport("x", "y",232new OpenMBeanParameterInfo[] {233ombpi1, ombpi2234}, SimpleType.DATE,235MBeanOperationInfo.ACTION,236(Descriptor) null),237new OpenMBeanOperationInfoSupport("x", "y",238new OpenMBeanParameterInfo[] {239ombpi1, ombpi2240}, SimpleType.DATE,241MBeanOperationInfo.ACTION,242empty),243244mmbi1,245mmbi2,246247new ModelMBeanInfoSupport(mmbi1),248new ModelMBeanInfoSupport(mmbi2),249250(DescriptorRead) mmbi1.clone(),251(DescriptorRead) mmbi2.clone(),252253mmbai1,254mmbai2,255mmbai3,256mmbai4,257258new ModelMBeanAttributeInfo(mmbai1),259new ModelMBeanAttributeInfo(mmbai2),260new ModelMBeanAttributeInfo(mmbai3),261new ModelMBeanAttributeInfo(mmbai4),262263(DescriptorRead) mmbai1.clone(),264(DescriptorRead) mmbai2.clone(),265(DescriptorRead) mmbai3.clone(),266(DescriptorRead) mmbai4.clone(),267268mmbci1,269mmbci2,270mmbci3,271mmbci4,272273// Oddly enough there's no public copy constructor for this class274275(DescriptorRead) mmbci1.clone(),276(DescriptorRead) mmbci2.clone(),277(DescriptorRead) mmbci3.clone(),278(DescriptorRead) mmbci4.clone(),279280mmbni1,281mmbni2,282283new ModelMBeanNotificationInfo(mmbni1),284new ModelMBeanNotificationInfo(mmbni2),285286(DescriptorRead) mmbni1.clone(),287(DescriptorRead) mmbni2.clone(),288289mmboi1,290mmboi2,291mmboi3,292mmboi4,293294new ModelMBeanOperationInfo(mmboi1),295new ModelMBeanOperationInfo(mmboi2),296new ModelMBeanOperationInfo(mmboi3),297new ModelMBeanOperationInfo(mmboi4),298299(DescriptorRead) mmboi1.clone(),300(DescriptorRead) mmboi2.clone(),301(DescriptorRead) mmboi3.clone(),302(DescriptorRead) mmboi4.clone(),303304};305306System.out.println("Testing that a default descriptor is always " +307"supplied");308for (DescriptorRead info : infos) {309System.out.println(info);310Descriptor d = info.getDescriptor();311if (d == null)312throw new Exception("getDescriptor returned null: " + info);313}314System.out.println("Test passed");315}316317public int getWhatever() {318return 0;319}320321public void setWhatever(int x) {322}323324public void doWhatever(String x) {325}326}327328329