/**
* Verify that invoke method throws exception if target operation method
* throws exception.
* <ul>
* Step by step:
* <li>Create operation method with one string parameter which always
* throws an exception with message=parameter of this method.
* <li>Create ModelMBeanOperationInfo object for operation method.
* <li>Set value currencyTimeLimit = 0 in descriptor for
* ModelMBeanOperationInfo object.
* <li>Create ModelMBeanInfoSupport object with default descriptor. All
* ModelMBeanXXXInfo except ModelMBeanOperationInfo are default.
* <li>Instance of class created in 1st step sets managed resource for
* RequiredModelMBean using setManagedResource method.
* <li>Create ObjectName object.
* <li>Register RequiredModelMBean object in MBeanServer with above
* ObjectName.
* <li>Invoke operation methodThrowException method thru invoke method of
* MBeanServer with specific msg.
* <li>Verify that MBeanException was thrown with nested exception which
* has message which specified in previous step.
* </ul>
*/
public Result testException() throws Exception {
Method method = class1.getMethod("methodThrowException",
new Class[] { String.class });
ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
"description", method);
Descriptor descriptor = operationInfo1.getDescriptor();
descriptor.setField("currencyTimeLimit", "0");
operationInfo1.setDescriptor(descriptor);
ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
class1.getName(), "description", null, null,
new ModelMBeanOperationInfo[] { operationInfo1 }, null);
RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
beanInfoSupport);
requiredModelMBean.setManagedResource(this, "ObjectReference");
ObjectName objectName = new ObjectName("domain", "name", "simple name");
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.registerMBean(requiredModelMBean, objectName);
try {
server.invoke(objectName, method.getName(),
new Object[] { "message" }, new String[] { String.class
.getName() });
assertTrue(false);
} catch (MBeanException e) {
assertEquals(e.getCause().getMessage(), "message");
}
assertTrue(isInvokedMethod());
return result();
}
InvocationTest.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:freeVM
作者:
评论列表
文章目录