Path: blob/master/test/jdk/javax/management/descriptor/DefaultDescriptorTest.java
41149 views
/*1* Copyright (c) 2005, 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 620446926* @summary Test that MBean*Info can be constructed with default descriptor27* @author Eamonn McManus28*29* @run clean DefaultDescriptorTest30* @run build DefaultDescriptorTest31* @run main DefaultDescriptorTest32*/3334import java.lang.reflect.*;35import javax.management.*;36import javax.management.modelmbean.*;37import javax.management.openmbean.*;3839public class DefaultDescriptorTest {40public static void main(String[] args) throws Exception {41final Descriptor empty =42ImmutableDescriptor.EMPTY_DESCRIPTOR;4344final Class thisClass = DefaultDescriptorTest.class;4546final Method getWhatever = thisClass.getMethod("getWhatever");47final Method setWhatever = thisClass.getMethod("setWhatever",48int.class);49final Method doWhatever = thisClass.getMethod("doWhatever",50String.class);5152final Constructor<?> con = thisClass.getConstructor();5354final OpenMBeanParameterInfoSupport ombpi1 =55new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING);56final OpenMBeanParameterInfoSupport ombpi2 =57new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,58(Descriptor) null);59final OpenMBeanParameterInfoSupport ombpi3 =60new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,61empty);62final OpenMBeanParameterInfoSupport ombpi4 =63new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING,64"defaultString");65final OpenMBeanParameterInfoSupport ombpi5 =66new OpenMBeanParameterInfoSupport("x", "y", SimpleType.INTEGER,67null, 3, 5);68final OpenMBeanParameterInfoSupport ombpi6 =69new OpenMBeanParameterInfoSupport("x", "y", SimpleType.LONG,7053L, new Long[] {28L, 53L});7172final ModelMBeanInfoSupport mmbi1 =73new ModelMBeanInfoSupport("yo", "yo", null, null, null, null);74final ModelMBeanInfoSupport mmbi2 =75new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,76(Descriptor) null);77// final ModelMBeanInfoSupport mmbi3 =78// new ModelMBeanInfoSupport("yo", "yo", null, null, null, null,79// empty);80// an empty descriptor is currently illegal for MMBIS8182final ModelMBeanAttributeInfo mmbai1 =83new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever);84final ModelMBeanAttributeInfo mmbai2 =85new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever,86(Descriptor) null);87final ModelMBeanAttributeInfo mmbai3 =88new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false);89final ModelMBeanAttributeInfo mmbai4 =90new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false,91(Descriptor) null);9293final ModelMBeanConstructorInfo mmbci1 =94new ModelMBeanConstructorInfo("yo", con);95final ModelMBeanConstructorInfo mmbci2 =96new ModelMBeanConstructorInfo("yo", con, (Descriptor) null);97final ModelMBeanConstructorInfo mmbci3 =98new ModelMBeanConstructorInfo("yo", "yo", null);99final ModelMBeanConstructorInfo mmbci4 =100new ModelMBeanConstructorInfo("yo", "yo", null, (Descriptor) null);101102final ModelMBeanNotificationInfo mmbni1 =103new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo");104final ModelMBeanNotificationInfo mmbni2 =105new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo",106(Descriptor) null);107108final ModelMBeanOperationInfo mmboi1 =109new ModelMBeanOperationInfo("yo", doWhatever);110final ModelMBeanOperationInfo mmboi2 =111new ModelMBeanOperationInfo("yo", doWhatever, (Descriptor) null);112final ModelMBeanOperationInfo mmboi3 =113new ModelMBeanOperationInfo("yo", "yo", null, "typo",114MBeanOperationInfo.ACTION);115final ModelMBeanOperationInfo mmboi4 =116new ModelMBeanOperationInfo("yo", "yo", null, "typo",117MBeanOperationInfo.ACTION,118(Descriptor) null);119120final DescriptorRead[] infos = {121new MBeanInfo("a.b.c", "blah", null, null, null, null),122new MBeanInfo("a.b.c", "blah", null, null, null, null,123(Descriptor) null),124new MBeanInfo("a.b.c", "blah", null, null, null, null,125empty),126127new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever),128// Following constructor deleted because Method has implicit Descriptor129// from annotations130// new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,131// (Descriptor) null),132// new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever,133// empty),134135new MBeanAttributeInfo("blah", "a.b.c", "blah",136true, true, false),137new MBeanAttributeInfo("blah", "a.b.c", "blah",138true, true, false, (Descriptor) null),139new MBeanAttributeInfo("blah", "a.b.c", "blah",140true, true, false, empty),141142new MBeanConstructorInfo("blah", con),143// Following constructor deleted because Constructor has implicit Descriptor144// from annotations145// new MBeanConstructorInfo("blah", con, (Descriptor) null),146// new MBeanConstructorInfo("blah", con, empty),147148new MBeanConstructorInfo("blah", "blah", null),149new MBeanConstructorInfo("blah", "blah", null, (Descriptor) null),150new MBeanConstructorInfo("blah", "blah", null, empty),151152// this class should be abstract but isn't153new MBeanFeatureInfo("blah", "blah"),154new MBeanFeatureInfo("blah", "blah", (Descriptor) null),155new MBeanFeatureInfo("blah", "blah", empty),156157new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah"),158new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",159(Descriptor) null),160new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah",161empty),162163164new MBeanOperationInfo("blah", doWhatever),165// Following constructor deleted because Method has implicit Descriptor166// from annotations167// new MBeanOperationInfo("blah", doWhatever, (Descriptor) null),168// new MBeanOperationInfo("blah", doWhatever, empty),169170new MBeanOperationInfo("blah", "blah", null, "a.b.c",171MBeanOperationInfo.ACTION_INFO),172new MBeanOperationInfo("blah", "blah", null, "a.b.c",173MBeanOperationInfo.ACTION,174(Descriptor) null),175new MBeanOperationInfo("blah", "blah", null, "a.b.c",176MBeanOperationInfo.INFO,177empty),178179new MBeanParameterInfo("blah", "a.b.c", "blah"),180new MBeanParameterInfo("blah", "a.b.c", "blah", (Descriptor) null),181new MBeanParameterInfo("blah", "a.b.c", "blah", empty),182183new OpenMBeanInfoSupport("x", "y", null, null, null, null),184new OpenMBeanInfoSupport("x", "y", null, null, null, null,185(Descriptor) null),186new OpenMBeanInfoSupport("x", "y", null, null, null, null,187empty),188189ombpi1,190ombpi2,191ombpi3,192ombpi4,193ombpi5,194ombpi6,195196new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,197true, true, false),198new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,199true, true, false,200(Descriptor) null),201new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,202true, true, false,203empty),204new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING,205true, true, false,206"defaultString"),207new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.INTEGER,208true, true, false,209null, 3, 5),210new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.LONG,211true, true, false,21253L, new Long[] {28L, 53L}),213214new OpenMBeanConstructorInfoSupport("x", "y",215new OpenMBeanParameterInfo[] {216ombpi1, ombpi2217}),218new OpenMBeanConstructorInfoSupport("x", "y",219new OpenMBeanParameterInfo[] {220ombpi1, ombpi2221}, (Descriptor) null),222new OpenMBeanConstructorInfoSupport("x", "y",223new OpenMBeanParameterInfo[] {224ombpi1, ombpi2225}, empty),226227new OpenMBeanOperationInfoSupport("x", "y",228new OpenMBeanParameterInfo[] {229ombpi1, ombpi2230}, SimpleType.DATE,231MBeanOperationInfo.ACTION),232new OpenMBeanOperationInfoSupport("x", "y",233new OpenMBeanParameterInfo[] {234ombpi1, ombpi2235}, SimpleType.DATE,236MBeanOperationInfo.ACTION,237(Descriptor) null),238new OpenMBeanOperationInfoSupport("x", "y",239new OpenMBeanParameterInfo[] {240ombpi1, ombpi2241}, SimpleType.DATE,242MBeanOperationInfo.ACTION,243empty),244245mmbi1,246mmbi2,247248new ModelMBeanInfoSupport(mmbi1),249new ModelMBeanInfoSupport(mmbi2),250251(DescriptorRead) mmbi1.clone(),252(DescriptorRead) mmbi2.clone(),253254mmbai1,255mmbai2,256mmbai3,257mmbai4,258259new ModelMBeanAttributeInfo(mmbai1),260new ModelMBeanAttributeInfo(mmbai2),261new ModelMBeanAttributeInfo(mmbai3),262new ModelMBeanAttributeInfo(mmbai4),263264(DescriptorRead) mmbai1.clone(),265(DescriptorRead) mmbai2.clone(),266(DescriptorRead) mmbai3.clone(),267(DescriptorRead) mmbai4.clone(),268269mmbci1,270mmbci2,271mmbci3,272mmbci4,273274// Oddly enough there's no public copy constructor for this class275276(DescriptorRead) mmbci1.clone(),277(DescriptorRead) mmbci2.clone(),278(DescriptorRead) mmbci3.clone(),279(DescriptorRead) mmbci4.clone(),280281mmbni1,282mmbni2,283284new ModelMBeanNotificationInfo(mmbni1),285new ModelMBeanNotificationInfo(mmbni2),286287(DescriptorRead) mmbni1.clone(),288(DescriptorRead) mmbni2.clone(),289290mmboi1,291mmboi2,292mmboi3,293mmboi4,294295new ModelMBeanOperationInfo(mmboi1),296new ModelMBeanOperationInfo(mmboi2),297new ModelMBeanOperationInfo(mmboi3),298new ModelMBeanOperationInfo(mmboi4),299300(DescriptorRead) mmboi1.clone(),301(DescriptorRead) mmboi2.clone(),302(DescriptorRead) mmboi3.clone(),303(DescriptorRead) mmboi4.clone(),304305};306307System.out.println("Testing that a default descriptor is always " +308"supplied");309for (DescriptorRead info : infos) {310System.out.println(info);311Descriptor d = info.getDescriptor();312if (d == null)313throw new Exception("getDescriptor returned null: " + info);314}315System.out.println("Test passed");316}317318public int getWhatever() {319return 0;320}321322public void setWhatever(int x) {323}324325public void doWhatever(String x) {326}327}328329330