Path: blob/master/test/jdk/javax/management/Introspector/LegacyConstructorPropertiesTest.java
41149 views
1/*2* Copyright (c) 2015, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324import java.beans.ConstructorProperties;25import javax.management.ConstructorParameters;26import javax.management.MBeanServer;27import javax.management.MBeanServerFactory;28import javax.management.ObjectName;2930/*31* @test32* @bug 719935333* @summary Asserts that 'java.beans.ConstructorProperties' annotation is still34* recognized and properly handled for custom types mapped to open types.35* Also, makes sure that if the same constructor is annotated by both36* j.b.ConstructorProperties and j.m.ConstructorProperties annotations37* only j.m.ConstructorProperties annotation is considered.38* @author Jaroslav Bachorik39*40* @modules java.desktop41* java.management42*43* @run main LegacyConstructorPropertiesTest44*/4546public class LegacyConstructorPropertiesTest {47public static class CustomType {48private String name;49private int value;50@ConstructorProperties({"name", "value"})51public CustomType(String name, int value) {52this.name = name;53this.value = value;54}5556// if @java.beans.ConstructorProperties would be used57// the introspector would choke on this58@ConstructorProperties("noname")59@ConstructorParameters("name")60public CustomType(String name) {61this.name = name;62this.value = -1;63}6465public String getName() {66return name;67}6869public void setName(String name) {70this.name = name;71}7273public int getValue() {74return value;75}7677public void setValue(int value) {78this.value = value;79}80}8182public static interface CustomMXBean {83public CustomType getProp();84public void setProp(CustomType prop);85}8687public static final class Custom implements CustomMXBean {88private CustomType prop;8990@Override91public CustomType getProp() {92return prop;93}9495@Override96public void setProp(CustomType prop) {97this.prop = prop;98}99}100101public static void main(String[] args) throws Exception {102MBeanServer mbs = MBeanServerFactory.createMBeanServer();103CustomMXBean mbean = new Custom();104105mbs.registerMBean(mbean, ObjectName.getInstance("test:type=Custom"));106}107}108109110