/**
* Verify that value of attribute always retrieves from returned value of
* getter method if currencyTimeLimit is not defined in descriptor.
* <p>
* Instructions are the same as in testNegative.
*/
public Result testNotPresent() throws Exception {
Method getter = class1.getMethod("getG", null);
Method setter = class1.getMethod("setG", new Class[] { String.class });
ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
"name", "description", getter, setter);
Descriptor descriptor = attributeInfoForG.getDescriptor();
descriptor.setField("setMethod", setter.getName());
descriptor.setField("getMethod", getter.getName());
attributeInfoForG.setDescriptor(descriptor);
ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
ModelMBeanOperationInfo[] operationInfos = new ModelMBeanOperationInfo[] {
new ModelMBeanOperationInfo("description", setter),
new ModelMBeanOperationInfo("description", getter) };
ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
class1.getName(), "description", attributeInfos, null,
operationInfos, null);
RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
beanInfoSupport);
ManageResourceAndNotification notificationListener = new ManageResourceAndNotification();
requiredModelMBean.addAttributeChangeNotificationListener(
notificationListener, attributeInfoForG.getName(),
ManageResourceAndNotification.handback);
ManageResourceAndNotification managedResource = new ManageResourceAndNotification();
requiredModelMBean.setManagedResource(managedResource,
"ObjectReference");
ObjectName objectName = new ObjectName("domain", "name", "simple name");
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.registerMBean(requiredModelMBean, objectName);
String newValue = "new value";
server.setAttribute(objectName, new Attribute(attributeInfoForG
.getName(), newValue));
assertTrue(notificationListener.isWasHandleNotificationInvoked());
assertEquals(managedResource.getG(), newValue);
managedResource.isGetGWasInvoked();
assertEquals(server.getAttribute(objectName, attributeInfoForG
.getName()), newValue);
assertTrue(managedResource.isGetGWasInvoked());
assertTrue(server.getMBeanInfo(objectName).getAttributes()[0] == attributeInfoForG);
assertNull(attributeInfoForG.getDescriptor().getFieldValue("value"));
return result();
}
RequiredModelMBeanTest.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:freeVM
作者:
评论列表
文章目录