InvocationTest.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:freeVM 作者:
/**
 * Verify that invoke method invokes correctly method with parameter and
 * without it.
 * <ul>
 * Step by step:
 * <li>Create operation method without parameters which always returns the
 * same value.
 * <li>Create operation method with name as in 1 step with parameter which
 * always returns the parameter.
 * <li>Create 2 ModelMBeanOperationInfo object for both operation method.
 * <li>Create ModelMBeanInfoSupport object with default descriptor. All
 * ModelMBeanXXXInfo except ModelMBeanOperationInfo are default.
 * <li>Create RequiredModelMBean object.
 * <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 1st operation method thru invoke method of MBeanServer:
 * server.invoke(objectName, methodName, null, null).
 * <li>Verify value which the invoke method returned is the same as value
 * which the 1st operation method returned.
 * <li>Invoke 2nd operation method thru invoke method of MBeanServer:
 * server.invoke(objectName, methodName, argument, signature).
 * <li>Verify value which the invoke method returned is the same as
 * argument.
 * </ul>
 */
public Result testMethodWithParameter() throws Exception {
    Method method1 = class1.getDeclaredMethod("simpleMethod",
        new Class[] { int.class });
    ModelMBeanOperationInfo operationInfo1 = new ModelMBeanOperationInfo(
        "description", method1);
    Method method2 = class1.getMethod("simpleMethod", null);
    ModelMBeanOperationInfo operationInfo2 = new ModelMBeanOperationInfo(
        "description", method2);
    ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
        class1.getName(), "description", null, null,
        new ModelMBeanOperationInfo[] { operationInfo1, operationInfo2 },
        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);
    Object value = server.invoke(objectName, method2.getName(), null, null);
    assertEquals(value, returnedObject);
    int integer = 8;
    value = server.invoke(objectName, method1.getName(),
        new Object[] { new Integer(integer) }, new String[] { method1
            .getParameterTypes()[0].getName() });
    assertEquals(value, new Integer(integer));
    return result();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号