KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > timer > unit > RemoteUnitTestCase


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.ejb3.test.timer.unit;
23
24 import java.util.Date JavaDoc;
25
26 import org.jboss.ejb3.test.timer.TimerTester;
27 import org.jboss.test.JBossTestCase;
28 import junit.framework.Test;
29
30 /**
31  * Sample client for the jboss container.
32  *
33  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
34  * @version $Id: RemoteUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
35  */

36
37 public class RemoteUnitTestCase
38 extends JBossTestCase
39 {
40    org.jboss.logging.Logger log = getLog();
41
42    static boolean deployed = false;
43    static int test = 0;
44
45    public RemoteUnitTestCase(String JavaDoc name)
46    {
47
48       super(name);
49
50    }
51
52    public void testNewTransaction() throws Exception JavaDoc
53    {
54       TimerTester test = (TimerTester) getInitialContext().lookup("TransactionalTimerTesterBean/remote");
55       test.startTimer(5000);
56       test.accessTimer();
57       Thread.sleep(6000);
58       assertTrue(test.isTimerCalled());
59    }
60    
61    // EJBTHREE-630
62
public void testPersistence() throws Exception JavaDoc
63    {
64       TimerTester test = (TimerTester) getInitialContext().lookup("TimerTesterService/remote");
65       long when = System.currentTimeMillis() + 5000;
66       test.setTimer(new Date JavaDoc(when));
67       
68       redeploy("timer-test.jar");
69       
70       test = (TimerTester) getInitialContext().lookup("TimerTesterService/remote");
71       long wait = 1000 + (when - System.currentTimeMillis());
72       if(wait > 0)
73          Thread.sleep(wait);
74       assertTrue(test.isTimerCalled());
75    }
76    
77    public void testService() throws Exception JavaDoc
78    {
79       TimerTester test = (TimerTester) getInitialContext().lookup("TimerTesterService/remote");
80       test.startTimer(5000);
81       test.accessTimer();
82       Thread.sleep(6000);
83       assertTrue(test.isTimerCalled());
84       test.startTimerViaEJBContext(5000);
85       test.accessTimer();
86       Thread.sleep(6000);
87       assertTrue(test.isTimerCalled());
88    }
89    
90    public void testSimple() throws Exception JavaDoc
91    {
92       TimerTester test = (TimerTester) this.getInitialContext().lookup("TimerTesterBean/remote");
93       test.startTimer(5000);
94       test.accessTimer();
95       Thread.sleep(6000);
96       assertTrue(test.isTimerCalled());
97       test.startTimerViaEJBContext(5000);
98       test.accessTimer();
99       Thread.sleep(6000);
100       assertTrue(test.isTimerCalled());
101    }
102    
103    public void testSimple21() throws Exception JavaDoc
104    {
105       TimerTester test = (TimerTester) this.getInitialContext().lookup("TimerTesterBean21");
106       test.startTimer(5000);
107       test.accessTimer();
108       Thread.sleep(6000);
109       assertTrue(test.isTimerCalled());
110       test.startTimerViaEJBContext(5000);
111       test.accessTimer();
112       Thread.sleep(6000);
113       assertTrue(test.isTimerCalled());
114    }
115
116    public void testRollback() throws Exception JavaDoc
117    {
118       TimerTester test = (TimerTester) this.getInitialContext().lookup("TimerTesterBean/remote");
119       test.startTimerAndRollback(5000);
120       Thread.sleep(6000);
121       assertFalse(test.isTimerCalled());
122    }
123    
124    public static Test suite() throws Exception JavaDoc
125    {
126       return getDeploySetup(RemoteUnitTestCase.class, "timer-test.jar");
127    }
128
129 }
130
Popular Tags