Path: blob/master/test/jdk/javax/management/modelmbean/OnUnregisterTest.java
51441 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 617538726* @summary Check that OnUnregister is an allowed value for persistPolicy27* in ModelMBeanAttributeInfo28* @author Eamonn McManus29*30* @run clean OnUnregisterTest31* @run build OnUnregisterTest32* @run main OnUnregisterTest33*/3435// Since our RequiredModelMBean implementation doesn't support36// persistence, it doesn't have any behaviour for OnUnregister, so we37// can't test that. We can only test that the value is allowed.3839// In versions of the API prior to the addition of OnUnregister, the40// attempt to construct a DescriptorSupport with persistPolicy=OnUnregister41// will throw an exception.4243// The OnUnregister value is not case-sensitive, and we test that.4445import javax.management.*;46import javax.management.modelmbean.*;4748public class OnUnregisterTest {49public static void main(String[] args) throws Exception {50MBeanServer mbs = MBeanServerFactory.newMBeanServer();51ObjectName on = new ObjectName("a:b=c");5253DescriptorSupport desc;54ModelMBeanAttributeInfo mmbai;55ModelMBeanInfo mmbi;56ModelMBean mmb;5758desc = new DescriptorSupport("name=foo",59"descriptorType=attribute",60"persistPolicy=OnUnregister");61mmbai = new ModelMBeanAttributeInfo("foo", "int", "a foo",62true, true, false, desc);63mmbi = new ModelMBeanInfoSupport("a.b.c", "description",64new ModelMBeanAttributeInfo[] {mmbai},65null, null, null);66mmb = new RequiredModelMBean(mmbi);6768mbs.registerMBean(mmb, on);69mbs.unregisterMBean(on);7071desc = new DescriptorSupport("name=foo", "descriptorType=attribute");72mmbai = new ModelMBeanAttributeInfo("foo", "int", "a foo",73true, true, false, desc);74desc = new DescriptorSupport("name=bar",75"descriptorType=mbean",76"persistPolicy=onUnregister");77mmbi = new ModelMBeanInfoSupport("a.b.c", "description",78new ModelMBeanAttributeInfo[] {mmbai},79null, null, null, desc);80mmb = new RequiredModelMBean(mmbi);81mbs.registerMBean(mmb, on);82mbs.unregisterMBean(on);83}84}858687