KickJava   Java API By Example, From Geeks To Geeks.

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


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:
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
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34 import org.objectweb.jonas.jtests.beans.message.Sender;
35 import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
36 import org.objectweb.jonas.jtests.beans.message.SenderHome;
37 import org.objectweb.jonas.jtests.util.JTestCase;
38
39 public class G_BasicMDB extends JTestCase {
40
41     private static String JavaDoc BEAN_HOME = "messageSenderSFHome";
42     private static String JavaDoc BEAN1_1_HOME = "messageSender1_1SFHome";
43     protected static SenderHome home = null;
44     protected static Sender1_1Home home1 = null;
45
46     public G_BasicMDB(String JavaDoc name) {
47         super(name);
48     }
49   
50    
51     public void testEmpty() throws Exception JavaDoc {
52     }
53
54     public SenderHome getHome() {
55         if (home == null) {
56             try {
57                 home = (SenderHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), SenderHome.class);
58             } catch (NamingException JavaDoc e) {
59                 fail("Cannot get bean home");
60             }
61         }
62         return home;
63     }
64
65     public Sender1_1Home getHome1() {
66         if (home1 == null) {
67             try {
68                 home1 = (Sender1_1Home) PortableRemoteObject.narrow(ictx.lookup(BEAN1_1_HOME), Sender1_1Home.class);
69             } catch (NamingException JavaDoc e) {
70                 fail("Cannot get bean home1");
71             }
72         }
73         return home1;
74     }
75
76     /**
77      * init environment:
78      * - load beans
79      * - create/init database for entities.
80      */

81     protected void setUp() {
82         super.setUp();
83         useBeans("message", true);
84     }
85
86     // --------------------------------------------------------
87
// Basic Tests on Topics
88
// --------------------------------------------------------
89

90     /**
91      * Basic test: Send 1 message on a topic
92      * 2 MDB are reading the topic.
93      * No tx.
94      */

95     public void testCreateSendOnTopicRemove() throws Exception JavaDoc {
96         Sender s = getHome().create();
97         int val = 200;
98         s.sendOnTopic("JunitTopic1", val, 1);
99         assertEquals(2, s.check(val, 2, 4));
100         s.remove();
101         
102     }
103
104  
105     /**
106      * Basic test: send a message on a topic in a transaction committed
107      */

108     public void testCreateBeginSendOnTopicCommitRemove() throws Exception JavaDoc {
109
110         Sender s = getHome().create();
111         int val = 206;
112         utx.begin();
113         s.sendOnTopic("JunitTopic1", val, 1);
114         utx.commit();
115         assertEquals(2, s.check(val, 2, 4));
116         s.remove();
117       
118     }
119
120
121     
122     // --------------------------------------------------------
123
// Basic Tests on Queues
124
// --------------------------------------------------------
125

126     /**
127      * Basic test: Send 1 message on a queue
128      * No tx, MDB transacted.
129      */

130     public void testCreateSendOnQueueRemove() throws Exception JavaDoc {
131
132         Sender s = getHome().create();
133         int val = 100;
134         s.sendOnQueue("JunitQueue1", val, 1);
135         assertEquals(1, s.check(val, 1, 4));
136         s.remove();
137        
138     }
139
140   
141
142
143     /**
144      * Run all the tests
145      */

146     public static Test suite() {
147         return new TestSuite(G_BasicMDB.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 G_BasicMDB(testtorun));
164         }
165     }
166 }
167
Popular Tags