KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > conform > session > UnifiedSessionTest


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2002 INRIA
4  * Contact: joram-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  * Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.jtests.jms.conform.session;
26
27 import org.objectweb.jtests.jms.framework.*;
28 import junit.framework.*;
29
30 import javax.jms.*;
31
32 /**
33  * Test unified JMS 1.1 sessions.
34  * <br />
35  * See JMS 1.1 specifications
36  *
37  * @author Jeff Mesnil (jmesnil@inrialpes.fr)
38  * @version $Id: UnifiedSessionTest.java,v 1.2 2002/06/20 11:17:02 jmesnil Exp $
39  * @since JMS 1.1
40  */

41 public class UnifiedSessionTest extends UnifiedTestCase {
42     
43     /**
44      * QueueConnection
45      */

46     protected QueueConnection queueConnection;
47
48     /**
49      * QueueSession (non transacted, AUTO_ACKNOWLEDGE)
50      */

51     protected QueueSession queueSession;
52
53     /**
54      * TopicConnection
55      */

56     protected TopicConnection topicConnection;
57
58     /**
59      * TopicSession (non transacted, AUTO_ACKNOWLEDGE)
60      */

61     protected TopicSession topicSession;
62
63     /**
64      * Test that a call to <code>createDurableConnectionConsumer()</code> method
65      * on a <code>QueueConnection</code> throws a
66      * <code>javax.jms.IllegalStateException</code>.
67      * (see JMS 1.1 specs, table 4-1).
68      *
69      * @since JMS 1.1
70      */

71     public void testCreateDurableConnectionConsumerOnQueueConnection() {
72         try {
73             queueConnection.createDurableConnectionConsumer(topic,
74                                                             "subscriptionName",
75                                                             "",
76                                                             (ServerSessionPool)null,
77                                                             1);
78             fail("Should throw a javax.jms.IllegalStateException");
79         } catch (javax.jms.IllegalStateException JavaDoc e) {
80         } catch (JMSException e) {
81             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
82         }
83     }
84
85     /**
86      * Test that a call to <code>createDurableSubscriber()</code> method
87      * on a <code>QueueSession</code> throws a
88      * <code>javax.jms.IllegalStateException</code>.
89      * (see JMS 1.1 specs, table 4-1).
90      *
91      * @since JMS 1.1
92      */

93     public void testCreateDurableSubscriberOnQueueSession() {
94         try {
95             queueSession.createDurableSubscriber(topic,
96                                                  "subscriptionName");
97             fail("Should throw a javax.jms.IllegalStateException");
98         } catch (javax.jms.IllegalStateException JavaDoc e) {
99         } catch (JMSException e) {
100             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
101         }
102     }
103
104     /**
105      * Test that a call to <code>createTemporaryTopic()</code> method
106      * on a <code>QueueSession</code> throws a
107      * <code>javax.jms.IllegalStateException</code>.
108      * (see JMS 1.1 specs, table 4-1).
109      *
110      * @since JMS 1.1
111      */

112     public void testCreateTemporaryTopicOnQueueSession() {
113         try {
114             TemporaryTopic tempTopic = queueSession.createTemporaryTopic();
115             fail("Should throw a javax.jms.IllegalStateException");
116         } catch (javax.jms.IllegalStateException JavaDoc e) {
117         } catch (JMSException e) {
118             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
119         }
120     }
121
122     /**
123      * Test that a call to <code>createTopic()</code> method
124      * on a <code>QueueSession</code> throws a
125      * <code>javax.jms.IllegalStateException</code>.
126      * (see JMS 1.1 specs, table 4-1).
127      *
128      * @since JMS 1.1
129      */

130     public void testCreateTopicOnQueueSession() {
131         try {
132             Topic tempTopic = queueSession.createTopic("topic_name");
133             fail("Should throw a javax.jms.IllegalStateException");
134         } catch (javax.jms.IllegalStateException JavaDoc e) {
135         } catch (JMSException e) {
136             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
137         }
138     }
139
140     /**
141      * Test that a call to <code>unsubscribe()</code> method
142      * on a <code>QueueSession</code> throws a
143      * <code>javax.jms.IllegalStateException</code>.
144      * (see JMS 1.1 specs, table 4-1).
145      *
146      * @since JMS 1.1
147      */

148     public void testUnsubscribeOnQueueSession() {
149         try {
150             queueSession.unsubscribe("subscriptionName");
151             fail("Should throw a javax.jms.IllegalStateException");
152         } catch (javax.jms.IllegalStateException JavaDoc e) {
153         } catch (JMSException e) {
154             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
155         }
156     }
157     
158     /**
159      * Test that a call to <code>createBrowser()</code> method
160      * on a <code>TopicSession</code> throws a
161      * <code>javax.jms.IllegalStateException</code>.
162      * (see JMS 1.1 specs, table 4-1).
163      *
164      * @since JMS 1.1
165      */

166     public void testCreateBrowserOnTopicSession() {
167         try {
168             QueueBrowser queueBrowser = topicSession.createBrowser(queue);
169             fail("Should throw a javax.jms.IllegalStateException");
170         } catch (javax.jms.IllegalStateException JavaDoc e) {
171         } catch (JMSException e) {
172             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
173         }
174     }
175
176     /**
177      * Test that a call to <code>createQueue()</code> method
178      * on a <code>TopicSession</code> throws a
179      * <code>javax.jms.IllegalStateException</code>.
180      * (see JMS 1.1 specs, table 4-1).
181      *
182      * @since JMS 1.1
183      */

184     public void testCreateQueueOnTopicSession() {
185         try {
186             Queue tempQueue = topicSession.createQueue("queue_name");
187             fail("Should throw a javax.jms.IllegalStateException");
188         } catch (javax.jms.IllegalStateException JavaDoc e) {
189         } catch (JMSException e) {
190             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
191         }
192     }
193
194     /**
195      * Test that a call to <code>createTemporaryQueue()</code> method
196      * on a <code>TopicSession</code> throws a
197      * <code>javax.jms.IllegalStateException</code>.
198      * (see JMS 1.1 specs, table 4-1).
199      *
200      * @since JMS 1.1
201      */

202     public void testCreateTemporaryQueueOnTopicSession() {
203         try {
204             TemporaryQueue tempQueue = topicSession.createTemporaryQueue();
205             fail("Should throw a javax.jms.IllegalStateException");
206         } catch (javax.jms.IllegalStateException JavaDoc e) {
207         } catch (JMSException e) {
208             fail("Should throw a javax.jms.IllegalStateException, not a "+ e);
209         }
210     }
211
212     public void setUp() {
213         super.setUp();
214         try {
215             queueConnection = queueConnectionFactory.createQueueConnection();
216             queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
217             topicConnection = topicConnectionFactory.createTopicConnection();
218             topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
219
220             queueConnection.start();
221             topicConnection.start();
222         } catch (Exception JavaDoc e) {
223             //XXX
224
e.printStackTrace();
225         }
226     }
227     
228     public void tearDown() {
229         try {
230             queueConnection.close();
231             topicConnection.close();
232         } catch (Exception JavaDoc e) {
233             //XXX
234
e.printStackTrace();
235         } finally {
236             queueConnection = null;
237             queueSession = null;
238             topicConnection = null;
239             topicSession = null;
240             super.tearDown();
241         }
242     }
243
244     /**
245      * Method to use this class in a Test suite
246      */

247     public static Test suite() {
248         return new TestSuite(UnifiedSessionTest.class);
249     }
250     
251     public UnifiedSessionTest(String JavaDoc name) {
252         super(name);
253     }
254 }
255
Popular Tags