KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jca15 > F_Worker


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_Worker.java,v 1.1 2005/04/07 09:37:22 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.jca15;
27
28 import java.rmi.RemoteException JavaDoc;
29
30 import javax.naming.NamingException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36 import org.objectweb.jonas.jtests.beans.worker.Worker;
37 import org.objectweb.jonas.jtests.beans.worker.WorkerHome;
38 import org.objectweb.jonas.jtests.util.JTestCase;
39
40
41 public class F_Worker extends JTestCase {
42
43     private static String JavaDoc BEAN_HOME = "workerHome";
44     private static WorkerHome home = null;
45
46     public F_Worker(String JavaDoc name) {
47         super(name);
48     }
49
50     public WorkerHome getHome() {
51         if (home == null) {
52             try {
53                 home = (WorkerHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), WorkerHome.class);
54             } catch (NamingException JavaDoc e) {
55                 fail("Cannot get bean home");
56             }
57         }
58         return home;
59     }
60
61     protected void setUp() {
62         super.setUp();
63         useBeans("worker", false);
64     }
65
66     public void testDoWorkTx() throws Exception JavaDoc {
67         Worker w = getHome().create();
68         int count = 1;
69         w.doWorkInTx();
70         assertEquals("count", count, w.getwcount());
71         w.remove();
72     }
73
74     public void testStartWorkTx() throws Exception JavaDoc {
75         Worker w = getHome().create();
76         int count = 1;
77         w.startWorkInTx();
78         assertEquals("count", count, w.getwcount());
79         w.remove();
80     }
81
82     public void testScheduleWorkTx() throws Exception JavaDoc {
83         Worker w = getHome().create();
84         int count = 1;
85         w.scheduleWorkInTx();
86         assertEquals("count", count, w.getwcount());
87         w.remove();
88     }
89
90     public void testDoWorkBasic() throws Exception JavaDoc {
91         Worker w = getHome().create();
92         int count = 1;
93         w.doWorks(count);
94         assertEquals("count", count, w.getwcount());
95         w.remove();
96     }
97
98     public void testDo20Works() throws Exception JavaDoc {
99         Worker w = getHome().create();
100         int count = 20;
101         w.doWorks(count);
102         assertEquals("count", count, w.getwcount());
103         w.remove();
104     }
105
106     public void testStartWorkBasic() throws Exception JavaDoc {
107         Worker w = getHome().create();
108         int count = 1;
109         w.startWorks(count);
110         sleep(500);
111         assertEquals("count", count, w.getwcount());
112         w.remove();
113     }
114
115     public void testStart20Works() throws Exception JavaDoc {
116         Worker w = getHome().create();
117         int count = 20;
118         w.startWorks(count);
119         sleep(2000);
120         assertEquals("count", count, w.getwcount());
121         w.remove();
122     }
123
124     public void testScheduleWorkBasic() throws Exception JavaDoc {
125         Worker w = getHome().create();
126         int count = 1;
127         w.scheduleWorks(count, 20000);
128         sleep(500);
129         assertEquals("count", count, w.getwcount());
130         assertEquals("accepted", count, w.getNotifyAccepted());
131         assertEquals("started", count, w.getNotifyStarted());
132         assertEquals("rejected", 0, w.getNotifyRejected());
133         assertEquals("completed", count, w.getNotifyCompleted());
134         w.remove();
135     }
136
137     public void testScheduleWorkTimedout() throws Exception JavaDoc {
138         Worker w = getHome().create();
139         int count = 1;
140         w.scheduleWorks(count, 1L);
141         sleep(500);
142         assertEquals("count", 0, w.getwcount());
143         assertEquals("accepted", count, w.getNotifyAccepted());
144         assertEquals("started", 0, w.getNotifyStarted());
145         assertEquals("rejected", count, w.getNotifyRejected());
146         assertEquals("completed", 0, w.getNotifyCompleted());
147         w.remove();
148     }
149
150     public void testSchedule20Works() throws Exception JavaDoc {
151         Worker w = getHome().create();
152         int count = 20;
153         w.scheduleWorks(count, 20000);
154         sleep(2000);
155         assertEquals("count", count, w.getwcount());
156         assertEquals("accepted", count, w.getNotifyAccepted());
157         assertEquals("started", count, w.getNotifyStarted());
158         assertEquals("rejected", 0, w.getNotifyRejected());
159         assertEquals("completed", count, w.getNotifyCompleted());
160         w.remove();
161     }
162
163     public static Test suite() {
164         return new TestSuite(F_Worker.class);
165     }
166
167     public static void main (String JavaDoc args[]) {
168         String JavaDoc testtorun = null;
169         // Get args
170
for (int argn = 0; argn < args.length; argn++) {
171             String JavaDoc s_arg = args[argn];
172             Integer JavaDoc i_arg;
173             if (s_arg.equals("-n")) {
174                 testtorun = args[++argn];
175             }
176         }
177         if (testtorun == null) {
178             junit.textui.TestRunner.run(suite());
179         } else {
180             junit.textui.TestRunner.run(new F_Worker(testtorun));
181         }
182     }
183 }
184
185
Popular Tags