1 // Tags: JDK1.5 |
|
2 // Uses: BadGuy |
|
3 |
|
4 // Copyright (C) 2006 Andrew John Hughes <gnu_andrew@member.fsf.org> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 package gnu.testlet.java.lang.management; |
|
24 |
|
25 import gnu.testlet.TestHarness; |
|
26 import gnu.testlet.Testlet; |
|
27 |
|
28 import java.lang.management.ManagementFactory; |
|
29 import java.lang.management.RuntimeMXBean; |
|
30 |
|
31 /** |
|
32 * Gets hold of a runtime management bean from the |
|
33 * @link{java.lang.management.ManagementFactory} and |
|
34 * test its security. |
|
35 * |
|
36 * @author <a href="mailto:gnu_andrew@member.fsf.org">Andrew John Hughes</a> |
|
37 */ |
|
38 public class RuntimeMXBeanTest |
|
39 implements Testlet |
|
40 { |
|
41 |
|
42 private BadGuy bg = new BadGuy(); |
|
43 |
|
44 public void test(TestHarness h) |
|
45 { |
|
46 try |
|
47 { |
|
48 Exception caught = null; |
|
49 RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); |
|
50 |
|
51 bg.install(); |
|
52 |
|
53 // Check getVmName |
|
54 caught = null; |
|
55 try |
|
56 { |
|
57 bean.getVmName(); |
|
58 } |
|
59 catch (Exception ex) |
|
60 { |
|
61 caught = ex; |
|
62 } |
|
63 h.check(caught instanceof SecurityException, "vmName"); |
|
64 |
|
65 // Check getVmVendor |
|
66 caught = null; |
|
67 try |
|
68 { |
|
69 bean.getVmVendor(); |
|
70 } |
|
71 catch (Exception ex) |
|
72 { |
|
73 caught = ex; |
|
74 } |
|
75 h.check(caught instanceof SecurityException, "vmVendor"); |
|
76 |
|
77 // Check getVmVersion |
|
78 caught = null; |
|
79 try |
|
80 { |
|
81 bean.getVmVersion(); |
|
82 } |
|
83 catch (Exception ex) |
|
84 { |
|
85 caught = ex; |
|
86 } |
|
87 h.check(caught instanceof SecurityException, "vmVersion"); |
|
88 |
|
89 // Check getSpecName |
|
90 caught = null; |
|
91 try |
|
92 { |
|
93 bean.getSpecName(); |
|
94 } |
|
95 catch (Exception ex) |
|
96 { |
|
97 caught = ex; |
|
98 } |
|
99 h.check(caught instanceof SecurityException, "specName"); |
|
100 |
|
101 // Check getSpecVendor |
|
102 caught = null; |
|
103 try |
|
104 { |
|
105 bean.getSpecVendor(); |
|
106 } |
|
107 catch (Exception ex) |
|
108 { |
|
109 caught = ex; |
|
110 } |
|
111 h.check(caught instanceof SecurityException, "specVendor"); |
|
112 |
|
113 // Check getSpecVersion |
|
114 caught = null; |
|
115 try |
|
116 { |
|
117 bean.getSpecVersion(); |
|
118 } |
|
119 catch (Exception ex) |
|
120 { |
|
121 caught = ex; |
|
122 } |
|
123 h.check(caught instanceof SecurityException, "specVersion"); |
|
124 |
|
125 // Check getClassPath |
|
126 caught = null; |
|
127 try |
|
128 { |
|
129 bean.getClassPath(); |
|
130 } |
|
131 catch (Exception ex) |
|
132 { |
|
133 caught = ex; |
|
134 } |
|
135 h.check(caught instanceof SecurityException, "classPath"); |
|
136 |
|
137 // Check getLibraryPath |
|
138 caught = null; |
|
139 try |
|
140 { |
|
141 bean.getLibraryPath(); |
|
142 } |
|
143 catch (Exception ex) |
|
144 { |
|
145 caught = ex; |
|
146 } |
|
147 h.check(caught instanceof SecurityException, "libraryPath"); |
|
148 |
|
149 // Check getBootClassPath |
|
150 caught = null; |
|
151 try |
|
152 { |
|
153 bean.getBootClassPath(); |
|
154 } |
|
155 catch (Exception ex) |
|
156 { |
|
157 caught = ex; |
|
158 } |
|
159 if (bean.isBootClassPathSupported()) |
|
160 h.check(caught instanceof SecurityException, "bootClassPath"); |
|
161 else |
|
162 h.check(caught instanceof UnsupportedOperationException, "bootClassPath"); |
|
163 |
|
164 // Check getInputArguments |
|
165 caught = null; |
|
166 try |
|
167 { |
|
168 bean.getInputArguments(); |
|
169 } |
|
170 catch (Exception ex) |
|
171 { |
|
172 caught = ex; |
|
173 } |
|
174 h.check(caught instanceof SecurityException, "inputArguments"); |
|
175 |
|
176 // Check getSystemProperties |
|
177 caught = null; |
|
178 try |
|
179 { |
|
180 bean.getSystemProperties(); |
|
181 } |
|
182 catch (Exception ex) |
|
183 { |
|
184 caught = ex; |
|
185 } |
|
186 h.check(caught instanceof SecurityException, "systemProperties"); |
|
187 |
|
188 } |
|
189 finally |
|
190 { |
|
191 bg.uninstall(); |
|
192 } |
|
193 } |
|
194 |
|
195 } |
|
196 |
|