author | ykantser |
Thu, 07 May 2015 09:11:49 +0200 | |
changeset 30376 | 2ccf2cf7ea48 |
parent 5506 | 202f599c92aa |
child 33315 | d2a313368ccb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6175517 |
|
27 |
* @summary Test the PropertyNames annotation with MXBeans |
|
28 |
* @author Eamonn McManus |
|
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
29 |
* @modules java.desktop |
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
30 |
* java.management |
2 | 31 |
* @run clean PropertyNamesTest |
32 |
* @run build PropertyNamesTest |
|
33 |
* @run main PropertyNamesTest |
|
34 |
*/ |
|
35 |
||
36 |
import java.beans.ConstructorProperties; |
|
37 |
import java.util.Collections; |
|
38 |
import java.util.List; |
|
39 |
import javax.management.JMX; |
|
40 |
import javax.management.MBeanServer; |
|
41 |
import javax.management.MBeanServerFactory; |
|
42 |
import javax.management.ObjectName; |
|
43 |
import javax.management.openmbean.CompositeData; |
|
44 |
import javax.management.openmbean.CompositeDataSupport; |
|
45 |
import javax.management.openmbean.CompositeType; |
|
46 |
import javax.management.openmbean.OpenType; |
|
47 |
import javax.management.openmbean.SimpleType; |
|
48 |
||
49 |
public class PropertyNamesTest { |
|
50 |
public static void main(String[] args) throws Exception { |
|
51 |
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); |
|
52 |
ObjectName pointName = new ObjectName("a:type=Point"); |
|
53 |
PointMXBean pointmx = new PointImpl(); |
|
54 |
mbs.registerMBean(pointmx, pointName); |
|
55 |
Point point = new Point(1, 2); |
|
56 |
PointMXBean pointproxy = |
|
57 |
JMX.newMXBeanProxy(mbs, pointName, PointMXBean.class); |
|
58 |
Point point1 = pointproxy.identity(point); |
|
59 |
if (point1.getX() != point.getX() || point1.getY() != point.getY()) |
|
60 |
throw new Exception("Point doesn't match"); |
|
61 |
System.out.println("Point test passed"); |
|
62 |
||
63 |
ObjectName evolveName = new ObjectName("a:type=Evolve"); |
|
64 |
EvolveMXBean evolvemx = new EvolveImpl(); |
|
65 |
mbs.registerMBean(evolvemx, evolveName); |
|
66 |
Evolve evolve = |
|
67 |
new Evolve(59, "tralala", Collections.singletonList("tiddly")); |
|
68 |
EvolveMXBean evolveProxy = |
|
69 |
JMX.newMXBeanProxy(mbs, evolveName, EvolveMXBean.class); |
|
70 |
Evolve evolve1 = evolveProxy.identity(evolve); |
|
71 |
if (evolve1.getOldInt() != evolve.getOldInt() |
|
72 |
|| !evolve1.getNewString().equals(evolve.getNewString()) |
|
73 |
|| !evolve1.getNewerList().equals(evolve.getNewerList())) |
|
74 |
throw new Exception("Evolve doesn't match"); |
|
75 |
System.out.println("Evolve test passed"); |
|
76 |
||
77 |
ObjectName evolvedName = new ObjectName("a:type=Evolved"); |
|
78 |
EvolveMXBean evolvedmx = new EvolveImpl(); |
|
79 |
mbs.registerMBean(evolvedmx, evolvedName); |
|
80 |
CompositeType evolvedType = |
|
81 |
new CompositeType("Evolved", "descr", new String[] {"oldInt"}, |
|
82 |
new String[] {"oldInt descr"}, |
|
83 |
new OpenType[] {SimpleType.INTEGER}); |
|
84 |
CompositeData evolvedData = |
|
85 |
new CompositeDataSupport(evolvedType, new String[] {"oldInt"}, |
|
86 |
new Object[] {5}); |
|
87 |
CompositeData evolved1 = (CompositeData) |
|
88 |
mbs.invoke(evolvedName, "identity", new Object[] {evolvedData}, |
|
89 |
new String[] {CompositeData.class.getName()}); |
|
90 |
if ((Integer) evolved1.get("oldInt") != 5 |
|
91 |
|| !evolved1.get("newString").equals("defaultString") |
|
92 |
|| ((String[]) evolved1.get("newerList")).length != 0) |
|
93 |
throw new Exception("Evolved doesn't match: " + evolved1); |
|
94 |
System.out.println("Evolved test passed"); |
|
95 |
} |
|
96 |
||
97 |
public static class Point { |
|
98 |
@ConstructorProperties({"x", "y"}) |
|
99 |
public Point(int x, int y) { |
|
100 |
this.x = x; |
|
101 |
this.y = y; |
|
102 |
} |
|
103 |
||
104 |
public int getY() { |
|
105 |
return y; |
|
106 |
} |
|
107 |
||
108 |
public int getX() { |
|
109 |
return x; |
|
110 |
} |
|
111 |
||
112 |
private final int x, y; |
|
113 |
} |
|
114 |
||
115 |
public static interface PointMXBean { |
|
116 |
Point identity(Point x); |
|
117 |
} |
|
118 |
||
119 |
public static class PointImpl implements PointMXBean { |
|
120 |
public Point identity(Point x) { |
|
121 |
return x; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
public static class Evolve { |
|
126 |
@ConstructorProperties({"oldInt"}) |
|
127 |
public Evolve(int oldInt) { |
|
128 |
this(oldInt, "defaultString"); |
|
129 |
} |
|
130 |
||
131 |
@ConstructorProperties({"oldInt", "newString"}) |
|
132 |
public Evolve(int oldInt, String newString) { |
|
133 |
this(oldInt, newString, Collections.<String>emptyList()); |
|
134 |
} |
|
135 |
||
136 |
@ConstructorProperties({"oldInt", "newString", "newerList"}) |
|
137 |
public Evolve(int oldInt, String newString, List<String> newerList) { |
|
138 |
this.oldInt = oldInt; |
|
139 |
this.newString = newString; |
|
140 |
this.newerList = newerList; |
|
141 |
} |
|
142 |
||
143 |
public int getOldInt() { |
|
144 |
return oldInt; |
|
145 |
} |
|
146 |
||
147 |
public String getNewString() { |
|
148 |
return newString; |
|
149 |
} |
|
150 |
||
151 |
public List<String> getNewerList() { |
|
152 |
return newerList; |
|
153 |
} |
|
154 |
||
155 |
private final int oldInt; |
|
156 |
private final String newString; |
|
157 |
private final List<String> newerList; |
|
158 |
} |
|
159 |
||
160 |
public static interface EvolveMXBean { |
|
161 |
Evolve identity(Evolve x); |
|
162 |
} |
|
163 |
||
164 |
public static class EvolveImpl implements EvolveMXBean { |
|
165 |
public Evolve identity(Evolve x) { |
|
166 |
return x; |
|
167 |
} |
|
168 |
} |
|
169 |
} |