Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/modelmbean/OnUnregisterTest.java
38840 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 617538726* @summary Check that OnUnregister is an allowed value for persistPolicy27* in ModelMBeanAttributeInfo28* @author Eamonn McManus29* @run clean OnUnregisterTest30* @run build OnUnregisterTest31* @run main OnUnregisterTest32*/3334// Since our RequiredModelMBean implementation doesn't support35// persistence, it doesn't have any behaviour for OnUnregister, so we36// can't test that. We can only test that the value is allowed.3738// In versions of the API prior to the addition of OnUnregister, the39// attempt to construct a DescriptorSupport with persistPolicy=OnUnregister40// will throw an exception.4142// The OnUnregister value is not case-sensitive, and we test that.4344import javax.management.*;45import javax.management.modelmbean.*;4647public class OnUnregisterTest {48public static void main(String[] args) throws Exception {49MBeanServer mbs = MBeanServerFactory.newMBeanServer();50ObjectName on = new ObjectName("a:b=c");5152DescriptorSupport desc;53ModelMBeanAttributeInfo mmbai;54ModelMBeanInfo mmbi;55ModelMBean mmb;5657desc = new DescriptorSupport("name=foo",58"descriptorType=attribute",59"persistPolicy=OnUnregister");60mmbai = new ModelMBeanAttributeInfo("foo", "int", "a foo",61true, true, false, desc);62mmbi = new ModelMBeanInfoSupport("a.b.c", "description",63new ModelMBeanAttributeInfo[] {mmbai},64null, null, null);65mmb = new RequiredModelMBean(mmbi);6667mbs.registerMBean(mmb, on);68mbs.unregisterMBean(on);6970desc = new DescriptorSupport("name=foo", "descriptorType=attribute");71mmbai = new ModelMBeanAttributeInfo("foo", "int", "a foo",72true, true, false, desc);73desc = new DescriptorSupport("name=bar",74"descriptorType=mbean",75"persistPolicy=onUnregister");76mmbi = new ModelMBeanInfoSupport("a.b.c", "description",77new ModelMBeanAttributeInfo[] {mmbai},78null, null, null, desc);79mmb = new RequiredModelMBean(mmbi);80mbs.registerMBean(mmb, on);81mbs.unregisterMBean(on);82}83}848586