mx4j/src/test/test/javax/management/modelmbean RequiredModelMBeanTest.java,1.13,1.14
Jeremy Boynes <[email protected]> Sun, 13 Feb 2005 16:36:18 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/test/test/javax/management/modelmbean
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26074/src/test/test/javax/management/modelmbean
Modified Files:
RequiredModelMBeanTest.java
Log Message:
Fix for [ 1121844 ] RequiredModelMBean must list default notifications
Fix for [ 1121843 ] RequiredModelMBean should have one notification broadcaster
Also fixes problems with argument checking and ensures correct Exception is thrown
Index: RequiredModelMBeanTest.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/test/test/javax/management/modelmbean/RequiredModelMBeanTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** RequiredModelMBeanTest.java 13 Nov 2004 16:38:43 -0000 1.13
--- RequiredModelMBeanTest.java 13 Feb 2005 16:36:16 -0000 1.14
***************
*** 10,33 ****
import java.util.List;
! import javax.management.Attribute;
! import javax.management.AttributeList;
! import javax.management.Descriptor;
! import javax.management.InstanceNotFoundException;
! import javax.management.MBeanException;
! import javax.management.MBeanParameterInfo;
! import javax.management.MBeanServer;
! import javax.management.MBeanServerFactory;
! import javax.management.NotCompliantMBeanException;
! import javax.management.Notification;
! import javax.management.NotificationListener;
! import javax.management.ObjectName;
! import javax.management.RuntimeOperationsException;
! import javax.management.modelmbean.DescriptorSupport;
! import javax.management.modelmbean.ModelMBean;
! import javax.management.modelmbean.ModelMBeanAttributeInfo;
! import javax.management.modelmbean.ModelMBeanInfoSupport;
! import javax.management.modelmbean.ModelMBeanNotificationInfo;
! import javax.management.modelmbean.ModelMBeanOperationInfo;
! import javax.management.modelmbean.RequiredModelMBean;
import test.MX4JTestCase;
--- 10,15 ----
import java.util.List;
! import javax.management.*;
! import javax.management.modelmbean.*;
import test.MX4JTestCase;
***************
*** 81,88 ****
{
m_server.registerMBean(rmmb, name);
! fail("RequireModelMBean cannot be registered, ModelMBeanInfo is missing");
}
catch (NotCompliantMBeanException x)
{
}
--- 63,71 ----
{
m_server.registerMBean(rmmb, name);
! m_server.unregisterMBean(name);
}
catch (NotCompliantMBeanException x)
{
+ fail("Default RequireModelMBean cannot be registered");
}
***************
*** 90,97 ****
{
m_server.createMBean(RequiredModelMBean.class.getName(), name, null);
! fail("RequireModelMBean cannot be registered, ModelMBeanInfo is missing");
}
catch (NotCompliantMBeanException x)
{
}
--- 73,81 ----
{
m_server.createMBean(RequiredModelMBean.class.getName(), name, null);
! m_server.unregisterMBean(name);
}
catch (NotCompliantMBeanException x)
{
+ fail("Default RequireModelMBean cannot be created");
}
***************
*** 373,381 ****
rmmb.removeAttributeChangeNotificationListener(dummyListener, null);
! // Change the persist policy
attrDescr1.setField("persistPolicy", "OnUpdate");
info.setDescriptor(attrDescr1, "attribute");
rmmb.setModelMBeanInfo(info);
storeTester.set(false);
value = "SET_SECOND_TIME";
--- 357,367 ----
rmmb.removeAttributeChangeNotificationListener(dummyListener, null);
! // Change the persist policy - have to unregeister to call setModelMBeanInfo
! m_server.unregisterMBean(name);
attrDescr1.setField("persistPolicy", "OnUpdate");
info.setDescriptor(attrDescr1, "attribute");
rmmb.setModelMBeanInfo(info);
storeTester.set(false);
+ m_server.registerMBean(rmmb, name);
value = "SET_SECOND_TIME";
***************
*** 388,392 ****
assertTrue("Store should have been called", storeTester.get());
! // Now remove setMethod
names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "currencyTimeLimit"};
// changed to match the actual behaviour indicated in the specs about currencyTimeLimit
--- 374,379 ----
assertTrue("Store should have been called", storeTester.get());
! // Now remove setMethod - again we have to unregister
! m_server.unregisterMBean(name);
names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "currencyTimeLimit"};
// changed to match the actual behaviour indicated in the specs about currencyTimeLimit
***************
*** 398,401 ****
--- 385,389 ----
rmmb.setModelMBeanInfo(info);
storeTester.set(false);
+ m_server.registerMBean(rmmb, name);
value = "SET_THIRD_TIME";
***************
*** 418,421 ****
--- 406,410 ----
// Test attribute that takes array as parameters
+ m_server.unregisterMBean(name);
String attrName = "ArrayAttribute";
String[] names = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "setMethod", "currencyTimeLimit"};
***************
*** 428,431 ****
--- 417,421 ----
info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attrInfo}, null, null, null);
rmmb.setModelMBeanInfo(info);
+ m_server.registerMBean(rmmb, name);
String[] v = new String[]{"one", "two"};
***************
*** 544,547 ****
--- 534,538 ----
}
+ m_server.unregisterMBean(name);
ModelMBeanTarget.TargetBean target = new ModelMBeanTarget.TargetBean();
operDescr.setField("targetObject", target);
***************
*** 550,553 ****
--- 541,546 ----
info.setDescriptor(operDescr, "operation");
rmmb.setModelMBeanInfo(info);
+ m_server.registerMBean(rmmb, name);
+
list = (List)m_server.invoke(name, operation, args, params);
***************
*** 588,595 ****
m_server.invoke(name, "setManagedResource", new Object[]{new ModelMBeanTarget(new MutableInteger(0)), "ObjectReference"}, new String[]{Object.class.getName(), String.class.getName()});
m_server.invoke(name, "store", new Object[0], new String[0]);
- m_server.invoke(name, "load", new Object[0], new String[0]);
m_server.invoke(name, "sendNotification", new Object[]{"generic"}, new String[]{String.class.getName()});
// Now specify setManagedResource as an operation in the MMBI
String operation = "setManagedResource";
MBeanParameterInfo paramInfo1 = new MBeanParameterInfo("resource", Object.class.getName(), "");
--- 581,588 ----
m_server.invoke(name, "setManagedResource", new Object[]{new ModelMBeanTarget(new MutableInteger(0)), "ObjectReference"}, new String[]{Object.class.getName(), String.class.getName()});
m_server.invoke(name, "store", new Object[0], new String[0]);
m_server.invoke(name, "sendNotification", new Object[]{"generic"}, new String[]{String.class.getName()});
// Now specify setManagedResource as an operation in the MMBI
+ m_server.unregisterMBean(name);
String operation = "setManagedResource";
MBeanParameterInfo paramInfo1 = new MBeanParameterInfo("resource", Object.class.getName(), "");
***************
*** 598,601 ****
--- 591,596 ----
info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", null, null, new ModelMBeanOperationInfo[]{operInfo}, null);
mmb.setModelMBeanInfo(info);
+ m_server.registerMBean(mmb, name);
+
// Spec says I must be able to invoke it
Object target = new ModelMBeanTarget(new MutableInteger(0));
***************
*** 610,617 ****
notification[0] = new ModelMBeanNotificationInfo(new String[]{ModelMBeanTarget.class.getName() + ".notification"}, "name", "");
! ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", null, null, null, notification);
RequiredModelMBean rmmb = new RequiredModelMBean();
rmmb.setModelMBeanInfo(info);
m_server.registerMBean(rmmb, name);
--- 605,614 ----
notification[0] = new ModelMBeanNotificationInfo(new String[]{ModelMBeanTarget.class.getName() + ".notification"}, "name", "");
! ModelMBeanAttributeInfo attributeInfo = new ModelMBeanAttributeInfo("MutableContent", String.class.getName(), "", true, true, false);
! ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attributeInfo}, null, null, notification);
RequiredModelMBean rmmb = new RequiredModelMBean();
rmmb.setModelMBeanInfo(info);
+ rmmb.setManagedResource(new ModelMBeanTarget(new MutableInteger(0)), "objectReference");
m_server.registerMBean(rmmb, name);
***************
*** 622,626 ****
rmmb.sendNotification("generic notification");
! assertEquals("jmx.modelmbean.general", listener.type);
assertEquals("generic notification", listener.message);
assertSame(listenerHandback, listener.handback);
--- 619,623 ----
rmmb.sendNotification("generic notification");
! assertEquals("jmx.modelmbean.generic", listener.type);
assertEquals("generic notification", listener.message);
assertSame(listenerHandback, listener.handback);
***************
*** 630,633 ****
--- 627,648 ----
assertEquals("a message", listener.message);
assertSame(listenerHandback, listener.handback);
+
+ m_server.setAttribute(name, new Attribute("MutableContent", "Hello World"));
+ assertEquals("jmx.attribute.change", listener.type);
+ }
+
+ public void testGetNotificationInfo() throws Exception
+ {
+ RequiredModelMBean rmmb = new RequiredModelMBean();
+ MBeanNotificationInfo[] notificationInfos = rmmb.getNotificationInfo();
+ assertEquals(2, notificationInfos.length);
+
+ ModelMBeanNotificationInfo notification[] = new ModelMBeanNotificationInfo[1];
+ notification[0] = new ModelMBeanNotificationInfo(new String[]{ModelMBeanTarget.class.getName() + ".notification"}, "name", "");
+
+ ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", null, null, null, notification);
+ rmmb.setModelMBeanInfo(info);
+ notificationInfos = rmmb.getNotificationInfo();
+ assertEquals(3, notificationInfos.length);
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click