KickJava   Java API By Example, From Geeks To Geeks.

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


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_RollbackMDB.java,v 1.4 2003/04/17 13:40:27 coqp 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_RollbackMDB 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
46     public F_RollbackMDB(String JavaDoc name) {
47     super(name);
48     }
49
50
51     public SenderHome getHome() {
52     if (home == null) {
53         try {
54         home = (SenderHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), SenderHome.class);
55         } catch (NamingException JavaDoc e) {
56         fail("Cannot get bean home");
57         }
58     }
59     return home;
60     }
61
62     public Sender1_1Home getHome1() {
63     if (home1 == null) {
64         try {
65         home1 = (Sender1_1Home) PortableRemoteObject.narrow(ictx.lookup(BEAN1_1_HOME), Sender1_1Home.class);
66         } catch (NamingException JavaDoc e) {
67         fail("Cannot get bean home1");
68         }
69     }
70     return home1;
71     }
72
73     /**
74      * init environment:
75      * - load beans
76      * - create/init database for entities.
77      */

78     protected void setUp() {
79     super.setUp();
80     useBeans("message", true);
81     }
82
83     // --------------------------------------------------------
84
// Tests Rollback
85
// --------------------------------------------------------
86

87     /**
88      * send a message on a topic in a transaction rolled back
89      */

90     public void testRollbackSendOnTopic1() throws Exception JavaDoc {
91     Sender s = getHome().create();
92     int val = 204;
93     utx.begin();
94     s.sendOnTopic("JunitTopic1", val, 1);
95     utx.rollback();
96     assertEquals(0, s.check(val, 2, 4));
97     s.remove();
98     }
99
100     /**
101      * send a message on a topic in a transaction rolled back
102      * via Sender1_1SF and JMS1.1 interfaces
103      */

104     public void testRollbackSendOnDestTopic1() throws Exception JavaDoc {
105     Sender1_1 s = getHome1().create();
106     int val = 204;
107     utx.begin();
108     s.sendOnDestination("JunitTopic1", val, 1);
109     utx.rollback();
110     assertEquals(0, s.check(val, 2, 4));
111     s.remove();
112     }
113
114     /**
115      * send a message on a queue in a transaction rolled back
116      * MDB transacted.
117      */

118     public void testRollbackSendOnQueue1() throws Exception JavaDoc {
119     Sender s = getHome().create();
120     int val = 104;
121     utx.begin();
122     s.sendOnQueue("JunitQueue1", val, 1);
123     utx.rollback();
124     assertEquals(0, s.check(val, 1, 4));
125     s.remove();
126     }
127
128     /**
129      * send a message on a queue in a transaction rolled back
130      * MDB transacted.
131      * via Sender1_1SF and JMS1.1 interfaces
132      */

133     public void testRollbackSendOnDestQueue1() throws Exception JavaDoc {
134     Sender1_1 s = getHome1().create();
135     int val = 104;
136     utx.begin();
137     s.sendOnDestination("JunitQueue1", val, 1);
138     utx.rollback();
139     assertEquals(0, s.check(val, 1, 4));
140     s.remove();
141     }
142
143     /**
144      * Test that it's possible to set rollback only in a message driven
145      * 2 MDB are listening queue3, but 1 of them rollback all messages.
146      * So, we should receive all messages by the commiting MDB.
147      */

148     public void testRollbackOnlyOnQueue3() throws Exception JavaDoc {
149     Sender s = getHome().create();
150     int val = 114;
151     int nb = 25;
152     s.sendOnQueue("JunitQueue3", val, nb);
153     assertEquals(nb, s.check(val, nb, 10));
154     s.remove();
155     }
156
157     /**
158      * Test that it's possible to set rollback only in a message driven
159      * 2 MDB are listening queue3, but 1 of them rollback all messages.
160      * So, we should receive all messages by the commiting MDB.
161      * via Sender1_1SF and JMS1.1 interfaces
162      */

163     public void testRollbackOnlyOnDestQueue3() throws Exception JavaDoc {
164     Sender1_1 s = getHome1().create();
165     int val = 114;
166     int nb = 25;
167     s.sendOnDestination("JunitQueue3", val, nb);
168     assertEquals(nb, s.check(val, nb, 10));
169     s.remove();
170     }
171
172     /**
173      * Run all the tests
174      */

175     public static Test suite() {
176     return new TestSuite(F_RollbackMDB.class);
177     }
178
179     public static void main (String JavaDoc args[]) {
180     String JavaDoc testtorun = null;
181     // Get args
182
for (int argn = 0; argn < args.length; argn++) {
183         String JavaDoc s_arg = args[argn];
184         Integer JavaDoc i_arg;
185         if (s_arg.equals("-n")) {
186         testtorun = args[++argn];
187         }
188     }
189     if (testtorun == null) {
190         junit.textui.TestRunner.run(suite());
191     } else {
192         junit.textui.TestRunner.run(new F_RollbackMDB(testtorun));
193     }
194     }
195 }
196
Popular Tags