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_RollbackMDB.java 1971 2003-04-17 13:40:28Z coqp $
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_RollbackMDB 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_RollbackMDB(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: // Tests Rollback
085: // --------------------------------------------------------
086:
087: /**
088: * send a message on a topic in a transaction rolled back
089: */
090: public void testRollbackSendOnTopic1() throws Exception {
091: Sender s = getHome().create();
092: int val = 204;
093: utx.begin();
094: s.sendOnTopic("JunitTopic1", val, 1);
095: utx.rollback();
096: assertEquals(0, s.check(val, 2, 4));
097: s.remove();
098: }
099:
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 {
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 {
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 {
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 {
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 {
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 args[]) {
180: String testtorun = null;
181: // Get args
182: for (int argn = 0; argn < args.length; argn++) {
183: String s_arg = args[argn];
184: Integer 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: }
|