1 22 package test.implementation.persistence; 23 24 import javax.management.MBeanServer ; 25 import javax.management.MBeanServerFactory ; 26 import javax.management.Descriptor ; 27 import javax.management.ObjectName ; 28 import javax.management.modelmbean.DescriptorSupport ; 29 import javax.management.modelmbean.ModelMBean ; 30 import javax.management.modelmbean.ModelMBeanInfo ; 31 import javax.management.modelmbean.ModelMBeanInfoSupport ; 32 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 33 import javax.management.modelmbean.RequiredModelMBean ; 34 35 import org.jboss.mx.modelmbean.ModelMBeanConstants; 36 37 import junit.framework.TestCase; 38 39 import test.implementation.persistence.support.Resource; 40 41 public class OnTimerPersistenceTEST 42 extends TestCase 43 implements ModelMBeanConstants 44 { 45 46 public OnTimerPersistenceTEST(String s) 47 { 48 super(s); 49 } 50 51 public void testOnTimerCallback() 52 { 53 try 54 { 55 MBeanServer server = MBeanServerFactory.createMBeanServer(); 56 57 Descriptor descriptor = new DescriptorSupport (); 58 descriptor.setField(NAME, "Active"); 59 descriptor.setField(DESCRIPTOR_TYPE, ATTRIBUTE_DESCRIPTOR); 60 descriptor.setField(PERSIST_POLICY, PP_ON_TIMER); 61 descriptor.setField(PERSIST_PERIOD, "1000"); 62 63 ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo ( 64 "Active", 65 boolean.class.getName(), 66 "Test Attribute", 67 IS_READABLE, 68 !IS_WRITABLE, 69 !IS_IS, 70 descriptor 71 ); 72 73 ModelMBeanInfo info = new ModelMBeanInfoSupport ( 74 Resource.class.getName(), 75 "Test Resource", 76 new ModelMBeanAttributeInfo [] { attrInfo }, 77 null, null, null ); 81 82 ModelMBean mmb = new RequiredModelMBean (); 83 mmb.setManagedResource(new Resource(), OBJECT_REF); 84 mmb.setModelMBeanInfo(info); 85 86 ObjectName oname = new ObjectName ("test:name=OnTimerCallBack"); 87 server.registerMBean(mmb, oname); 88 89 Thread.sleep(5000); 90 } 91 catch (Throwable t) 92 { 93 t.printStackTrace(); 94 fail("Creating Required ModelMBean instance with default constructor failed: " + t.toString()); 95 } 96 } 97 98 } 99 | Popular Tags |