Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/PropertyNamesTest.java
38841 views
/*1* Copyright (c) 2005, 2006, 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 617551726* @summary Test the PropertyNames annotation with MXBeans27* @author Eamonn McManus28* @run clean PropertyNamesTest29* @run build PropertyNamesTest30* @run main PropertyNamesTest31*/3233import java.beans.ConstructorProperties;34import java.util.Collections;35import java.util.List;36import javax.management.JMX;37import javax.management.MBeanServer;38import javax.management.MBeanServerFactory;39import javax.management.ObjectName;40import javax.management.openmbean.CompositeData;41import javax.management.openmbean.CompositeDataSupport;42import javax.management.openmbean.CompositeType;43import javax.management.openmbean.OpenType;44import javax.management.openmbean.SimpleType;4546public class PropertyNamesTest {47public static void main(String[] args) throws Exception {48MBeanServer mbs = MBeanServerFactory.newMBeanServer();49ObjectName pointName = new ObjectName("a:type=Point");50PointMXBean pointmx = new PointImpl();51mbs.registerMBean(pointmx, pointName);52Point point = new Point(1, 2);53PointMXBean pointproxy =54JMX.newMXBeanProxy(mbs, pointName, PointMXBean.class);55Point point1 = pointproxy.identity(point);56if (point1.getX() != point.getX() || point1.getY() != point.getY())57throw new Exception("Point doesn't match");58System.out.println("Point test passed");5960ObjectName evolveName = new ObjectName("a:type=Evolve");61EvolveMXBean evolvemx = new EvolveImpl();62mbs.registerMBean(evolvemx, evolveName);63Evolve evolve =64new Evolve(59, "tralala", Collections.singletonList("tiddly"));65EvolveMXBean evolveProxy =66JMX.newMXBeanProxy(mbs, evolveName, EvolveMXBean.class);67Evolve evolve1 = evolveProxy.identity(evolve);68if (evolve1.getOldInt() != evolve.getOldInt()69|| !evolve1.getNewString().equals(evolve.getNewString())70|| !evolve1.getNewerList().equals(evolve.getNewerList()))71throw new Exception("Evolve doesn't match");72System.out.println("Evolve test passed");7374ObjectName evolvedName = new ObjectName("a:type=Evolved");75EvolveMXBean evolvedmx = new EvolveImpl();76mbs.registerMBean(evolvedmx, evolvedName);77CompositeType evolvedType =78new CompositeType("Evolved", "descr", new String[] {"oldInt"},79new String[] {"oldInt descr"},80new OpenType[] {SimpleType.INTEGER});81CompositeData evolvedData =82new CompositeDataSupport(evolvedType, new String[] {"oldInt"},83new Object[] {5});84CompositeData evolved1 = (CompositeData)85mbs.invoke(evolvedName, "identity", new Object[] {evolvedData},86new String[] {CompositeData.class.getName()});87if ((Integer) evolved1.get("oldInt") != 588|| !evolved1.get("newString").equals("defaultString")89|| ((String[]) evolved1.get("newerList")).length != 0)90throw new Exception("Evolved doesn't match: " + evolved1);91System.out.println("Evolved test passed");92}9394public static class Point {95@ConstructorProperties({"x", "y"})96public Point(int x, int y) {97this.x = x;98this.y = y;99}100101public int getY() {102return y;103}104105public int getX() {106return x;107}108109private final int x, y;110}111112public static interface PointMXBean {113Point identity(Point x);114}115116public static class PointImpl implements PointMXBean {117public Point identity(Point x) {118return x;119}120}121122public static class Evolve {123@ConstructorProperties({"oldInt"})124public Evolve(int oldInt) {125this(oldInt, "defaultString");126}127128@ConstructorProperties({"oldInt", "newString"})129public Evolve(int oldInt, String newString) {130this(oldInt, newString, Collections.<String>emptyList());131}132133@ConstructorProperties({"oldInt", "newString", "newerList"})134public Evolve(int oldInt, String newString, List<String> newerList) {135this.oldInt = oldInt;136this.newString = newString;137this.newerList = newerList;138}139140public int getOldInt() {141return oldInt;142}143144public String getNewString() {145return newString;146}147148public List<String> getNewerList() {149return newerList;150}151152private final int oldInt;153private final String newString;154private final List<String> newerList;155}156157public static interface EvolveMXBean {158Evolve identity(Evolve x);159}160161public static class EvolveImpl implements EvolveMXBean {162public Evolve identity(Evolve x) {163return x;164}165}166}167168169