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_TestsWithBMT.java 5152 2004-07-20 14:57:00Z tachker $
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_2;
036: import org.objectweb.jonas.jtests.beans.message.Sender1_2Home;
037:
038: public class F_TestsWithBMT extends JTestCase {
039:
040: private static String BEAN_HOME = "messageSender1_2SFHome";
041:
042: protected static Sender1_2Home home = null;
043:
044: public F_TestsWithBMT(String name) {
045: super (name);
046: }
047:
048: public Sender1_2Home getHome() {
049: if (home == null) {
050: try {
051: home = (Sender1_2Home) PortableRemoteObject.narrow(ictx
052: .lookup(BEAN_HOME), Sender1_2Home.class);
053: } catch (NamingException e) {
054: fail("Cannot get bean home1");
055: }
056: }
057: return home;
058: }
059:
060: /**
061: * init environment:
062: * - load beans
063: * - create/init database for entities.
064: */
065: protected void setUp() {
066: super .setUp();
067: useBeans("message", true);
068: }
069:
070: // --------------------------------------------------------
071: // Basic Tests on Topics
072: // --------------------------------------------------------
073:
074: /**
075: * test: Send 1 message on a topic inside a transaction that commits
076: * the message must be received
077: * transaction is demarcated explicitly in a BMT session bean
078: * the begin transaction occurs before the create_session
079: * 2 MDB are reading the topic.
080: *
081: */
082: public void testSendOnTopic1_1() throws Exception {
083: Sender1_2 s = getHome().create();
084: int val = 200;
085: s.sendOnDestinationWithTxBeforeSession("JunitTopic1", val, 1,
086: true);
087: assertEquals(2, s.check(val, 2, 4));
088: s.remove();
089: }
090:
091: /**
092: * test: Send 1 message on a topic inside a transaction that rollback
093: * no message must be received
094: * transaction is demarcated explicitly in a BMT session bean
095: * the begin transaction occurs before the create_session
096: * 2 MDB are reading the topic.
097: *
098: */
099: public void testSendOnTopic1_2() throws Exception {
100: Sender1_2 s = getHome().create();
101: int val = 200;
102: s.sendOnDestinationWithTxBeforeSession("JunitTopic1", val, 1,
103: false);
104: assertEquals(0, s.check(val, 2, 4));
105: s.remove();
106: }
107:
108: /**
109: * test: Send 1 message on a topic inside a transaction that commits
110: * the message must be received
111: * transaction is demarcated explicitly in a BMT session bean
112: * the begin transaction occurs after the create_session
113: * 2 MDB are reading the topic.
114: *
115: */
116: public void testSendOnTopic1_3() throws Exception {
117: Sender1_2 s = getHome().create();
118: int val = 200;
119: s.sendOnDestinationWithTxAfterSession("JunitTopic1", val, 1,
120: true);
121: assertEquals(2, s.check(val, 2, 4));
122: s.remove();
123: }
124:
125: /**
126: * test: Send 1 message on a topic inside a transaction that roll back
127: * no message must be received
128: * transaction is demarcated explicitly in a BMT session bean
129: * the begin transaction occurs after the create_session
130: * 2 MDB are reading the topic.
131: *
132: * reproduces the bug #300587
133: */
134: public void testSendOnTopic1_4() throws Exception {
135: Sender1_2 s = getHome().create();
136: int val = 200;
137: s.sendOnDestinationWithTxAfterSession("JunitTopic1", val, 1,
138: false);
139: assertEquals(0, s.check(val, 2, 4));
140: s.remove();
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 args[]) {
151: String testtorun = null;
152: // Get args
153: for (int argn = 0; argn < args.length; argn++) {
154: String s_arg = args[argn];
155: Integer 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: }
|