01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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 extends TestCase implements
42: ModelMBeanConstants {
43:
44: public OnTimerPersistenceTEST(String s) {
45: super (s);
46: }
47:
48: public void testOnTimerCallback() {
49: try {
50: MBeanServer server = MBeanServerFactory.createMBeanServer();
51:
52: Descriptor descriptor = new DescriptorSupport();
53: descriptor.setField(NAME, "Active");
54: descriptor.setField(DESCRIPTOR_TYPE, ATTRIBUTE_DESCRIPTOR);
55: descriptor.setField(PERSIST_POLICY, PP_ON_TIMER);
56: descriptor.setField(PERSIST_PERIOD, "1000");
57:
58: ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo(
59: "Active", boolean.class.getName(),
60: "Test Attribute", IS_READABLE, !IS_WRITABLE,
61: !IS_IS, descriptor);
62:
63: ModelMBeanInfo info = new ModelMBeanInfoSupport(
64: Resource.class.getName(), "Test Resource",
65: new ModelMBeanAttributeInfo[] { attrInfo }, null, // constructors
66: null, // operations
67: null // notification
68: );
69:
70: ModelMBean mmb = new RequiredModelMBean();
71: mmb.setManagedResource(new Resource(), OBJECT_REF);
72: mmb.setModelMBeanInfo(info);
73:
74: ObjectName oname = new ObjectName(
75: "test:name=OnTimerCallBack");
76: server.registerMBean(mmb, oname);
77:
78: Thread.sleep(5000);
79: } catch (Throwable t) {
80: t.printStackTrace();
81: fail("Creating Required ModelMBean instance with default constructor failed: "
82: + t.toString());
83: }
84: }
85:
86: }
|