KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > implementation > persistence > OnTimerPersistenceTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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 JavaDoc;
25 import javax.management.MBeanServerFactory JavaDoc;
26 import javax.management.Descriptor JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.modelmbean.DescriptorSupport JavaDoc;
29 import javax.management.modelmbean.ModelMBean JavaDoc;
30 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
31 import javax.management.modelmbean.ModelMBeanInfoSupport JavaDoc;
32 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
33 import javax.management.modelmbean.RequiredModelMBean JavaDoc;
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 JavaDoc s)
47    {
48       super(s);
49    }
50
51    public void testOnTimerCallback()
52    {
53       try
54       {
55          MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
56          
57          Descriptor JavaDoc descriptor = new DescriptorSupport JavaDoc();
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 JavaDoc attrInfo = new ModelMBeanAttributeInfo JavaDoc(
64                "Active",
65                boolean.class.getName(),
66                "Test Attribute",
67                IS_READABLE,
68                !IS_WRITABLE,
69                !IS_IS,
70                descriptor
71          );
72          
73          ModelMBeanInfo JavaDoc info = new ModelMBeanInfoSupport JavaDoc(
74                Resource.class.getName(),
75                "Test Resource",
76                new ModelMBeanAttributeInfo JavaDoc[] { attrInfo },
77                null, // constructors
78
null, // operations
79
null // notification
80
);
81          
82          ModelMBean JavaDoc mmb = new RequiredModelMBean JavaDoc();
83          mmb.setManagedResource(new Resource(), OBJECT_REF);
84          mmb.setModelMBeanInfo(info);
85          
86          ObjectName JavaDoc oname = new ObjectName JavaDoc("test:name=OnTimerCallBack");
87          server.registerMBean(mmb, oname);
88          
89          Thread.sleep(5000);
90       }
91       catch (Throwable JavaDoc t)
92       {
93          t.printStackTrace();
94          fail("Creating Required ModelMBean instance with default constructor failed: " + t.toString());
95       }
96    }
97
98 }
99
Popular Tags