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:
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jms;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.message.Sender;
035: import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
036: import org.objectweb.jonas.jtests.beans.message.SenderHome;
037: import org.objectweb.jonas.jtests.util.JTestCase;
038:
039: public class G_BasicMDB extends JTestCase {
040:
041: private static String BEAN_HOME = "messageSenderSFHome";
042: private static String BEAN1_1_HOME = "messageSender1_1SFHome";
043: protected static SenderHome home = null;
044: protected static Sender1_1Home home1 = null;
045:
046: public G_BasicMDB(String name) {
047: super (name);
048: }
049:
050: public void testEmpty() throws Exception {
051: }
052:
053: public SenderHome getHome() {
054: if (home == null) {
055: try {
056: home = (SenderHome) PortableRemoteObject.narrow(ictx
057: .lookup(BEAN_HOME), SenderHome.class);
058: } catch (NamingException e) {
059: fail("Cannot get bean home");
060: }
061: }
062: return home;
063: }
064:
065: public Sender1_1Home getHome1() {
066: if (home1 == null) {
067: try {
068: home1 = (Sender1_1Home) PortableRemoteObject.narrow(
069: ictx.lookup(BEAN1_1_HOME), Sender1_1Home.class);
070: } catch (NamingException e) {
071: fail("Cannot get bean home1");
072: }
073: }
074: return home1;
075: }
076:
077: /**
078: * init environment:
079: * - load beans
080: * - create/init database for entities.
081: */
082: protected void setUp() {
083: super .setUp();
084: useBeans("message", true);
085: }
086:
087: // --------------------------------------------------------
088: // Basic Tests on Topics
089: // --------------------------------------------------------
090:
091: /**
092: * Basic test: Send 1 message on a topic
093: * 2 MDB are reading the topic.
094: * No tx.
095: */
096: public void testCreateSendOnTopicRemove() throws Exception {
097: Sender s = getHome().create();
098: int val = 200;
099: s.sendOnTopic("JunitTopic1", val, 1);
100: assertEquals(2, s.check(val, 2, 4));
101: s.remove();
102:
103: }
104:
105: /**
106: * Basic test: send a message on a topic in a transaction committed
107: */
108: public void testCreateBeginSendOnTopicCommitRemove()
109: throws Exception {
110:
111: Sender s = getHome().create();
112: int val = 206;
113: utx.begin();
114: s.sendOnTopic("JunitTopic1", val, 1);
115: utx.commit();
116: assertEquals(2, s.check(val, 2, 4));
117: s.remove();
118:
119: }
120:
121: // --------------------------------------------------------
122: // Basic Tests on Queues
123: // --------------------------------------------------------
124:
125: /**
126: * Basic test: Send 1 message on a queue
127: * No tx, MDB transacted.
128: */
129: public void testCreateSendOnQueueRemove() throws Exception {
130:
131: Sender s = getHome().create();
132: int val = 100;
133: s.sendOnQueue("JunitQueue1", val, 1);
134: assertEquals(1, s.check(val, 1, 4));
135: s.remove();
136:
137: }
138:
139: /**
140: * Run all the tests
141: */
142: public static Test suite() {
143: return new TestSuite(G_BasicMDB.class);
144: }
145:
146: public static void main(String args[]) {
147: String testtorun = null;
148: // Get args
149: for (int argn = 0; argn < args.length; argn++) {
150: String s_arg = args[argn];
151: Integer i_arg;
152: if (s_arg.equals("-n")) {
153: testtorun = args[++argn];
154: }
155: }
156: if (testtorun == null) {
157: junit.textui.TestRunner.run(suite());
158: } else {
159: junit.textui.TestRunner.run(new G_BasicMDB(testtorun));
160: }
161: }
162: }
|