blob: b99ba96db19922c006731f5fc6816e0e10d2ce3e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. 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 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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 6292705
27 * @summary Test support for arrays in parameterized types.
28 * @author Luis-Miguel Alventosa
29 * @run clean GenericArrayTypeTest
30 * @run build GenericArrayTypeTest
31 * @run main GenericArrayTypeTest
32 */
33
34import java.lang.management.ManagementFactory;
35import java.lang.management.MonitorInfo;
36import java.util.ArrayList;
37import java.util.HashMap;
38import java.util.HashSet;
39import java.util.List;
40import java.util.Map;
41import java.util.Set;
42import javax.management.JMX;
43import javax.management.MBeanServer;
44import javax.management.MBeanServerConnection;
45import javax.management.ObjectName;
46import javax.management.remote.JMXConnector;
47import javax.management.remote.JMXConnectorFactory;
48import javax.management.remote.JMXConnectorServer;
49import javax.management.remote.JMXConnectorServerFactory;
50import javax.management.remote.JMXServiceURL;
51
52public class GenericArrayTypeTest {
53
54 public interface TestMXBean {
55
56 public String[] getT1();
57 public void setT1(String[] v);
58
59 public MonitorInfo[] getT2();
60 public void setT2(MonitorInfo[] v);
61
62 public Map<String,String[]> getT3();
63 public void setT3(Map<String,String[]> v);
64
65 public Map<String,MonitorInfo[]> getT4();
66 public void setT4(Map<String,MonitorInfo[]> v);
67
68 public Set<String[]> getT5();
69 public void setT5(Set<String[]> v);
70
71 public Set<MonitorInfo[]> getT6();
72 public void setT6(Set<MonitorInfo[]> v);
73
74 public List<String[]> getT7();
75 public void setT7(List<String[]> v);
76
77 public List<MonitorInfo[]> getT8();
78 public void setT8(List<MonitorInfo[]> v);
79
80 public Set<List<String[]>> getT9();
81 public void setT9(Set<List<String[]>> v);
82
83 public Set<List<MonitorInfo[]>> getT10();
84 public void setT10(Set<List<MonitorInfo[]>> v);
85
86 public Map<String,Set<List<String[]>>> getT11();
87 public void setT11(Map<String,Set<List<String[]>>> v);
88
89 public Map<String,Set<List<MonitorInfo[]>>> getT12();
90 public void setT12(Map<String,Set<List<MonitorInfo[]>>> v);
91 }
92
93 public static class Test implements TestMXBean {
94
95 public String[] getT1() {
96 return t1;
97 }
98 public void setT1(String[] v) {
99 t1 = v;
100 }
101 private String[] t1;
102
103 public MonitorInfo[] getT2() {
104 return t2;
105 }
106 public void setT2(MonitorInfo[] v) {
107 t2 = v;
108 }
109 private MonitorInfo[] t2;
110
111 public Map<String,String[]> getT3() {
112 return t3;
113 }
114 public void setT3(Map<String,String[]> v) {
115 t3 = v;
116 }
117 private Map<String,String[]> t3;
118
119 public Map<String,MonitorInfo[]> getT4() {
120 return t4;
121 }
122 public void setT4(Map<String,MonitorInfo[]> v) {
123 t4 = v;
124 }
125 private Map<String,MonitorInfo[]> t4;
126
127 public Set<String[]> getT5() {
128 return t5;
129 }
130 public void setT5(Set<String[]> v) {
131 t5 = v;
132 }
133 private Set<String[]> t5;
134
135 public Set<MonitorInfo[]> getT6() {
136 return t6;
137 }
138 public void setT6(Set<MonitorInfo[]> v) {
139 t6 = v;
140 }
141 private Set<MonitorInfo[]> t6;
142
143 public List<String[]> getT7() {
144 return t7;
145 }
146 public void setT7(List<String[]> v) {
147 t7 = v;
148 }
149 private List<String[]> t7;
150
151 public List<MonitorInfo[]> getT8() {
152 return t8;
153 }
154 public void setT8(List<MonitorInfo[]> v) {
155 t8 = v;
156 }
157 private List<MonitorInfo[]> t8;
158
159 public Set<List<String[]>> getT9() {
160 return t9;
161 }
162 public void setT9(Set<List<String[]>> v) {
163 t9 = v;
164 }
165 private Set<List<String[]>> t9;
166
167 public Set<List<MonitorInfo[]>> getT10() {
168 return t10;
169 }
170 public void setT10(Set<List<MonitorInfo[]>> v) {
171 t10 = v;
172 }
173 private Set<List<MonitorInfo[]>> t10;
174
175 public Map<String,Set<List<String[]>>> getT11() {
176 return t11;
177 }
178 public void setT11(Map<String,Set<List<String[]>>> v) {
179 t11 = v;
180 }
181 private Map<String,Set<List<String[]>>> t11;
182
183 public Map<String,Set<List<MonitorInfo[]>>> getT12() {
184 return t12;
185 }
186 public void setT12(Map<String,Set<List<MonitorInfo[]>>> v) {
187 t12 = v;
188 }
189 private Map<String,Set<List<MonitorInfo[]>>> t12;
190 }
191
192 public static void main(String[] args) throws Exception {
193
194 int error = 0;
195 JMXConnector cc = null;
196 JMXConnectorServer cs = null;
197
198 try {
199 // Instantiate the MBean server
200 //
201 echo("\n>>> Create the MBean server");
202 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
203
204 // Get default domain
205 //
206 echo("\n>>> Get the MBean server's default domain");
207 String domain = mbs.getDefaultDomain();
208 echo("\tDefault Domain = " + domain);
209
210 // Register TestMXBean
211 //
212 echo("\n>>> Register TestMXBean");
213 ObjectName name =
214 ObjectName.getInstance(domain + ":type=" + TestMXBean.class);
215 mbs.createMBean(Test.class.getName(), name);
216
217 // Create an RMI connector server
218 //
219 echo("\n>>> Create an RMI connector server");
220 JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
221 cs =
222 JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
223
224 // Start the RMI connector server
225 //
226 echo("\n>>> Start the RMI connector server");
227 cs.start();
228
229 // Create an RMI connector client
230 //
231 echo("\n>>> Create an RMI connector client");
232 cc = JMXConnectorFactory.connect(cs.getAddress(), null);
233 MBeanServerConnection mbsc = cc.getMBeanServerConnection();
234
235 // Create TestMXBean proxy
236 //
237 echo("\n>>> Create the TestMXBean proxy");
238 TestMXBean test = JMX.newMXBeanProxy(mbsc, name, TestMXBean.class);
239
240 // Play with proxy getters and setters
241 //
242 echo("\n>>> Play with proxy getters and setters");
243 String[] t1 = new String[] { "t1" };
244 MonitorInfo[] t2 = new MonitorInfo[] {
245 new MonitorInfo("dummy", 0, 0,
246 new StackTraceElement("dummy", "dummy", "dummy", 0)) };
247 Map<String,String[]> t3 = new HashMap<String,String[]>();
248 t3.put("key", t1);
249 Map<String,MonitorInfo[]> t4 = new HashMap<String,MonitorInfo[]>();
250 t4.put("key", t2);
251 Set<String[]> t5 = new HashSet<String[]>();
252 t5.add(t1);
253 Set<MonitorInfo[]> t6 = new HashSet<MonitorInfo[]>();
254 t6.add(t2);
255 List<String[]> t7 = new ArrayList<String[]>();
256 t7.add(t1);
257 List<MonitorInfo[]> t8 = new ArrayList<MonitorInfo[]>();
258 t8.add(t2);
259 Set<List<String[]>> t9 = new HashSet<List<String[]>>();
260 t9.add(t7);
261 Set<List<MonitorInfo[]>> t10 = new HashSet<List<MonitorInfo[]>>();
262 t10.add(t8);
263 Map<String,Set<List<String[]>>> t11 = new HashMap<String,Set<List<String[]>>>();
264 t11.put("key", t9);
265 Map<String,Set<List<MonitorInfo[]>>> t12 = new HashMap<String,Set<List<MonitorInfo[]>>>();
266 t12.put("key", t10);
267
268 test.setT1(t1);
269 test.setT2(t2);
270 test.setT3(t3);
271 test.setT4(t4);
272 test.setT5(t5);
273 test.setT6(t6);
274 test.setT7(t7);
275 test.setT8(t8);
276 test.setT9(t9);
277 test.setT10(t10);
278 test.setT11(t11);
279 test.setT12(t12);
280
281 String r;
282 String e1 = "t1";
283 String e2 = "dummy";
284 echo("\tT1 = " + test.getT1());
285 r = ((String[])test.getT1())[0];
286 echo("\tR1 = " + r);
287 if (!e1.equals(r)) error++;
288 echo("\tT2 = " + test.getT2());
289 r = ((MonitorInfo[])test.getT2())[0].getClassName();
290 echo("\tR2 = " + r);
291 if (!e2.equals(r)) error++;
292 echo("\tT3 = " + test.getT3());
293 r = ((String[])((Map<String,String[]>)test.getT3()).get("key"))[0];
294 echo("\tR3 = " + r);
295 if (!e1.equals(r)) error++;
296 echo("\tT4 = " + test.getT4());
297 r = ((MonitorInfo[])((Map<String,MonitorInfo[]>)test.getT4()).get("key"))[0].getClassName();
298 echo("\tR4 = " + r);
299 if (!e2.equals(r)) error++;
300 echo("\tT5 = " + test.getT5());
301 r = ((String[])((Set<String[]>)test.getT5()).iterator().next())[0];
302 echo("\tR5 = " + r);
303 if (!e1.equals(r)) error++;
304 echo("\tT6 = " + test.getT6());
305 r = ((MonitorInfo[])((Set<MonitorInfo[]>)test.getT6()).iterator().next())[0].getClassName();
306 echo("\tR6 = " + r);
307 if (!e2.equals(r)) error++;
308 echo("\tT7 = " + test.getT7());
309 r = ((String[])((List<String[]>)test.getT7()).get(0))[0];
310 echo("\tR7 = " + r);
311 if (!e1.equals(r)) error++;
312 echo("\tT8 = " + test.getT8());
313 r = ((MonitorInfo[])((List<MonitorInfo[]>)test.getT8()).get(0))[0].getClassName();
314 echo("\tR8 = " + r);
315 if (!e2.equals(r)) error++;
316 echo("\tT9 = " + test.getT9());
317 r = ((String[])((List<String[]>)((Set<List<String[]>>)test.getT9()).iterator().next()).get(0))[0];
318 echo("\tR9 = " + r);
319 if (!e1.equals(r)) error++;
320 echo("\tT10 = " + test.getT10());
321 r = ((MonitorInfo[])((List<MonitorInfo[]>)((Set<List<MonitorInfo[]>>)test.getT10()).iterator().next()).get(0))[0].getClassName();
322 echo("\tR10 = " + r);
323 if (!e2.equals(r)) error++;
324 echo("\tT11 = " + test.getT11());
325 r = ((String[])((List<String[]>)((Set<List<String[]>>)((Map<String,Set<List<String[]>>>)test.getT11()).get("key")).iterator().next()).get(0))[0];
326 echo("\tR11 = " + r);
327 if (!e1.equals(r)) error++;
328 echo("\tT12 = " + test.getT12());
329 r = ((MonitorInfo[])((List<MonitorInfo[]>)((Set<List<MonitorInfo[]>>)((Map<String,Set<List<MonitorInfo[]>>>)test.getT12()).get("key")).iterator().next()).get(0))[0].getClassName();
330 echo("\tR12 = " + r);
331 if (!e2.equals(r)) error++;
332 } catch (Exception e) {
333 e.printStackTrace(System.out);
334 error++;
335 } finally {
336 // Close client
337 //
338 echo("\n>>> Close the RMI connector client");
339 if (cc != null)
340 cc.close();
341
342 // Stop server
343 //
344 echo("\n>>> Stop the RMI connector server");
345 if (cs != null)
346 cs.stop();
347
348 echo("\n>>> Bye! Bye!");
349 }
350
351 if (error > 0) {
352 echo("\nTest failed! " + error + " errors.\n");
353 throw new IllegalArgumentException("Test failed");
354 } else {
355 echo("\nTest passed!\n");
356 }
357 }
358
359 private static void echo(String msg) {
360 System.out.println(msg);
361 }
362}