KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jms > QueueRequestorTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 //
19
// This source code implements specifications defined by the Java
20
// Community Process. In order to remain compliant with the specification
21
// DO NOT add / change / or delete method signatures!
22
//
23

24 package javax.jms;
25
26 import com.mockobjects.jms.MockMessage;
27 import com.mockobjects.jms.MockQueue;
28 import com.mockobjects.jms.MockQueueReceiver;
29 import com.mockobjects.jms.MockQueueSender;
30 import com.mockobjects.jms.MockQueueSession;
31 import com.mockobjects.jms.MockTemporaryQueue;
32 import com.mockobjects.jms.MockTextMessage;
33
34 import junit.framework.TestCase;
35
36
37 /**
38  * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
39  */

40 public class QueueRequestorTest extends TestCase {
41     public void testConstructorNullQueue() {
42         MockQueue queue = new MockQueue();
43
44         try {
45             new QueueRequestor(null, queue);
46             fail();
47         } catch (JMSException ex) {
48             fail("JMSException should not have been thrown.");
49         } catch (NullPointerException ex) {
50             // success.
51
}
52
53         queue.verify();
54     }
55
56     public void testConstructorSessionNull() {
57         MockQueueSession session = new MockQueueSession();
58
59         try {
60             new QueueRequestor(session, null);
61             fail();
62         } catch (JMSException ex) {
63             // success
64
}
65
66         session.verify();
67     }
68
69     public void testConstructorSessionQueue() {
70         MockQueue queue = new MockQueue();
71         MockQueueReceiver receiver = new MockQueueReceiver();
72         MockQueueSender sender = new MockQueueSender();
73         MockQueueSession session = new MockQueueSession();
74         MockTemporaryQueue tempQueue = new MockTemporaryQueue();
75
76         session.setupReceiver(receiver);
77         session.setupSender(sender);
78         session.setupTemporaryQueue(tempQueue);
79
80         try {
81             new QueueRequestor(session, queue);
82             // success
83
} catch (JMSException ex) {
84             fail();
85         }
86
87         queue.verify();
88         receiver.verify();
89         sender.verify();
90         session.verify();
91         tempQueue.verify();
92     }
93
94     public void testRequestNull() {
95         MockQueue queue = new MockQueue();
96         MockQueueReceiver receiver = new MockQueueReceiver();
97         MockQueueSender sender = new MockQueueSender();
98         MockQueueSession session = new MockQueueSession();
99         MockTemporaryQueue tempQueue = new MockTemporaryQueue();
100
101         session.setupReceiver(receiver);
102         session.setupSender(sender);
103         session.setupTemporaryQueue(tempQueue);
104
105         try {
106             QueueRequestor requestor = new QueueRequestor(session, queue);
107             requestor.request(null);
108             fail();
109         } catch (JMSException ex) {
110             fail("JMSException should not have been thrown.");
111         } catch (NullPointerException ex) {
112             // success
113
}
114
115         queue.verify();
116         receiver.verify();
117         sender.verify();
118         session.verify();
119         tempQueue.verify();
120     }
121
122     public void testRequestMessage() {
123         MockMessage reply = new MockTextMessage();
124         MockMessage request = new MockTextMessage();
125         MockQueue queue = new MockQueue();
126         MockQueueReceiver receiver = new MockQueueReceiver();
127         MockQueueSender sender = new MockQueueSender();
128         MockQueueSession session = new MockQueueSession();
129         MockTemporaryQueue tempQueue = new MockTemporaryQueue();
130
131         request.setExpectedJMSReplyTo(tempQueue);
132
133         receiver.setExpectedReceiveCalls(1);
134         receiver.setupReceivedMessage(reply);
135
136         sender.setExpectedSendCalls(1);
137
138         session.setupReceiver(receiver);
139         session.setupSender(sender);
140         session.setupTemporaryQueue(tempQueue);
141
142         try {
143             QueueRequestor requestor = new QueueRequestor(session, queue);
144             Message jmsReply = requestor.request(request);
145             assertEquals(jmsReply, reply);
146         } catch (JMSException ex) {
147             fail("JMSException should not have been thrown.");
148         }
149
150         reply.verify();
151         request.verify();
152         queue.verify();
153         receiver.verify();
154         sender.verify();
155         session.verify();
156         tempQueue.verify();
157     }
158
159     public void testClose() {
160         MockQueue queue = new MockQueue();
161         MockQueueReceiver receiver = new MockQueueReceiver();
162         MockQueueSender sender = new MockQueueSender();
163         MockQueueSession session = new MockQueueSession();
164         MockTemporaryQueue tempQueue = new MockTemporaryQueue();
165
166         session.setExpectedCloseCalls(1);
167         session.setupReceiver(receiver);
168         session.setupSender(sender);
169         session.setupTemporaryQueue(tempQueue);
170
171         tempQueue.setExpectedDeleteCalls(1);
172
173         try {
174             QueueRequestor requestor = new QueueRequestor(session, queue);
175             requestor.close();
176         } catch (JMSException ex) {
177             fail();
178         }
179
180         queue.verify();
181         receiver.verify();
182         sender.verify();
183         session.verify();
184         tempQueue.verify();
185     }
186 }
187
Popular Tags