001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_BasicMDB.java 6611 2005-04-22 07:43:05Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jms;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030: import junit.framework.Test;
031: import junit.framework.TestSuite;
032: import org.objectweb.jonas.jtests.util.JTestCase;
033: import org.objectweb.jonas.jtests.beans.message.Sender;
034: import org.objectweb.jonas.jtests.beans.message.SenderHome;
035: import org.objectweb.jonas.jtests.beans.message.Sender1_1;
036: import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
037:
038: public class F_BasicMDB extends JTestCase {
039:
040: private static String BEAN_HOME = "messageSenderSFHome";
041: private static String BEAN1_1_HOME = "messageSender1_1SFHome";
042: protected static SenderHome home = null;
043: protected static Sender1_1Home home1 = null;
044:
045: public F_BasicMDB(String name) {
046: super (name);
047: }
048:
049: public SenderHome getHome() {
050: if (home == null) {
051: try {
052: home = (SenderHome) PortableRemoteObject.narrow(ictx
053: .lookup(BEAN_HOME), SenderHome.class);
054: } catch (NamingException e) {
055: fail("Cannot get bean home");
056: }
057: }
058: return home;
059: }
060:
061: public Sender1_1Home getHome1() {
062: if (home1 == null) {
063: try {
064: home1 = (Sender1_1Home) PortableRemoteObject.narrow(
065: ictx.lookup(BEAN1_1_HOME), Sender1_1Home.class);
066: } catch (NamingException e) {
067: fail("Cannot get bean home1");
068: }
069: }
070: return home1;
071: }
072:
073: /**
074: * init environment:
075: * - load beans
076: * - create/init database for entities.
077: */
078: protected void setUp() {
079: super .setUp();
080: useBeans("message", true);
081: }
082:
083: // --------------------------------------------------------
084: // Basic Tests on Topics
085: // --------------------------------------------------------
086:
087: /**
088: * Basic test: Send 1 message on a topic
089: * 2 MDB are reading the topic.
090: * No tx.
091: */
092: public void testBasicSendOnTopic1() throws Exception {
093: Sender s = getHome().create();
094: int val = 200;
095: s.sendOnTopic("JunitTopic1", val, 1);
096: assertEquals(2, s.check(val, 2, 4));
097: s.remove();
098: }
099:
100: /**
101: * Basic test: Send 1 message on a topic Durable
102: * 2 MDB are reading the topic.
103: * No tx.
104: */
105: public void testBasicSendOnTopic2() throws Exception {
106: Sender s = getHome().create();
107: int val = 200;
108: s.sendOnTopic("JunitTopic2", val, 1);
109: assertEquals(2, s.check(val, 2, 4));
110: s.remove();
111: }
112:
113: /**
114: * Basic test: Send nb messages on a topic
115: * 2 MDB are reading the topic.
116: * No tx.
117: */
118: public void testMultipleSendOnTopic1() throws Exception {
119: Sender s = getHome().create();
120: int val = 210;
121: int nb = 10;
122: s.sendOnTopic("JunitTopic1", val, nb);
123: assertEquals(nb * 2, s.check(val, nb * 2, 8));
124: s.remove();
125: }
126:
127: /**
128: * Basic test: Send 1 message on a topic
129: * 2 MDB are reading the topic.
130: * tx.
131: */
132: public void testBasicSendOnTopic1Tx() throws Exception {
133: Sender s = getHome().create();
134: int val = 201;
135: s.sendOnTopicTx("JunitTopic1", val, 1);
136: assertEquals(2, s.check(val, 2, 4));
137: s.remove();
138: }
139:
140: /**
141: * Basic test: Send n messages on a topic
142: * 2 MDB are reading the topic.
143: * tx.
144: */
145: public void testMutipleSendOnTopic1Tx() throws Exception {
146: Sender s = getHome().create();
147: int val = 211;
148: int nb = 10;
149: s.sendOnTopicTx("JunitTopic1", val, nb);
150: assertEquals(2 * nb, s.check(val, 2 * nb, 4));
151: s.remove();
152: }
153:
154: /**
155: * Basic test: send a message on a topic in a transaction committed
156: */
157: public void testCommitSendOnTopic1() throws Exception {
158:
159: Sender s = getHome().create();
160: int val = 206;
161: utx.begin();
162: s.sendOnTopic("JunitTopic1", val, 1);
163: utx.commit();
164: assertEquals(2, s.check(val, 2, 4));
165: s.remove();
166: }
167:
168: /**
169: * Basic test: send n message on a topic in a transaction committed
170: */
171: public void testNCommitSendOnTopic1() throws Exception {
172:
173: Sender s = getHome().create();
174: int val = 206;
175: int nb = 12;
176: utx.begin();
177: s.sendOnTopic("JunitTopic1", val, nb);
178: utx.commit();
179: assertEquals(2 * nb, s.check(val, 2 * nb, 4));
180: s.remove();
181: }
182:
183: /**
184: * Basic test: send more messages on a topic in a transaction committed
185: */
186: public void testManySendOnTopic() throws Exception {
187:
188: Sender s = getHome().create();
189: int val = 2060;
190: int nb = 120;
191: s.sendOnTopic("JunitTopic1", val, nb);
192: assertEquals(2 * nb, s.check(val, 2 * nb, 80));
193: s.remove();
194: }
195:
196: /**
197: * Basic test: Send more messages on a topic
198: * 2 MDB are reading the topic.
199: * tx.
200: */
201: public void testManySendOnTopicTx() throws Exception {
202: Sender s = getHome().create();
203: int val = 2110;
204: int nb = 100;
205: s.sendOnTopicTx("JunitTopic1", val, nb);
206: assertEquals(2 * nb, s.check(val, 2 * nb, 80));
207: s.remove();
208: }
209:
210: // --------------------------------------------------------
211: // Basic Tests on Queues
212: // --------------------------------------------------------
213:
214: /**
215: * Basic test: Send 1 message on a queue
216: * No tx, MDB transacted.
217: */
218: public void testBasicSendOnQueue1() throws Exception {
219:
220: Sender s = getHome().create();
221: int val = 100;
222: s.sendOnQueue("JunitQueue1", val, 1);
223: assertEquals(1, s.check(val, 1, 4));
224: s.remove();
225: }
226:
227: /**
228: * Basic test: Send n messages on a queue
229: * No tx, MDB transacted.
230: */
231: public void testMultipleSendOnQueue1() throws Exception {
232: Sender s = getHome().create();
233: int val = 100;
234: int nb = 5;
235: s.sendOnQueue("JunitQueue1", val, nb);
236: assertEquals(nb, s.check(val, nb, 8));
237: s.remove();
238: }
239:
240: /**
241: * Basic test: Send 1 message on a queue
242: * tx, MDB transacted.
243: */
244: public void testBasicSendOnQueue1Tx() throws Exception {
245: Sender s = getHome().create();
246: int val = 101;
247: s.sendOnQueueTx("JunitQueue1", val, 1);
248: assertEquals(1, s.check(val, 1, 4));
249: s.remove();
250: }
251:
252: /**
253: * Basic test: Send nb messages on a queue
254: * tx, MDB transacted.
255: */
256: public void testMultipleSendOnQueue1Tx() throws Exception {
257: Sender s = getHome().create();
258: int val = 121;
259: int nb = 20;
260: s.sendOnQueueTx("JunitQueue1", val, nb);
261: assertEquals(nb, s.check(val, nb, 10));
262: s.remove();
263: }
264:
265: /**
266: * Basic test: Send 1 message on a queue
267: * No tx, MDB not transacted.
268: */
269: public void testBasicSendOnQueue2() throws Exception {
270: Sender s = getHome().create();
271: int val = 102;
272: s.sendOnQueue("JunitQueue2", val, 1);
273: assertEquals(1, s.check(val, 1, 4));
274: s.remove();
275: }
276:
277: /**
278: * Basic test: Send 1 message on a queue
279: * tx, MDB not transacted.
280: */
281: public void testBasicSendOnQueue2Tx() throws Exception {
282: Sender s = getHome().create();
283: int val = 103;
284: s.sendOnQueueTx("JunitQueue2", val, 1);
285: assertEquals(1, s.check(val, 1, 4));
286: s.remove();
287: }
288:
289: /**
290: * Basic test: send a message on a queue in a transaction rolled back
291: * MDB not transacted.
292: */
293: public void testRollbackSendOnQueue2() throws Exception {
294: Sender s = getHome().create();
295: int val = 105;
296: utx.begin();
297: s.sendOnQueue("JunitQueue2", val, 1);
298: utx.rollback();
299: assertEquals(0, s.check(val, 1, 4));
300: s.remove();
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 {
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: * Basic test: send a message on a queue in a transaction committed
319: * MDB not transacted.
320: */
321: public void testCommitSendOnQueue2() throws Exception {
322: Sender s = getHome().create();
323: int val = 107;
324: utx.begin();
325: s.sendOnQueue("JunitQueue2", val, 1);
326: utx.commit();
327: assertEquals(1, s.check(val, 1, 4));
328: s.remove();
329: }
330:
331: // --------------------------------------------------------
332: // Basic Tests on Topics (JMS1.1)
333: // --------------------------------------------------------
334:
335: /**
336: * Basic test: Send 1 message on a topic
337: * 2 MDB are reading the topic.
338: * No tx.
339: */
340: public void testBasicSendOnDestTopic1() throws Exception {
341: Sender1_1 s = getHome1().create();
342: int val = 200;
343: s.sendOnDestination("JunitTopic1", val, 1);
344: assertEquals(2, s.check(val, 2, 4));
345: s.remove();
346: }
347:
348: /**
349: * Basic test: Send 1 message on a topic Durable
350: * 2 MDB are reading the topic.
351: * No tx.
352: */
353: public void testBasicSendOnDestTopic2() throws Exception {
354: Sender1_1 s = getHome1().create();
355: int val = 200;
356: s.sendOnDestination("JunitTopic2", val, 1);
357: assertEquals(2, s.check(val, 2, 4));
358: s.remove();
359: }
360:
361: /**
362: * Basic test: Send nb messages on a topic
363: * 2 MDB are reading the topic.
364: * No tx.
365: */
366: public void testMultipleSendOnDestTopic1() throws Exception {
367: Sender1_1 s = getHome1().create();
368: int val = 210;
369: int nb = 10;
370: s.sendOnDestination("JunitTopic1", val, nb);
371: assertEquals(nb * 2, s.check(val, nb * 2, 8));
372: s.remove();
373: }
374:
375: /**
376: * Basic test: Send 1 message on a topic
377: * 2 MDB are reading the topic.
378: * tx.
379: */
380: public void testBasicSendOnDestTopic1Tx() throws Exception {
381: Sender1_1 s = getHome1().create();
382: int val = 201;
383: s.sendOnDestinationTx("JunitTopic1", val, 1);
384: assertEquals(2, s.check(val, 2, 4));
385: s.remove();
386: }
387:
388: /**
389: * Basic test: Send n messages on a topic
390: * 2 MDB are reading the topic.
391: * tx.
392: */
393: public void testMutipleSendOnDestTopic1Tx() throws Exception {
394: Sender1_1 s = getHome1().create();
395: int val = 211;
396: int nb = 10;
397: s.sendOnDestinationTx("JunitTopic1", val, nb);
398: assertEquals(2 * nb, s.check(val, 2 * nb, 4));
399: s.remove();
400: }
401:
402: /**
403: * Basic test: send a message on a topic in a transaction committed
404: */
405: public void testCommitSendOnDestTopic1() throws Exception {
406:
407: Sender1_1 s = getHome1().create();
408: int val = 206;
409: utx.begin();
410: s.sendOnDestination("JunitTopic1", val, 1);
411: utx.commit();
412: assertEquals(2, s.check(val, 2, 4));
413: s.remove();
414: }
415:
416: /**
417: * Basic test: send n message on a topic in a transaction committed
418: */
419: public void testNCommitSendOnDestTopic1() throws Exception {
420:
421: Sender1_1 s = getHome1().create();
422: int val = 206;
423: int nb = 12;
424: utx.begin();
425: s.sendOnDestination("JunitTopic1", val, nb);
426: utx.commit();
427: assertEquals(2 * nb, s.check(val, 2 * nb, 4));
428: s.remove();
429: }
430:
431: /**
432: * Basic test: send more messages on a topic in a transaction committed
433: */
434: public void testManySendOnDestTopic() throws Exception {
435:
436: Sender1_1 s = getHome1().create();
437: int val = 2061;
438: int nb = 100;
439: s.sendOnDestination("JunitTopic1", val, nb);
440: assertEquals(2 * nb, s.check(val, 2 * nb, 80));
441: s.remove();
442: }
443:
444: /**
445: * Basic test: Send more messages on a topic
446: * 2 MDB are reading the topic.
447: * tx.
448: */
449: public void testManySendOnDestTopicTx() throws Exception {
450: Sender1_1 s = getHome1().create();
451: int val = 2111;
452: int nb = 100;
453: s.sendOnDestinationTx("JunitTopic1", val, nb);
454: assertEquals(2 * nb, s.check(val, 2 * nb, 80));
455: s.remove();
456: }
457:
458: // --------------------------------------------------------
459: // Basic Tests on Queues (JMS1.1)
460: // --------------------------------------------------------
461:
462: /**
463: * Basic test: Send 1 message on a queue
464: * No tx, MDB transacted.
465: */
466: public void testBasicSendOnDestQueue1() throws Exception {
467:
468: Sender1_1 s = getHome1().create();
469: int val = 100;
470: s.sendOnDestination("JunitQueue1", val, 1);
471: assertEquals(1, s.check(val, 1, 4));
472: s.remove();
473: }
474:
475: /**
476: * Basic test: Send n messages on a queue
477: * No tx, MDB transacted.
478: */
479: public void testMultipleSendOnDestQueue1() throws Exception {
480: Sender1_1 s = getHome1().create();
481: int val = 100;
482: int nb = 20;
483: s.sendOnDestination("JunitQueue1", val, nb);
484: assertEquals(nb, s.check(val, nb, 8));
485: s.remove();
486: }
487:
488: /**
489: * Basic test: Send 1 message on a queue
490: * tx, MDB transacted.
491: */
492: public void testBasicSendOnDestQueue1Tx() throws Exception {
493: Sender1_1 s = getHome1().create();
494: int val = 101;
495: s.sendOnDestinationTx("JunitQueue1", val, 1);
496: assertEquals(1, s.check(val, 1, 4));
497: s.remove();
498: }
499:
500: /**
501: * Basic test: Send nb messages on a queue
502: * tx, MDB transacted.
503: */
504: public void testMultipleSendOnDestQueue1Tx() throws Exception {
505: Sender1_1 s = getHome1().create();
506: int val = 121;
507: int nb = 20;
508: s.sendOnDestinationTx("JunitQueue1", val, nb);
509: assertEquals(nb, s.check(val, nb, 10));
510: s.remove();
511: }
512:
513: /**
514: * Basic test: Send 1 message on a queue
515: * No tx, MDB not transacted.
516: */
517: public void testBasicSendOnDestQueue2() throws Exception {
518: Sender1_1 s = getHome1().create();
519: int val = 102;
520: s.sendOnDestination("JunitQueue2", val, 1);
521: assertEquals(1, s.check(val, 1, 4));
522: s.remove();
523: }
524:
525: /**
526: * Basic test: Send 1 message on a queue
527: * tx, MDB not transacted.
528: */
529: public void testBasicSendOnDestQueue2Tx() throws Exception {
530: Sender1_1 s = getHome1().create();
531: int val = 103;
532: s.sendOnDestinationTx("JunitQueue2", val, 1);
533: assertEquals(1, s.check(val, 1, 4));
534: s.remove();
535: }
536:
537: /**
538: * Basic test: send a message on a queue in a transaction rolled back
539: * MDB not transacted.
540: */
541: public void testRollbackSendOnDestQueue2() throws Exception {
542: Sender1_1 s = getHome1().create();
543: int val = 105;
544: utx.begin();
545: s.sendOnDestination("JunitQueue2", val, 1);
546: utx.rollback();
547: assertEquals(0, s.check(val, 1, 4));
548: s.remove();
549: }
550:
551: /**
552: * Basic test: send a message on a queue in a transaction committed
553: * MDB transacted.
554: */
555: public void testCommitSendOnDestQueue1() throws Exception {
556: Sender1_1 s = getHome1().create();
557: int val = 106;
558: utx.begin();
559: s.sendOnDestination("JunitQueue1", val, 1);
560: utx.commit();
561: assertEquals(1, s.check(val, 1, 4));
562: s.remove();
563: }
564:
565: /**
566: * Basic test: send a message on a queue in a transaction committed
567: * MDB not transacted.
568: */
569: public void testCommitSendOnDestQueue2() throws Exception {
570: Sender1_1 s = getHome1().create();
571: int val = 107;
572: utx.begin();
573: s.sendOnDestination("JunitQueue2", val, 1);
574: utx.commit();
575: assertEquals(1, s.check(val, 1, 4));
576: s.remove();
577: }
578:
579: /**
580: * Run all the tests
581: */
582: public static Test suite() {
583: return new TestSuite(F_BasicMDB.class);
584: }
585:
586: public static void main(String args[]) {
587: String testtorun = null;
588: // Get args
589: for (int argn = 0; argn < args.length; argn++) {
590: String s_arg = args[argn];
591: Integer i_arg;
592: if (s_arg.equals("-n")) {
593: testtorun = args[++argn];
594: }
595: }
596: if (testtorun == null) {
597: junit.textui.TestRunner.run(suite());
598: } else {
599: junit.textui.TestRunner.run(new F_BasicMDB(testtorun));
600: }
601: }
602: }
|