001: package com.mockrunner.test.jms;
002:
003: import java.util.List;
004:
005: import javax.jms.Session;
006:
007: import junit.framework.TestCase;
008:
009: import com.mockrunner.jms.ConfigurationManager;
010: import com.mockrunner.jms.DestinationManager;
011: import com.mockrunner.jms.GenericTransmissionManager;
012: import com.mockrunner.jms.QueueTransmissionManager;
013: import com.mockrunner.jms.TopicTransmissionManager;
014: import com.mockrunner.jms.TransmissionManagerWrapper;
015: import com.mockrunner.mock.jms.MockConnection;
016: import com.mockrunner.mock.jms.MockMessageProducer;
017: import com.mockrunner.mock.jms.MockQueue;
018: import com.mockrunner.mock.jms.MockQueueBrowser;
019: import com.mockrunner.mock.jms.MockQueueReceiver;
020: import com.mockrunner.mock.jms.MockQueueSender;
021: import com.mockrunner.mock.jms.MockSession;
022: import com.mockrunner.mock.jms.MockTopic;
023: import com.mockrunner.mock.jms.MockTopicPublisher;
024: import com.mockrunner.mock.jms.MockTopicSubscriber;
025:
026: public class TransmissionManagerTest extends TestCase {
027: private MockConnection connection;
028: private MockSession session;
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: DestinationManager destManager = new DestinationManager();
033: ConfigurationManager confManager = new ConfigurationManager();
034: connection = new MockConnection(destManager, confManager);
035: session = (MockSession) connection.createSession(false,
036: Session.CLIENT_ACKNOWLEDGE);
037: }
038:
039: public void testQueueTransmissionManagerCreate() {
040: QueueTransmissionManager manager = session
041: .getQueueTransmissionManager();
042: manager.createQueueSender(new MockQueue("Queue1"));
043: manager.createQueueSender(new MockQueue("Queue2"));
044: manager.createQueueReceiver(new MockQueue("Queue1"), "");
045: manager.createQueueBrowser(new MockQueue("Queue1"), "");
046: manager.createQueueBrowser(new MockQueue("Queue2"), "");
047: manager.createQueueBrowser(new MockQueue("Queue2"), "");
048: manager.createQueueBrowser(new MockQueue("Queue2"), "");
049: assertEquals(2, manager.getQueueSenderList().size());
050: assertEquals(1, manager.getQueueReceiverList().size());
051: assertEquals(4, manager.getQueueBrowserList().size());
052: assertEquals(1, manager.getQueueSenderList("Queue1").size());
053: assertEquals(1, manager.getQueueReceiverList("Queue1").size());
054: assertEquals(0, manager.getQueueReceiverList("Queue2").size());
055: assertEquals(3, manager.getQueueBrowserList("Queue2").size());
056: assertNotNull(manager.getQueueSender(1));
057: assertNull(manager.getQueueSender(2));
058: assertNotNull(manager.getQueueReceiver(0));
059: assertNull(manager.getQueueReceiver(1));
060: assertNotNull(manager.getQueueBrowser(0));
061: assertNotNull(manager.getQueueBrowser(3));
062: assertNull(manager.getQueueBrowser(4));
063: assertNotNull(manager.getQueueSender("Queue1"));
064: assertNotNull(manager.getQueueReceiver("Queue1"));
065: assertNotNull(manager.getQueueBrowser("Queue1"));
066: assertNull(manager.getQueueSender("Queue3"));
067: assertNull(manager.getQueueReceiver("Queue3"));
068: assertNull(manager.getQueueBrowser("Queue3"));
069: }
070:
071: public void testTopicTransmissionManagerCreate() {
072: TopicTransmissionManager manager = session
073: .getTopicTransmissionManager();
074: manager.createTopicPublisher(new MockTopic("Topic1"));
075: manager.createTopicSubscriber(new MockTopic("Topic1"), "",
076: false);
077: manager
078: .createTopicSubscriber(new MockTopic("Topic1"), "",
079: true);
080: manager.createDurableTopicSubscriber(new MockTopic("Topic1"),
081: "subscription1", "", true);
082: manager.createDurableTopicSubscriber(new MockTopic("Topic1"),
083: "subscription2", "", false);
084: manager.createDurableTopicSubscriber(new MockTopic("Topic2"),
085: "subscription2", "", true);
086: assertEquals(1, manager.getTopicPublisherList().size());
087: assertEquals(2, manager.getTopicSubscriberList().size());
088: assertEquals(2, manager.getDurableTopicSubscriberMap().size());
089: assertEquals(1, manager.getTopicPublisherList("Topic1").size());
090: assertEquals(0, manager.getTopicPublisherList("Topic2").size());
091: assertEquals(2, manager.getTopicSubscriberList("Topic1").size());
092: assertEquals(1, manager.getDurableTopicSubscriberMap("Topic1")
093: .size());
094: assertEquals(1, manager.getDurableTopicSubscriberMap("Topic2")
095: .size());
096: assertNotNull(manager.getTopicPublisher(0));
097: assertNull(manager.getTopicPublisher(1));
098: assertNotNull(manager.getTopicSubscriber(1));
099: assertNull(manager.getTopicSubscriber(2));
100: assertNotNull(manager
101: .getDurableTopicSubscriber("subscription1"));
102: assertNotNull(manager
103: .getDurableTopicSubscriber("subscription2"));
104: manager.removeTopicDurableSubscriber("subscription2");
105: assertNotNull(manager
106: .getDurableTopicSubscriber("subscription1"));
107: assertNull(manager.getDurableTopicSubscriber("subscription2"));
108: assertNull(manager.getDurableTopicSubscriber("subscription3"));
109: assertNotNull(manager.getTopicPublisher("Topic1"));
110: assertNotNull(manager.getTopicSubscriber("Topic1"));
111: assertNull(manager.getTopicPublisher("Topic2"));
112: assertNull(manager.getTopicSubscriber("Topic2"));
113: }
114:
115: public void testQueueTransmissionManagerClose() {
116: QueueTransmissionManager manager = session
117: .getQueueTransmissionManager();
118: MockQueueSender sender1 = manager
119: .createQueueSender(new MockQueue("Queue1"));
120: MockQueueSender sender2 = manager
121: .createQueueSender(new MockQueue("Queue2"));
122: MockQueueReceiver receiver1 = manager.createQueueReceiver(
123: new MockQueue("Queue1"), "");
124: MockQueueReceiver receiver2 = manager.createQueueReceiver(
125: new MockQueue("Queue1"), "");
126: MockQueueBrowser browser = manager.createQueueBrowser(
127: new MockQueue("Queue1"), "");
128: manager.closeAllQueueSenders();
129: manager.closeAllQueueReceivers();
130: manager.closeAllQueueBrowsers();
131: assertTrue(sender1.isClosed());
132: assertTrue(sender2.isClosed());
133: assertTrue(receiver1.isClosed());
134: assertTrue(receiver2.isClosed());
135: assertTrue(browser.isClosed());
136: sender1 = manager.createQueueSender(new MockQueue("Queue1"));
137: sender2 = manager.createQueueSender(new MockQueue("Queue2"));
138: receiver1 = manager.createQueueReceiver(
139: new MockQueue("Queue1"), "");
140: receiver2 = manager.createQueueReceiver(
141: new MockQueue("Queue1"), "");
142: browser = manager.createQueueBrowser(new MockQueue("Queue1"),
143: "");
144: manager.closeAll();
145: assertTrue(sender1.isClosed());
146: assertTrue(sender2.isClosed());
147: assertTrue(receiver1.isClosed());
148: assertTrue(receiver2.isClosed());
149: assertTrue(browser.isClosed());
150: }
151:
152: public void testTopicTransmissionManagerClose() {
153: TopicTransmissionManager manager = session
154: .getTopicTransmissionManager();
155: MockTopicPublisher publisher1 = manager
156: .createTopicPublisher(new MockTopic("Topic1"));
157: MockTopicPublisher publisher2 = manager
158: .createTopicPublisher(new MockTopic("Topic2"));
159: MockTopicSubscriber subscriber1 = manager
160: .createTopicSubscriber(new MockTopic("Topic1"), "",
161: false);
162: ;
163: MockTopicSubscriber durableSubscriber1 = manager
164: .createDurableTopicSubscriber(new MockTopic("Topic1"),
165: "subscription1", "", true);
166: MockTopicSubscriber durableSubscriber2 = manager
167: .createDurableTopicSubscriber(new MockTopic("Topic1"),
168: "subscription2", "", false);
169: MockTopicSubscriber durableSubscriber3 = manager
170: .createDurableTopicSubscriber(new MockTopic("Topic2"),
171: "subscription3", "", true);
172: manager.closeAllTopicPublishers();
173: manager.closeAllTopicSubscribers();
174: manager.closeAllTopicDurableSubscribers();
175: assertTrue(publisher1.isClosed());
176: assertTrue(publisher2.isClosed());
177: assertTrue(subscriber1.isClosed());
178: assertTrue(durableSubscriber1.isClosed());
179: assertTrue(durableSubscriber2.isClosed());
180: assertTrue(durableSubscriber3.isClosed());
181: publisher1 = manager.createTopicPublisher(new MockTopic(
182: "Topic1"));
183: publisher2 = manager.createTopicPublisher(new MockTopic(
184: "Topic2"));
185: subscriber1 = manager.createTopicSubscriber(new MockTopic(
186: "Topic1"), "", false);
187: ;
188: durableSubscriber1 = manager.createDurableTopicSubscriber(
189: new MockTopic("Topic1"), "subscription1", "", true);
190: durableSubscriber2 = manager.createDurableTopicSubscriber(
191: new MockTopic("Topic1"), "subscription2", "", false);
192: durableSubscriber3 = manager.createDurableTopicSubscriber(
193: new MockTopic("Topic2"), "subscription3", "", true);
194: manager.closeAll();
195: assertTrue(publisher1.isClosed());
196: assertTrue(publisher2.isClosed());
197: assertTrue(subscriber1.isClosed());
198: assertTrue(durableSubscriber1.isClosed());
199: assertTrue(durableSubscriber2.isClosed());
200: assertTrue(durableSubscriber3.isClosed());
201: }
202:
203: public void testGenericTransmissionManager() {
204: GenericTransmissionManager manager = session
205: .getGenericTransmissionManager();
206: MockMessageProducer producer1 = manager.createMessageProducer();
207: MockMessageProducer producer2 = manager.createQueueSender();
208: MockMessageProducer producer3 = manager.createTopicPublisher();
209: assertSame(producer1, manager.getMessageProducer(0));
210: assertSame(producer2, manager.getMessageProducer(1));
211: assertSame(producer3, manager.getMessageProducer(2));
212: List producerList = manager.getMessageProducerList();
213: assertEquals(3, producerList.size());
214: assertTrue(producerList.contains(producer1));
215: assertTrue(producerList.contains(producer2));
216: assertTrue(producerList.contains(producer3));
217: manager.closeAll();
218: assertTrue(producer1.isClosed());
219: assertTrue(producer2.isClosed());
220: assertTrue(producer3.isClosed());
221: }
222:
223: public void testTransmissionManagerWrapperProducerAndConsumer() {
224: QueueTransmissionManager queueManager = session
225: .getQueueTransmissionManager();
226: MockQueueSender sender1 = queueManager
227: .createQueueSender(new MockQueue("Queue1"));
228: MockQueueSender sender2 = queueManager
229: .createQueueSender(new MockQueue("Queue2"));
230: MockQueueReceiver receiver1 = queueManager.createQueueReceiver(
231: new MockQueue("Queue1"), "");
232: MockQueueReceiver receiver2 = queueManager.createQueueReceiver(
233: new MockQueue("Queue1"), "");
234: queueManager.createQueueBrowser(new MockQueue("Queue1"), "");
235: TopicTransmissionManager topicManager = session
236: .getTopicTransmissionManager();
237: MockTopicPublisher publisher1 = topicManager
238: .createTopicPublisher(new MockTopic("Topic1"));
239: MockTopicSubscriber subscriber1 = topicManager
240: .createTopicSubscriber(new MockTopic("Topic1"), "",
241: false);
242: MockTopicSubscriber subscriber2 = topicManager
243: .createTopicSubscriber(new MockTopic("Topic1"), "",
244: true);
245: MockTopicSubscriber durableSubscriber1 = topicManager
246: .createDurableTopicSubscriber(new MockTopic("Topic1"),
247: "subscription1", "", true);
248: GenericTransmissionManager genericManager = session
249: .getGenericTransmissionManager();
250: MockMessageProducer producer1 = genericManager
251: .createMessageProducer();
252: MockMessageProducer producer2 = genericManager
253: .createMessageProducer();
254: TransmissionManagerWrapper manager = new TransmissionManagerWrapper(
255: queueManager, topicManager, genericManager);
256: assertEquals(5, manager.getMessageProducerList().size());
257: assertEquals(5, manager.getMessageConsumerList().size());
258: assertNotNull(manager.getMessageProducer(2));
259: assertNull(manager.getMessageProducer(6));
260: assertNotNull(manager.getMessageConsumer(4));
261: assertNull(manager.getMessageConsumer(5));
262: assertTrue(manager.getMessageProducerList().contains(sender1));
263: assertTrue(manager.getMessageProducerList().contains(sender2));
264: assertTrue(manager.getMessageProducerList()
265: .contains(publisher1));
266: assertTrue(manager.getMessageProducerList().contains(producer1));
267: assertTrue(manager.getMessageProducerList().contains(producer2));
268: assertTrue(manager.getMessageConsumerList().contains(receiver1));
269: assertTrue(manager.getMessageConsumerList().contains(receiver2));
270: assertTrue(manager.getMessageConsumerList().contains(
271: subscriber1));
272: assertTrue(manager.getMessageConsumerList().contains(
273: subscriber2));
274: assertTrue(manager.getMessageConsumerList().contains(
275: durableSubscriber1));
276: }
277:
278: public void testTransmissionManagerWrapperQueueSender() {
279: QueueTransmissionManager queueManager = session
280: .getQueueTransmissionManager();
281: MockQueueSender sender1 = queueManager
282: .createQueueSender(new MockQueue("Queue1"));
283: MockQueueSender sender2 = queueManager
284: .createQueueSender(new MockQueue("Queue2"));
285: GenericTransmissionManager genericManager = session
286: .getGenericTransmissionManager();
287: MockMessageProducer producer1 = genericManager
288: .createMessageProducer();
289: MockMessageProducer producer2 = genericManager
290: .createTopicPublisher();
291: MockMessageProducer producer3 = genericManager
292: .createQueueSender();
293: TopicTransmissionManager topicManager = session
294: .getTopicTransmissionManager();
295: TransmissionManagerWrapper manager = new TransmissionManagerWrapper(
296: queueManager, topicManager, genericManager);
297: assertEquals(5, manager.getMessageProducerList().size());
298: assertEquals(3, manager.getQueueSenderList().size());
299: assertNotNull(manager.getQueueSender(2));
300: assertNull(manager.getQueueSender(3));
301: assertNotNull(manager.getMessageProducer(4));
302: assertNull(manager.getMessageProducer(5));
303: assertTrue(manager.getMessageProducerList().contains(sender1));
304: assertTrue(manager.getMessageProducerList().contains(sender2));
305: assertTrue(manager.getMessageProducerList().contains(producer1));
306: assertTrue(manager.getMessageProducerList().contains(producer2));
307: assertTrue(manager.getMessageProducerList().contains(producer3));
308: assertTrue(manager.getQueueSenderList().contains(sender1));
309: assertTrue(manager.getQueueSenderList().contains(sender2));
310: assertTrue(manager.getQueueSenderList().contains(producer3));
311: }
312:
313: public void testTransmissionManagerWrapperTopicPublisher() {
314: TopicTransmissionManager topicManager = session
315: .getTopicTransmissionManager();
316: MockTopicPublisher publisher1 = topicManager
317: .createTopicPublisher(new MockTopic("Topic1"));
318: GenericTransmissionManager genericManager = session
319: .getGenericTransmissionManager();
320: MockMessageProducer producer1 = genericManager
321: .createMessageProducer();
322: MockMessageProducer producer2 = genericManager
323: .createTopicPublisher();
324: MockMessageProducer producer3 = genericManager
325: .createQueueSender();
326: QueueTransmissionManager queueManager = session
327: .getQueueTransmissionManager();
328: TransmissionManagerWrapper manager = new TransmissionManagerWrapper(
329: queueManager, topicManager, genericManager);
330: assertEquals(4, manager.getMessageProducerList().size());
331: assertEquals(2, manager.getTopicPublisherList().size());
332: assertNotNull(manager.getTopicPublisher(1));
333: assertNull(manager.getTopicPublisher(2));
334: assertNotNull(manager.getMessageProducer(3));
335: assertNull(manager.getMessageProducer(4));
336: assertTrue(manager.getMessageProducerList()
337: .contains(publisher1));
338: assertTrue(manager.getMessageProducerList().contains(producer1));
339: assertTrue(manager.getMessageProducerList().contains(producer2));
340: assertTrue(manager.getMessageProducerList().contains(producer3));
341: assertTrue(manager.getTopicPublisherList().contains(publisher1));
342: assertTrue(manager.getTopicPublisherList().contains(producer2));
343: }
344: }
|