KickJava   Java API By Example, From Geeks To Geeks.

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


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_TestsWithBMT.java,v 1.2 2004/07/20 14:57:00 tachker 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_2;
36 import org.objectweb.jonas.jtests.beans.message.Sender1_2Home;
37
38 public class F_TestsWithBMT extends JTestCase {
39
40
41     private static String JavaDoc BEAN_HOME = "messageSender1_2SFHome";
42
43     protected static Sender1_2Home home = null;
44
45     public F_TestsWithBMT(String JavaDoc name) {
46         super(name);
47     }
48
49
50     public Sender1_2Home getHome() {
51         if (home == null) {
52             try {
53                 home = (Sender1_2Home) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), Sender1_2Home.class);
54             } catch (NamingException JavaDoc e) {
55                 fail("Cannot get bean home1");
56             }
57         }
58         return home;
59     }
60
61     /**
62      * init environment:
63      * - load beans
64      * - create/init database for entities.
65      */

66     protected void setUp() {
67         super.setUp();
68         useBeans("message", true);
69     }
70
71     // --------------------------------------------------------
72
// Basic Tests on Topics
73
// --------------------------------------------------------
74

75     /**
76      * test: Send 1 message on a topic inside a transaction that commits
77      * the message must be received
78      * transaction is demarcated explicitly in a BMT session bean
79      * the begin transaction occurs before the create_session
80      * 2 MDB are reading the topic.
81      *
82      */

83     public void testSendOnTopic1_1() throws Exception JavaDoc {
84         Sender1_2 s = getHome().create();
85         int val = 200;
86         s.sendOnDestinationWithTxBeforeSession("JunitTopic1", val, 1, true);
87         assertEquals(2, s.check(val, 2, 4));
88         s.remove();
89     }
90
91     /**
92      * test: Send 1 message on a topic inside a transaction that rollback
93      * no message must be received
94      * transaction is demarcated explicitly in a BMT session bean
95      * the begin transaction occurs before the create_session
96      * 2 MDB are reading the topic.
97      *
98      */

99     public void testSendOnTopic1_2() throws Exception JavaDoc {
100         Sender1_2 s = getHome().create();
101         int val = 200;
102         s.sendOnDestinationWithTxBeforeSession("JunitTopic1", val, 1, false);
103         assertEquals(0, s.check(val, 2, 4));
104         s.remove();
105     }
106
107    /**
108      * test: Send 1 message on a topic inside a transaction that commits
109      * the message must be received
110      * transaction is demarcated explicitly in a BMT session bean
111      * the begin transaction occurs after the create_session
112      * 2 MDB are reading the topic.
113      *
114      */

115     public void testSendOnTopic1_3() throws Exception JavaDoc {
116         Sender1_2 s = getHome().create();
117         int val = 200;
118         s.sendOnDestinationWithTxAfterSession("JunitTopic1", val, 1, true);
119         assertEquals(2, s.check(val, 2, 4));
120         s.remove();
121     }
122
123     /**
124      * test: Send 1 message on a topic inside a transaction that roll back
125      * no message must be received
126      * transaction is demarcated explicitly in a BMT session bean
127      * the begin transaction occurs after the create_session
128      * 2 MDB are reading the topic.
129      *
130      * reproduces the bug #300587
131      */

132     public void testSendOnTopic1_4() throws Exception JavaDoc {
133         Sender1_2 s = getHome().create();
134         int val = 200;
135         s.sendOnDestinationWithTxAfterSession("JunitTopic1", val, 1, false);
136         assertEquals(0, s.check(val, 2, 4));
137         s.remove();
138     }
139
140
141  
142
143     /**
144      * Run all the tests
145      */

146     public static Test suite() {
147         return new TestSuite(F_TestsWithBMT.class);
148     }
149
150     public static void main (String JavaDoc args[]) {
151         String JavaDoc testtorun = null;
152         // Get args
153
for (int argn = 0; argn < args.length; argn++) {
154             String JavaDoc s_arg = args[argn];
155             Integer JavaDoc i_arg;
156             if (s_arg.equals("-n")) {
157                 testtorun = args[++argn];
158             }
159         }
160         if (testtorun == null) {
161             junit.textui.TestRunner.run(suite());
162         } else {
163             junit.textui.TestRunner.run(new F_TestsWithBMT(testtorun));
164         }
165     }
166 }
167
Popular Tags