KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jms > F_BasicMDB


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_BasicMDB.java,v 1.5 2005/04/22 07:43:05 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.jms;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32 import org.objectweb.jonas.jtests.util.JTestCase;
33 import org.objectweb.jonas.jtests.beans.message.Sender;
34 import org.objectweb.jonas.jtests.beans.message.SenderHome;
35 import org.objectweb.jonas.jtests.beans.message.Sender1_1;
36 import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
37
38 public class F_BasicMDB extends JTestCase {
39
40     private static String JavaDoc BEAN_HOME = "messageSenderSFHome";
41     private static String JavaDoc BEAN1_1_HOME = "messageSender1_1SFHome";
42     protected static SenderHome home = null;
43     protected static Sender1_1Home home1 = null;
44
45     public F_BasicMDB(String JavaDoc name) {
46         super(name);
47     }
48
49     public SenderHome getHome() {
50         if (home == null) {
51             try {
52                 home = (SenderHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), SenderHome.class);
53             } catch (NamingException JavaDoc e) {
54                 fail("Cannot get bean home");
55             }
56         }
57         return home;
58     }
59
60     public Sender1_1Home getHome1() {
61         if (home1 == null) {
62             try {
63                 home1 = (Sender1_1Home) PortableRemoteObject.narrow(ictx.lookup(BEAN1_1_HOME), Sender1_1Home.class);
64             } catch (NamingException JavaDoc e) {
65                 fail("Cannot get bean home1");
66             }
67         }
68         return home1;
69     }
70
71     /**
72      * init environment:
73      * - load beans
74      * - create/init database for entities.
75      */

76     protected void setUp() {
77         super.setUp();
78         useBeans("message", true);
79     }
80
81     // --------------------------------------------------------
82
// Basic Tests on Topics
83
// --------------------------------------------------------
84

85     /**
86      * Basic test: Send 1 message on a topic
87      * 2 MDB are reading the topic.
88      * No tx.
89      */

90     public void testBasicSendOnTopic1() throws Exception JavaDoc {
91         Sender s = getHome().create();
92         int val = 200;
93         s.sendOnTopic("JunitTopic1", val, 1);
94         assertEquals(2, s.check(val, 2, 4));
95         s.remove();
96     }
97
98     /**
99      * Basic test: Send 1 message on a topic Durable
100      * 2 MDB are reading the topic.
101      * No tx.
102      */

103     public void testBasicSendOnTopic2() throws Exception JavaDoc {
104         Sender s = getHome().create();
105         int val = 200;
106         s.sendOnTopic("JunitTopic2", val, 1);
107         assertEquals(2, s.check(val, 2, 4));
108         s.remove();
109     }
110
111     /**
112      * Basic test: Send nb messages on a topic
113      * 2 MDB are reading the topic.
114      * No tx.
115      */

116     public void testMultipleSendOnTopic1() throws Exception JavaDoc {
117         Sender s = getHome().create();
118         int val = 210;
119         int nb = 10;
120         s.sendOnTopic("JunitTopic1", val, nb);
121         assertEquals(nb * 2, s.check(val, nb * 2, 8));
122         s.remove();
123     }
124
125     /**
126      * Basic test: Send 1 message on a topic
127      * 2 MDB are reading the topic.
128      * tx.
129      */

130     public void testBasicSendOnTopic1Tx() throws Exception JavaDoc {
131         Sender s = getHome().create();
132         int val = 201;
133         s.sendOnTopicTx("JunitTopic1", val, 1);
134         assertEquals(2, s.check(val, 2, 4));
135         s.remove();
136     }
137
138     /**
139      * Basic test: Send n messages on a topic
140      * 2 MDB are reading the topic.
141      * tx.
142      */

143     public void testMutipleSendOnTopic1Tx() throws Exception JavaDoc {
144         Sender s = getHome().create();
145         int val = 211;
146         int nb = 10;
147         s.sendOnTopicTx("JunitTopic1", val, nb);
148         assertEquals(2 * nb, s.check(val, 2 * nb, 4));
149         s.remove();
150     }
151
152     /**
153      * Basic test: send a message on a topic in a transaction committed
154      */

155     public void testCommitSendOnTopic1() throws Exception JavaDoc {
156
157         Sender s = getHome().create();
158         int val = 206;
159         utx.begin();
160         s.sendOnTopic("JunitTopic1", val, 1);
161         utx.commit();
162         assertEquals(2, s.check(val, 2, 4));
163         s.remove();
164     }
165
166     /**
167      * Basic test: send n message on a topic in a transaction committed
168      */

169     public void testNCommitSendOnTopic1() throws Exception JavaDoc {
170
171         Sender s = getHome().create();
172         int val = 206;
173         int nb = 12;
174         utx.begin();
175         s.sendOnTopic("JunitTopic1", val, nb);
176         utx.commit();
177         assertEquals(2*nb, s.check(val, 2*nb, 4));
178         s.remove();
179     }
180
181     /**
182      * Basic test: send more messages on a topic in a transaction committed
183      */

184     public void testManySendOnTopic() throws Exception JavaDoc {
185
186         Sender s = getHome().create();
187         int val = 2060;
188         int nb = 120;
189         s.sendOnTopic("JunitTopic1", val, nb);
190         assertEquals(2*nb, s.check(val, 2*nb, 80));
191         s.remove();
192     }
193
194     /**
195      * Basic test: Send more messages on a topic
196      * 2 MDB are reading the topic.
197      * tx.
198      */

199     public void testManySendOnTopicTx() throws Exception JavaDoc {
200         Sender s = getHome().create();
201         int val = 2110;
202         int nb = 100;
203         s.sendOnTopicTx("JunitTopic1", val, nb);
204         assertEquals(2 * nb, s.check(val, 2 * nb, 80));
205         s.remove();
206     }
207
208     // --------------------------------------------------------
209
// Basic Tests on Queues
210
// --------------------------------------------------------
211

212     /**
213      * Basic test: Send 1 message on a queue
214      * No tx, MDB transacted.
215      */

216     public void testBasicSendOnQueue1() throws Exception JavaDoc {
217
218         Sender s = getHome().create();
219         int val = 100;
220         s.sendOnQueue("JunitQueue1", val, 1);
221         assertEquals(1, s.check(val, 1, 4));
222         s.remove();
223     }
224
225     /**
226      * Basic test: Send n messages on a queue
227      * No tx, MDB transacted.
228      */

229     public void testMultipleSendOnQueue1() throws Exception JavaDoc {
230         Sender s = getHome().create();
231         int val = 100;
232         int nb = 5;
233         s.sendOnQueue("JunitQueue1", val, nb);
234         assertEquals(nb, s.check(val, nb, 8));
235         s.remove();
236     }
237
238     /**
239      * Basic test: Send 1 message on a queue
240      * tx, MDB transacted.
241      */

242     public void testBasicSendOnQueue1Tx() throws Exception JavaDoc {
243         Sender s = getHome().create();
244         int val = 101;
245         s.sendOnQueueTx("JunitQueue1", val, 1);
246         assertEquals(1, s.check(val, 1, 4));
247         s.remove();
248     }
249
250     /**
251      * Basic test: Send nb messages on a queue
252      * tx, MDB transacted.
253      */

254     public void testMultipleSendOnQueue1Tx() throws Exception JavaDoc {
255         Sender s = getHome().create();
256         int val = 121;
257         int nb = 20;
258         s.sendOnQueueTx("JunitQueue1", val, nb);
259         assertEquals(nb, s.check(val, nb, 10));
260         s.remove();
261     }
262
263     /**
264      * Basic test: Send 1 message on a queue
265      * No tx, MDB not transacted.
266      */

267     public void testBasicSendOnQueue2() throws Exception JavaDoc {
268         Sender s = getHome().create();
269         int val = 102;
270         s.sendOnQueue("JunitQueue2", val, 1);
271         assertEquals(1, s.check(val, 1, 4));
272         s.remove();
273     }
274
275     /**
276      * Basic test: Send 1 message on a queue
277      * tx, MDB not transacted.
278      */

279     public void testBasicSendOnQueue2Tx() throws Exception JavaDoc {
280         Sender s = getHome().create();
281         int val = 103;
282         s.sendOnQueueTx("JunitQueue2", val, 1);
283         assertEquals(1, s.check(val, 1, 4));
284         s.remove();
285     }
286
287
288     /**
289      * Basic test: send a message on a queue in a transaction rolled back
290      * MDB not transacted.
291      */

292     public void testRollbackSendOnQueue2() throws Exception JavaDoc {
293         Sender s = getHome().create();
294         int val = 105;
295         utx.begin();
296         s.sendOnQueue("JunitQueue2", val, 1);
297         utx.rollback();
298         assertEquals(0, s.check(val, 1, 4));
299         s.remove();
300     }
301
302
303     /**
304      * Basic test: send a message on a queue in a transaction committed
305      * MDB transacted.
306      */

307     public void testCommitSendOnQueue1() throws Exception JavaDoc {
308         Sender s = getHome().create();
309         int val = 106;
310         utx.begin();
311         s.sendOnQueue("JunitQueue1", val, 1);
312         utx.commit();
313         assertEquals(1, s.check(val, 1, 4));
314         s.remove();
315     }
316
317
318     /**
319      * Basic test: send a message on a queue in a transaction committed
320      * MDB not transacted.
321      */

322     public void testCommitSendOnQueue2() throws Exception JavaDoc {
323         Sender s = getHome().create();
324         int val = 107;
325         utx.begin();
326         s.sendOnQueue("JunitQueue2", val, 1);
327         utx.commit();
328         assertEquals(1, s.check(val, 1, 4));
329         s.remove();
330     }
331
332
333
334     // --------------------------------------------------------
335
// Basic Tests on Topics (JMS1.1)
336
// --------------------------------------------------------
337

338     /**
339      * Basic test: Send 1 message on a topic
340      * 2 MDB are reading the topic.
341      * No tx.
342      */

343     public void testBasicSendOnDestTopic1() throws Exception JavaDoc {
344         Sender1_1 s = getHome1().create();
345         int val = 200;
346         s.sendOnDestination("JunitTopic1", val, 1);
347         assertEquals(2, s.check(val, 2, 4));
348         s.remove();
349     }
350
351     /**
352      * Basic test: Send 1 message on a topic Durable
353      * 2 MDB are reading the topic.
354      * No tx.
355      */

356     public void testBasicSendOnDestTopic2() throws Exception JavaDoc {
357         Sender1_1 s = getHome1().create();
358         int val = 200;
359         s.sendOnDestination("JunitTopic2", val, 1);
360         assertEquals(2, s.check(val, 2, 4));
361         s.remove();
362     }
363
364     /**
365      * Basic test: Send nb messages on a topic
366      * 2 MDB are reading the topic.
367      * No tx.
368      */

369     public void testMultipleSendOnDestTopic1() throws Exception JavaDoc {
370         Sender1_1 s = getHome1().create();
371         int val = 210;
372         int nb = 10;
373         s.sendOnDestination("JunitTopic1", val, nb);
374         assertEquals(nb * 2, s.check(val, nb * 2, 8));
375         s.remove();
376     }
377
378     /**
379      * Basic test: Send 1 message on a topic
380      * 2 MDB are reading the topic.
381      * tx.
382      */

383     public void testBasicSendOnDestTopic1Tx() throws Exception JavaDoc {
384         Sender1_1 s = getHome1().create();
385         int val = 201;
386         s.sendOnDestinationTx("JunitTopic1", val, 1);
387         assertEquals(2, s.check(val, 2, 4));
388         s.remove();
389     }
390
391     /**
392      * Basic test: Send n messages on a topic
393      * 2 MDB are reading the topic.
394      * tx.
395      */

396     public void testMutipleSendOnDestTopic1Tx() throws Exception JavaDoc {
397         Sender1_1 s = getHome1().create();
398         int val = 211;
399         int nb = 10;
400         s.sendOnDestinationTx("JunitTopic1", val, nb);
401         assertEquals(2*nb, s.check(val, 2*nb, 4));
402         s.remove();
403     }
404
405     /**
406      * Basic test: send a message on a topic in a transaction committed
407      */

408     public void testCommitSendOnDestTopic1() throws Exception JavaDoc {
409
410         Sender1_1 s = getHome1().create();
411         int val = 206;
412         utx.begin();
413         s.sendOnDestination("JunitTopic1", val, 1);
414         utx.commit();
415         assertEquals(2, s.check(val, 2, 4));
416         s.remove();
417     }
418
419     /**
420      * Basic test: send n message on a topic in a transaction committed
421      */

422     public void testNCommitSendOnDestTopic1() throws Exception JavaDoc {
423
424         Sender1_1 s = getHome1().create();
425         int val = 206;
426         int nb = 12;
427         utx.begin();
428         s.sendOnDestination("JunitTopic1", val, nb);
429         utx.commit();
430         assertEquals(2 * nb, s.check(val, 2 * nb, 4));
431         s.remove();
432     }
433
434     /**
435      * Basic test: send more messages on a topic in a transaction committed
436      */

437     public void testManySendOnDestTopic() throws Exception JavaDoc {
438
439         Sender1_1 s = getHome1().create();
440         int val = 2061;
441         int nb = 100;
442         s.sendOnDestination("JunitTopic1", val, nb);
443         assertEquals(2*nb, s.check(val, 2*nb, 80));
444         s.remove();
445     }
446
447     /**
448      * Basic test: Send more messages on a topic
449      * 2 MDB are reading the topic.
450      * tx.
451      */

452     public void testManySendOnDestTopicTx() throws Exception JavaDoc {
453         Sender1_1 s = getHome1().create();
454         int val = 2111;
455         int nb = 100;
456         s.sendOnDestinationTx("JunitTopic1", val, nb);
457         assertEquals(2 * nb, s.check(val, 2 * nb, 80));
458         s.remove();
459     }
460
461     // --------------------------------------------------------
462
// Basic Tests on Queues (JMS1.1)
463
// --------------------------------------------------------
464

465     /**
466      * Basic test: Send 1 message on a queue
467      * No tx, MDB transacted.
468      */

469     public void testBasicSendOnDestQueue1() throws Exception JavaDoc {
470
471         Sender1_1 s = getHome1().create();
472         int val = 100;
473         s.sendOnDestination("JunitQueue1", val, 1);
474         assertEquals(1, s.check(val, 1, 4));
475         s.remove();
476     }
477
478     /**
479      * Basic test: Send n messages on a queue
480      * No tx, MDB transacted.
481      */

482     public void testMultipleSendOnDestQueue1() throws Exception JavaDoc {
483         Sender1_1 s = getHome1().create();
484         int val = 100;
485         int nb = 20;
486         s.sendOnDestination("JunitQueue1", val, nb);
487         assertEquals(nb, s.check(val, nb, 8));
488         s.remove();
489     }
490
491     /**
492      * Basic test: Send 1 message on a queue
493      * tx, MDB transacted.
494      */

495     public void testBasicSendOnDestQueue1Tx() throws Exception JavaDoc {
496         Sender1_1 s = getHome1().create();
497         int val = 101;
498         s.sendOnDestinationTx("JunitQueue1", val, 1);
499         assertEquals(1, s.check(val, 1, 4));
500         s.remove();
501     }
502
503     /**
504      * Basic test: Send nb messages on a queue
505      * tx, MDB transacted.
506      */

507     public void testMultipleSendOnDestQueue1Tx() throws Exception JavaDoc {
508         Sender1_1 s = getHome1().create();
509         int val = 121;
510         int nb = 20;
511         s.sendOnDestinationTx("JunitQueue1", val, nb);
512         assertEquals(nb, s.check(val, nb, 10));
513         s.remove();
514     }
515
516     /**
517      * Basic test: Send 1 message on a queue
518      * No tx, MDB not transacted.
519      */

520     public void testBasicSendOnDestQueue2() throws Exception JavaDoc {
521         Sender1_1 s = getHome1().create();
522         int val = 102;
523         s.sendOnDestination("JunitQueue2", val, 1);
524         assertEquals(1, s.check(val, 1, 4));
525         s.remove();
526     }
527
528     /**
529      * Basic test: Send 1 message on a queue
530      * tx, MDB not transacted.
531      */

532     public void testBasicSendOnDestQueue2Tx() throws Exception JavaDoc {
533         Sender1_1 s = getHome1().create();
534         int val = 103;
535         s.sendOnDestinationTx("JunitQueue2", val, 1);
536         assertEquals(1, s.check(val, 1, 4));
537         s.remove();
538     }
539
540
541     /**
542      * Basic test: send a message on a queue in a transaction rolled back
543      * MDB not transacted.
544      */

545     public void testRollbackSendOnDestQueue2() throws Exception JavaDoc {
546         Sender1_1 s = getHome1().create();
547         int val = 105;
548         utx.begin();
549         s.sendOnDestination("JunitQueue2", val, 1);
550         utx.rollback();
551         assertEquals(0, s.check(val, 1, 4));
552         s.remove();
553     }
554
555
556     /**
557      * Basic test: send a message on a queue in a transaction committed
558      * MDB transacted.
559      */

560     public void testCommitSendOnDestQueue1() throws Exception JavaDoc {
561         Sender1_1 s = getHome1().create();
562         int val = 106;
563         utx.begin();
564         s.sendOnDestination("JunitQueue1", val, 1);
565         utx.commit();
566         assertEquals(1, s.check(val, 1, 4));
567         s.remove();
568     }
569
570
571     /**
572      * Basic test: send a message on a queue in a transaction committed
573      * MDB not transacted.
574      */

575     public void testCommitSendOnDestQueue2() throws Exception JavaDoc {
576         Sender1_1 s = getHome1().create();
577         int val = 107;
578         utx.begin();
579         s.sendOnDestination("JunitQueue2", val, 1);
580         utx.commit();
581         assertEquals(1, s.check(val, 1, 4));
582         s.remove();
583     }
584
585
586
587     /**
588      * Run all the tests
589      */

590     public static Test suite() {
591         return new TestSuite(F_BasicMDB.class);
592     }
593
594     public static void main (String JavaDoc args[]) {
595         String JavaDoc testtorun = null;
596         // Get args
597
for (int argn = 0; argn < args.length; argn++) {
598             String JavaDoc s_arg = args[argn];
599             Integer JavaDoc i_arg;
600             if (s_arg.equals("-n")) {
601                 testtorun = args[++argn];
602             }
603         }
604         if (testtorun == null) {
605             junit.textui.TestRunner.run(suite());
606         } else {
607             junit.textui.TestRunner.run(new F_BasicMDB(testtorun));
608         }
609     }
610 }
611
Popular Tags