J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 6204469 |
| 27 | * @summary Test that MBean*Info can be constructed with default descriptor |
| 28 | * @author Eamonn McManus |
| 29 | * @run clean DefaultDescriptorTest |
| 30 | * @run build DefaultDescriptorTest |
| 31 | * @run main DefaultDescriptorTest |
| 32 | */ |
| 33 | |
| 34 | import java.lang.reflect.*; |
| 35 | import javax.management.*; |
| 36 | import javax.management.modelmbean.*; |
| 37 | import javax.management.openmbean.*; |
| 38 | |
| 39 | public class DefaultDescriptorTest { |
| 40 | public static void main(String[] args) throws Exception { |
| 41 | final Descriptor empty = |
| 42 | ImmutableDescriptor.EMPTY_DESCRIPTOR; |
| 43 | |
| 44 | final Class thisClass = DefaultDescriptorTest.class; |
| 45 | |
| 46 | final Method getWhatever = thisClass.getMethod("getWhatever"); |
| 47 | final Method setWhatever = thisClass.getMethod("setWhatever", |
| 48 | int.class); |
| 49 | final Method doWhatever = thisClass.getMethod("doWhatever", |
| 50 | String.class); |
| 51 | |
| 52 | final Constructor<?> con = thisClass.getConstructor(); |
| 53 | |
| 54 | final OpenMBeanParameterInfoSupport ombpi1 = |
| 55 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING); |
| 56 | final OpenMBeanParameterInfoSupport ombpi2 = |
| 57 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING, |
| 58 | (Descriptor) null); |
| 59 | final OpenMBeanParameterInfoSupport ombpi3 = |
| 60 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING, |
| 61 | empty); |
| 62 | final OpenMBeanParameterInfoSupport ombpi4 = |
| 63 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.STRING, |
| 64 | "defaultString"); |
| 65 | final OpenMBeanParameterInfoSupport ombpi5 = |
| 66 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.INTEGER, |
| 67 | null, 3, 5); |
| 68 | final OpenMBeanParameterInfoSupport ombpi6 = |
| 69 | new OpenMBeanParameterInfoSupport("x", "y", SimpleType.LONG, |
| 70 | 53L, new Long[] {28L, 53L}); |
| 71 | |
| 72 | final ModelMBeanInfoSupport mmbi1 = |
| 73 | new ModelMBeanInfoSupport("yo", "yo", null, null, null, null); |
| 74 | final ModelMBeanInfoSupport mmbi2 = |
| 75 | new ModelMBeanInfoSupport("yo", "yo", null, null, null, null, |
| 76 | (Descriptor) null); |
| 77 | // final ModelMBeanInfoSupport mmbi3 = |
| 78 | // new ModelMBeanInfoSupport("yo", "yo", null, null, null, null, |
| 79 | // empty); |
| 80 | // an empty descriptor is currently illegal for MMBIS |
| 81 | |
| 82 | final ModelMBeanAttributeInfo mmbai1 = |
| 83 | new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever); |
| 84 | final ModelMBeanAttributeInfo mmbai2 = |
| 85 | new ModelMBeanAttributeInfo("yo", "yo", getWhatever, setWhatever, |
| 86 | (Descriptor) null); |
| 87 | final ModelMBeanAttributeInfo mmbai3 = |
| 88 | new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false); |
| 89 | final ModelMBeanAttributeInfo mmbai4 = |
| 90 | new ModelMBeanAttributeInfo("yo", "yo", "yo", true, true, false, |
| 91 | (Descriptor) null); |
| 92 | |
| 93 | final ModelMBeanConstructorInfo mmbci1 = |
| 94 | new ModelMBeanConstructorInfo("yo", con); |
| 95 | final ModelMBeanConstructorInfo mmbci2 = |
| 96 | new ModelMBeanConstructorInfo("yo", con, (Descriptor) null); |
| 97 | final ModelMBeanConstructorInfo mmbci3 = |
| 98 | new ModelMBeanConstructorInfo("yo", "yo", null); |
| 99 | final ModelMBeanConstructorInfo mmbci4 = |
| 100 | new ModelMBeanConstructorInfo("yo", "yo", null, (Descriptor) null); |
| 101 | |
| 102 | final ModelMBeanNotificationInfo mmbni1 = |
| 103 | new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo"); |
| 104 | final ModelMBeanNotificationInfo mmbni2 = |
| 105 | new ModelMBeanNotificationInfo(new String[] {"x.y.z"}, "yo", "yo", |
| 106 | (Descriptor) null); |
| 107 | |
| 108 | final ModelMBeanOperationInfo mmboi1 = |
| 109 | new ModelMBeanOperationInfo("yo", doWhatever); |
| 110 | final ModelMBeanOperationInfo mmboi2 = |
| 111 | new ModelMBeanOperationInfo("yo", doWhatever, (Descriptor) null); |
| 112 | final ModelMBeanOperationInfo mmboi3 = |
| 113 | new ModelMBeanOperationInfo("yo", "yo", null, "typo", |
| 114 | MBeanOperationInfo.ACTION); |
| 115 | final ModelMBeanOperationInfo mmboi4 = |
| 116 | new ModelMBeanOperationInfo("yo", "yo", null, "typo", |
| 117 | MBeanOperationInfo.ACTION, |
| 118 | (Descriptor) null); |
| 119 | |
| 120 | final DescriptorRead[] infos = { |
| 121 | new MBeanInfo("a.b.c", "blah", null, null, null, null), |
| 122 | new MBeanInfo("a.b.c", "blah", null, null, null, null, |
| 123 | (Descriptor) null), |
| 124 | new MBeanInfo("a.b.c", "blah", null, null, null, null, |
| 125 | empty), |
| 126 | |
| 127 | new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever), |
| 128 | // Following constructor deleted because Method has implicit Descriptor |
| 129 | // from annotations |
| 130 | // new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever, |
| 131 | // (Descriptor) null), |
| 132 | // new MBeanAttributeInfo("blah", "blah", getWhatever, setWhatever, |
| 133 | // empty), |
| 134 | |
| 135 | new MBeanAttributeInfo("blah", "a.b.c", "blah", |
| 136 | true, true, false), |
| 137 | new MBeanAttributeInfo("blah", "a.b.c", "blah", |
| 138 | true, true, false, (Descriptor) null), |
| 139 | new MBeanAttributeInfo("blah", "a.b.c", "blah", |
| 140 | true, true, false, empty), |
| 141 | |
| 142 | new MBeanConstructorInfo("blah", con), |
| 143 | // Following constructor deleted because Constructor has implicit Descriptor |
| 144 | // from annotations |
| 145 | // new MBeanConstructorInfo("blah", con, (Descriptor) null), |
| 146 | // new MBeanConstructorInfo("blah", con, empty), |
| 147 | |
| 148 | new MBeanConstructorInfo("blah", "blah", null), |
| 149 | new MBeanConstructorInfo("blah", "blah", null, (Descriptor) null), |
| 150 | new MBeanConstructorInfo("blah", "blah", null, empty), |
| 151 | |
| 152 | // this class should be abstract but isn't |
| 153 | new MBeanFeatureInfo("blah", "blah"), |
| 154 | new MBeanFeatureInfo("blah", "blah", (Descriptor) null), |
| 155 | new MBeanFeatureInfo("blah", "blah", empty), |
| 156 | |
| 157 | new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah"), |
| 158 | new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah", |
| 159 | (Descriptor) null), |
| 160 | new MBeanNotificationInfo(new String[] {"a.b.c"}, "blah", "blah", |
| 161 | empty), |
| 162 | |
| 163 | |
| 164 | new MBeanOperationInfo("blah", doWhatever), |
| 165 | // Following constructor deleted because Method has implicit Descriptor |
| 166 | // from annotations |
| 167 | // new MBeanOperationInfo("blah", doWhatever, (Descriptor) null), |
| 168 | // new MBeanOperationInfo("blah", doWhatever, empty), |
| 169 | |
| 170 | new MBeanOperationInfo("blah", "blah", null, "a.b.c", |
| 171 | MBeanOperationInfo.ACTION_INFO), |
| 172 | new MBeanOperationInfo("blah", "blah", null, "a.b.c", |
| 173 | MBeanOperationInfo.ACTION, |
| 174 | (Descriptor) null), |
| 175 | new MBeanOperationInfo("blah", "blah", null, "a.b.c", |
| 176 | MBeanOperationInfo.INFO, |
| 177 | empty), |
| 178 | |
| 179 | new MBeanParameterInfo("blah", "a.b.c", "blah"), |
| 180 | new MBeanParameterInfo("blah", "a.b.c", "blah", (Descriptor) null), |
| 181 | new MBeanParameterInfo("blah", "a.b.c", "blah", empty), |
| 182 | |
| 183 | new OpenMBeanInfoSupport("x", "y", null, null, null, null), |
| 184 | new OpenMBeanInfoSupport("x", "y", null, null, null, null, |
| 185 | (Descriptor) null), |
| 186 | new OpenMBeanInfoSupport("x", "y", null, null, null, null, |
| 187 | empty), |
| 188 | |
| 189 | ombpi1, |
| 190 | ombpi2, |
| 191 | ombpi3, |
| 192 | ombpi4, |
| 193 | ombpi5, |
| 194 | ombpi6, |
| 195 | |
| 196 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING, |
| 197 | true, true, false), |
| 198 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING, |
| 199 | true, true, false, |
| 200 | (Descriptor) null), |
| 201 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING, |
| 202 | true, true, false, |
| 203 | empty), |
| 204 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.STRING, |
| 205 | true, true, false, |
| 206 | "defaultString"), |
| 207 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.INTEGER, |
| 208 | true, true, false, |
| 209 | null, 3, 5), |
| 210 | new OpenMBeanAttributeInfoSupport("x", "y", SimpleType.LONG, |
| 211 | true, true, false, |
| 212 | 53L, new Long[] {28L, 53L}), |
| 213 | |
| 214 | new OpenMBeanConstructorInfoSupport("x", "y", |
| 215 | new OpenMBeanParameterInfo[] { |
| 216 | ombpi1, ombpi2 |
| 217 | }), |
| 218 | new OpenMBeanConstructorInfoSupport("x", "y", |
| 219 | new OpenMBeanParameterInfo[] { |
| 220 | ombpi1, ombpi2 |
| 221 | }, (Descriptor) null), |
| 222 | new OpenMBeanConstructorInfoSupport("x", "y", |
| 223 | new OpenMBeanParameterInfo[] { |
| 224 | ombpi1, ombpi2 |
| 225 | }, empty), |
| 226 | |
| 227 | new OpenMBeanOperationInfoSupport("x", "y", |
| 228 | new OpenMBeanParameterInfo[] { |
| 229 | ombpi1, ombpi2 |
| 230 | }, SimpleType.DATE, |
| 231 | MBeanOperationInfo.ACTION), |
| 232 | new OpenMBeanOperationInfoSupport("x", "y", |
| 233 | new OpenMBeanParameterInfo[] { |
| 234 | ombpi1, ombpi2 |
| 235 | }, SimpleType.DATE, |
| 236 | MBeanOperationInfo.ACTION, |
| 237 | (Descriptor) null), |
| 238 | new OpenMBeanOperationInfoSupport("x", "y", |
| 239 | new OpenMBeanParameterInfo[] { |
| 240 | ombpi1, ombpi2 |
| 241 | }, SimpleType.DATE, |
| 242 | MBeanOperationInfo.ACTION, |
| 243 | empty), |
| 244 | |
| 245 | mmbi1, |
| 246 | mmbi2, |
| 247 | |
| 248 | new ModelMBeanInfoSupport(mmbi1), |
| 249 | new ModelMBeanInfoSupport(mmbi2), |
| 250 | |
| 251 | (DescriptorRead) mmbi1.clone(), |
| 252 | (DescriptorRead) mmbi2.clone(), |
| 253 | |
| 254 | mmbai1, |
| 255 | mmbai2, |
| 256 | mmbai3, |
| 257 | mmbai4, |
| 258 | |
| 259 | new ModelMBeanAttributeInfo(mmbai1), |
| 260 | new ModelMBeanAttributeInfo(mmbai2), |
| 261 | new ModelMBeanAttributeInfo(mmbai3), |
| 262 | new ModelMBeanAttributeInfo(mmbai4), |
| 263 | |
| 264 | (DescriptorRead) mmbai1.clone(), |
| 265 | (DescriptorRead) mmbai2.clone(), |
| 266 | (DescriptorRead) mmbai3.clone(), |
| 267 | (DescriptorRead) mmbai4.clone(), |
| 268 | |
| 269 | mmbci1, |
| 270 | mmbci2, |
| 271 | mmbci3, |
| 272 | mmbci4, |
| 273 | |
| 274 | // Oddly enough there's no public copy constructor for this class |
| 275 | |
| 276 | (DescriptorRead) mmbci1.clone(), |
| 277 | (DescriptorRead) mmbci2.clone(), |
| 278 | (DescriptorRead) mmbci3.clone(), |
| 279 | (DescriptorRead) mmbci4.clone(), |
| 280 | |
| 281 | mmbni1, |
| 282 | mmbni2, |
| 283 | |
| 284 | new ModelMBeanNotificationInfo(mmbni1), |
| 285 | new ModelMBeanNotificationInfo(mmbni2), |
| 286 | |
| 287 | (DescriptorRead) mmbni1.clone(), |
| 288 | (DescriptorRead) mmbni2.clone(), |
| 289 | |
| 290 | mmboi1, |
| 291 | mmboi2, |
| 292 | mmboi3, |
| 293 | mmboi4, |
| 294 | |
| 295 | new ModelMBeanOperationInfo(mmboi1), |
| 296 | new ModelMBeanOperationInfo(mmboi2), |
| 297 | new ModelMBeanOperationInfo(mmboi3), |
| 298 | new ModelMBeanOperationInfo(mmboi4), |
| 299 | |
| 300 | (DescriptorRead) mmboi1.clone(), |
| 301 | (DescriptorRead) mmboi2.clone(), |
| 302 | (DescriptorRead) mmboi3.clone(), |
| 303 | (DescriptorRead) mmboi4.clone(), |
| 304 | |
| 305 | }; |
| 306 | |
| 307 | System.out.println("Testing that a default descriptor is always " + |
| 308 | "supplied"); |
| 309 | for (DescriptorRead info : infos) { |
| 310 | System.out.println(info); |
| 311 | Descriptor d = info.getDescriptor(); |
| 312 | if (d == null) |
| 313 | throw new Exception("getDescriptor returned null: " + info); |
| 314 | } |
| 315 | System.out.println("Test passed"); |
| 316 | } |
| 317 | |
| 318 | public int getWhatever() { |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | public void setWhatever(int x) { |
| 323 | } |
| 324 | |
| 325 | public void doWhatever(String x) { |
| 326 | } |
| 327 | } |