KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > timer > F_TimerMD


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_TimerMD.java,v 1.2 2004/05/24 12:32:46 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.timer;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34 import org.objectweb.jonas.jtests.beans.message.Sender1_1;
35 import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * test TimerService on Message Driven Beans
40  */

41 public class F_TimerMD extends JTestCase {
42
43     // Uses JMS 1.1 (std API for J2EE 1.4)
44
private static String JavaDoc BEAN_HOME = "messageSender1_1SFHome";
45     protected static Sender1_1Home home = null;
46
47     // Must be the same values than in org.objectweb.jonas.jtests.beans.message.Listener
48
public static final int CREATE_TIMER_MIN = 1500;
49     public static final int CREATE_TIMER_MAX = 1600;
50
51     /**
52      * constructor
53      * @param name name of the test suite.
54      */

55     public F_TimerMD(String JavaDoc name) {
56         super(name);
57     }
58
59     /**
60      * Sets up the fixture, here load the beans if not loaded yet.
61      * This method is called before a test is executed.
62      */

63     protected void setUp() {
64         super.setUp();
65         useBeans("message", true);
66     }
67
68
69     public Sender1_1Home getHome() {
70         if (home == null) {
71             try {
72                 home = (Sender1_1Home) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), Sender1_1Home.class);
73             } catch (NamingException JavaDoc e) {
74                 fail("Cannot get bean home");
75             }
76         }
77         return home;
78     }
79
80     /**
81      * Basic test: Send 1 message on a topic
82      * 2 MDB are reading the topic.
83      * No tx.
84      */

85     public void testBasicSendOnTopic1() throws Exception JavaDoc {
86         Sender1_1 s = getHome().create();
87         int val = 200;
88         s.sendOnDestination("JunitTopic1", val, 1);
89         assertEquals(2, s.check(val, 2, 4));
90         s.remove();
91     }
92
93     /**
94      * Start a timer on Topic MDB
95      */

96     public void testTimerTopic1() throws Exception JavaDoc {
97         Sender1_1 s = getHome().create();
98         int val = CREATE_TIMER_MIN + 4;
99         s.sendOnDestination("JunitTopic1", val, 1);
100         assertEquals(2, s.check(val, 2, 5));
101         s.remove();
102     }
103
104     /**
105      * Start a timer on Queue MDB
106      */

107     public void testTimerQueue1() throws Exception JavaDoc {
108         Sender1_1 s = getHome().create();
109         int val = CREATE_TIMER_MIN + 5;
110         s.sendOnDestination("JunitQueue1", val, 1);
111         assertEquals(1, s.check(val, 1, 6));
112         s.remove();
113     }
114
115     /**
116      * Start several timers on Queue MDB
117      */

118     public void testTimersQueue1() throws Exception JavaDoc {
119         Sender1_1 s = getHome().create();
120         int val = CREATE_TIMER_MIN + 6;
121         s.sendOnDestination("JunitQueue1", val, 5);
122         assertEquals(5, s.check(val, 5, 7));
123         s.remove();
124     }
125
126     /**
127      * This suite is all Session Statless test cases
128      */

129     public static Test suite() {
130         return new TestSuite(F_TimerMD.class);
131     }
132
133     public static void main (String JavaDoc args[]) {
134         String JavaDoc testtorun = null;
135         // Get args
136
for (int argn = 0; argn < args.length; argn++) {
137             String JavaDoc sarg = args[argn];
138             if (sarg.equals("-n")) {
139                 testtorun = args[++argn];
140             }
141         }
142         if (testtorun == null) {
143             junit.textui.TestRunner.run(suite());
144         } else {
145             junit.textui.TestRunner.run(new F_TimerMD(testtorun));
146         }
147     }
148 }
149
Popular Tags