KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > txtimer > test > TimerTestBase


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 org.jboss.test.txtimer.test;
23
24 import javax.ejb.TimedObject JavaDoc;
25 import javax.ejb.TimerService JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.jboss.ejb.AllowedOperationsAssociation;
31 import org.jboss.ejb.txtimer.EJBTimerService;
32 import org.jboss.ejb.txtimer.EJBTimerServiceLocator;
33 import org.jboss.ejb.txtimer.TimedObjectId;
34
35 /**
36  * @author Thomas.Diesler@jboss.org
37  * @since 07-Apr-2004
38  */

39 public abstract class TimerTestBase extends TestCase
40 {
41    protected EJBTimerService ejbTimerService;
42
43    protected TimerTestBase(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    /**
49     * Sets up the fixture, for example, open a network connection.
50     * This method is called before a test is executed.
51     */

52    protected void setUp() throws Exception JavaDoc
53    {
54       super.setUp();
55       ejbTimerService = EJBTimerServiceLocator.getEjbTimerService();
56
57       // when the timer runs inside JBoss, this is taken care of by the container
58
// is standalone mode, we fake the context for timer operations, so the timer thinks we are inside a EJB
59
// business method, and does not refuse the operations
60
AllowedOperationsAssociation.pushInMethodFlag(AllowedOperationsAssociation.IN_BUSINESS_METHOD);
61    }
62
63    /**
64     * Tears down the fixture, for example, close a network connection.
65     * This method is called after a test is executed.
66     */

67    protected void tearDown() throws Exception JavaDoc
68    {
69       super.tearDown();
70       AllowedOperationsAssociation.popInMethodFlag();
71    }
72
73    protected TimerService JavaDoc createTimerService(TimedObject JavaDoc timedObject)
74    {
75       SimpleTimedObjectInvoker invoker = new SimpleTimedObjectInvoker();
76       TimedObjectId timedObjectId = invoker.addTimedObject(timedObject);
77       ObjectName JavaDoc containerId = timedObjectId.getContainerId();
78       Object JavaDoc instancePk = timedObjectId.getInstancePk();
79       return ejbTimerService.createTimerService(containerId, instancePk, invoker);
80    }
81
82    protected void sleep(long interval) throws InterruptedException JavaDoc
83    {
84       synchronized (this)
85       {
86          wait(interval);
87       }
88    }
89 }
90
Popular Tags