0001: package com.mockrunner.test.jms;
0002:
0003: import javax.jms.BytesMessage;
0004: import javax.jms.JMSException;
0005: import javax.jms.MapMessage;
0006: import javax.jms.Message;
0007: import javax.jms.MessageConsumer;
0008: import javax.jms.MessageListener;
0009: import javax.jms.ObjectMessage;
0010: import javax.jms.Queue;
0011: import javax.jms.QueueBrowser;
0012: import javax.jms.QueueConnection;
0013: import javax.jms.QueueReceiver;
0014: import javax.jms.QueueSender;
0015: import javax.jms.QueueSession;
0016: import javax.jms.Session;
0017: import javax.jms.TemporaryQueue;
0018: import javax.jms.TemporaryTopic;
0019: import javax.jms.TextMessage;
0020: import javax.jms.Topic;
0021: import javax.jms.TopicConnection;
0022: import javax.jms.TopicPublisher;
0023: import javax.jms.TopicSession;
0024: import javax.jms.TopicSubscriber;
0025:
0026: import junit.framework.TestCase;
0027:
0028: import com.mockrunner.base.VerifyFailedException;
0029: import com.mockrunner.jms.DestinationManager;
0030: import com.mockrunner.jms.GenericTransmissionManager;
0031: import com.mockrunner.jms.JMSTestModule;
0032: import com.mockrunner.jms.QueueTransmissionManager;
0033: import com.mockrunner.jms.TopicTransmissionManager;
0034: import com.mockrunner.jms.TransmissionManagerWrapper;
0035: import com.mockrunner.mock.jms.JMSMockObjectFactory;
0036: import com.mockrunner.mock.jms.MockBytesMessage;
0037: import com.mockrunner.mock.jms.MockConnection;
0038: import com.mockrunner.mock.jms.MockConnectionFactory;
0039: import com.mockrunner.mock.jms.MockMapMessage;
0040: import com.mockrunner.mock.jms.MockMessage;
0041: import com.mockrunner.mock.jms.MockMessageConsumer;
0042: import com.mockrunner.mock.jms.MockMessageProducer;
0043: import com.mockrunner.mock.jms.MockObjectMessage;
0044: import com.mockrunner.mock.jms.MockQueue;
0045: import com.mockrunner.mock.jms.MockQueueConnection;
0046: import com.mockrunner.mock.jms.MockQueueReceiver;
0047: import com.mockrunner.mock.jms.MockQueueSender;
0048: import com.mockrunner.mock.jms.MockQueueSession;
0049: import com.mockrunner.mock.jms.MockSession;
0050: import com.mockrunner.mock.jms.MockTemporaryQueue;
0051: import com.mockrunner.mock.jms.MockTemporaryTopic;
0052: import com.mockrunner.mock.jms.MockTextMessage;
0053: import com.mockrunner.mock.jms.MockTopic;
0054: import com.mockrunner.mock.jms.MockTopicConnection;
0055: import com.mockrunner.mock.jms.MockTopicPublisher;
0056: import com.mockrunner.mock.jms.MockTopicSession;
0057: import com.mockrunner.mock.jms.MockTopicSubscriber;
0058:
0059: public class JMSTestModuleTest extends TestCase {
0060: private JMSMockObjectFactory mockFactory;
0061: private JMSTestModule module;
0062: private MockQueueConnection queueConnection;
0063: private MockTopicConnection topicConnection;
0064: private MockConnection connection;
0065:
0066: protected void setUp() throws Exception {
0067: super .setUp();
0068: mockFactory = new JMSMockObjectFactory();
0069: module = new JMSTestModule(mockFactory);
0070: queueConnection = (MockQueueConnection) mockFactory
0071: .getMockQueueConnectionFactory()
0072: .createQueueConnection();
0073: topicConnection = (MockTopicConnection) mockFactory
0074: .getMockTopicConnectionFactory()
0075: .createTopicConnection();
0076: connection = (MockConnection) mockFactory
0077: .getMockConnectionFactory().createConnection();
0078: }
0079:
0080: public void testSetAndGetCurrentQueueConnection() throws Exception {
0081: assertEquals(queueConnection, module
0082: .getCurrentQueueConnection());
0083: module.setCurrentQueueConnectionIndex(1);
0084: assertNull(module.getCurrentQueueConnection());
0085: MockQueueConnection queueConnection1 = (MockQueueConnection) mockFactory
0086: .getMockQueueConnectionFactory()
0087: .createQueueConnection();
0088: module.setCurrentQueueConnectionIndex(-1);
0089: assertEquals(queueConnection1, module
0090: .getCurrentQueueConnection());
0091: queueConnection1.close();
0092: module.verifyQueueConnectionClosed();
0093: module.setCurrentQueueConnectionIndex(0);
0094: try {
0095: module.verifyQueueConnectionClosed();
0096: fail();
0097: } catch (VerifyFailedException exc) {
0098: //should throw exception
0099: }
0100: queueConnection1.start();
0101: module.verifyQueueConnectionStopped();
0102: module.setCurrentQueueConnectionIndex(1);
0103: try {
0104: module.verifyQueueConnectionStopped();
0105: fail();
0106: } catch (VerifyFailedException exc) {
0107: //should throw exception
0108: }
0109: QueueSession queueSession0 = queueConnection1
0110: .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
0111: QueueSession queueSession1 = queueConnection1
0112: .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
0113: assertEquals(queueSession0, module.getQueueSession(0));
0114: assertEquals(queueSession1, module.getQueueSession(1));
0115: module.setCurrentQueueConnectionIndex(0);
0116: assertNull(module.getQueueSession(0));
0117: }
0118:
0119: public void testSetAndGetCurrentTopicConnection() throws Exception {
0120: assertEquals(topicConnection, module
0121: .getCurrentTopicConnection());
0122: module.setCurrentTopicConnectionIndex(1);
0123: assertNull(module.getCurrentTopicConnection());
0124: MockTopicConnection topicConnection1 = (MockTopicConnection) mockFactory
0125: .getMockTopicConnectionFactory()
0126: .createTopicConnection();
0127: module.setCurrentTopicConnectionIndex(-2);
0128: assertEquals(topicConnection1, module
0129: .getCurrentTopicConnection());
0130: topicConnection.close();
0131: try {
0132: module.verifyTopicConnectionClosed();
0133: fail();
0134: } catch (VerifyFailedException exc) {
0135: //should throw exception
0136: }
0137: module.setCurrentTopicConnectionIndex(0);
0138: module.verifyTopicConnectionClosed();
0139: TopicSession topicSession = topicConnection.createTopicSession(
0140: true, Session.AUTO_ACKNOWLEDGE);
0141: assertEquals(topicSession, module.getTopicSession(0));
0142: module.setCurrentTopicConnectionIndex(1);
0143: assertNull(module.getTopicSession(0));
0144: }
0145:
0146: public void testSetAndGetCurrentConnection() throws Exception {
0147: assertEquals(connection, module.getCurrentConnection());
0148: module.setCurrentConnectionIndex(1);
0149: assertNull(module.getCurrentConnection());
0150: MockConnection connection1 = (MockConnection) mockFactory
0151: .getMockConnectionFactory().createConnection();
0152: module.setCurrentTopicConnectionIndex(-2);
0153: assertEquals(connection1, module.getCurrentConnection());
0154: connection.close();
0155: try {
0156: module.verifyConnectionClosed();
0157: fail();
0158: } catch (VerifyFailedException exc) {
0159: //should throw exception
0160: }
0161: module.setCurrentConnectionIndex(0);
0162: module.verifyConnectionClosed();
0163: Session session1 = connection.createSession(true,
0164: Session.CLIENT_ACKNOWLEDGE);
0165: Session session2 = connection.createSession(true,
0166: Session.CLIENT_ACKNOWLEDGE);
0167: Session session3 = connection.createSession(true,
0168: Session.CLIENT_ACKNOWLEDGE);
0169: assertEquals(session1, module.getSession(0));
0170: assertEquals(session2, module.getSession(1));
0171: assertEquals(session3, module.getSession(2));
0172: module.setCurrentConnectionIndex(1);
0173: assertNull(module.getTopicSession(0));
0174: }
0175:
0176: public void testRegisterQueueMessageListener() throws Exception {
0177: DestinationManager destManager = mockFactory
0178: .getDestinationManager();
0179: destManager.createQueue("queue");
0180: TestMessageListener listener = new TestMessageListener(true);
0181: module.registerTestMessageListenerForQueue("queue", listener);
0182: QueueConnection currentQueueConnection = module
0183: .getCurrentQueueConnection();
0184: assertFalse(currentQueueConnection == queueConnection);
0185: QueueTransmissionManager transManager = module
0186: .getQueueTransmissionManager(0);
0187: QueueReceiver receiver = transManager.getQueueReceiver(0);
0188: assertTrue(listener == receiver.getMessageListener());
0189: module.verifyQueueConnectionStarted();
0190: listener = new TestMessageListener(true);
0191: module.registerTestMessageListenerForQueue(queueConnection,
0192: "queue", listener);
0193: assertTrue(module.getQueueSession(0).getTransacted());
0194: assertTrue(module.getQueueSession(0).isAutoAcknowledge());
0195: module.verifyNumberQueueSessions(1);
0196: module.setCurrentQueueConnectionIndex(0);
0197: module.verifyNumberQueueSessions(1);
0198: transManager = module.getQueueTransmissionManager(0);
0199: receiver = transManager.getQueueReceiver(0);
0200: assertTrue(listener == receiver.getMessageListener());
0201: module.verifyQueueConnectionStarted();
0202: assertTrue(queueConnection.isStarted());
0203: module.registerTestMessageListenerForQueue(queueConnection,
0204: "queue", false, Session.CLIENT_ACKNOWLEDGE, listener);
0205: assertFalse(module.getQueueSession(1).getTransacted());
0206: assertFalse(module.getQueueSession(1).isAutoAcknowledge());
0207: module.registerTestMessageListenerForQueue(queueConnection,
0208: "queue", false, Session.CLIENT_ACKNOWLEDGE,
0209: "number = 1", listener);
0210: QueueTransmissionManager queueManager = module.getQueueSession(
0211: 2).getQueueTransmissionManager();
0212: MockQueueReceiver queueReceiver = queueManager
0213: .getQueueReceiver(0);
0214: assertEquals("number = 1", queueReceiver.getMessageSelector());
0215: }
0216:
0217: public void testRegisterTopicMessageListener() throws Exception {
0218: DestinationManager destManager = mockFactory
0219: .getDestinationManager();
0220: destManager.createTopic("topic");
0221: TestMessageListener listener = new TestMessageListener(true);
0222: module.registerTestMessageListenerForTopic("topic", listener);
0223: TopicConnection currentTopicConnection = module
0224: .getCurrentTopicConnection();
0225: assertFalse(currentTopicConnection == topicConnection);
0226: TopicTransmissionManager transManager = module
0227: .getTopicTransmissionManager(0);
0228: TopicSubscriber subscriber = transManager.getTopicSubscriber(0);
0229: assertTrue(listener == subscriber.getMessageListener());
0230: module.verifyTopicConnectionStarted();
0231: module.registerTestMessageListenerForTopic(
0232: (MockTopicConnection) currentTopicConnection, "topic",
0233: listener);
0234: assertTrue(module.getTopicSession(0).getTransacted());
0235: assertTrue(module.getTopicSession(0).isAutoAcknowledge());
0236: module.verifyNumberTopicSessions(2);
0237: transManager = module.getTopicTransmissionManager(1);
0238: subscriber = transManager.getTopicSubscriber(0);
0239: assertTrue(listener == subscriber.getMessageListener());
0240: module.verifyTopicConnectionStarted();
0241: assertFalse(topicConnection.isStarted());
0242: module.registerTestMessageListenerForTopic(topicConnection,
0243: "topic", listener);
0244: module.verifyNumberTopicSessions(2);
0245: module.setCurrentTopicConnectionIndex(0);
0246: module.verifyNumberTopicSessions(1);
0247: transManager = module.getTopicTransmissionManager(0);
0248: subscriber = transManager.getTopicSubscriber(0);
0249: assertTrue(listener == subscriber.getMessageListener());
0250: module.registerTestMessageListenerForTopic(topicConnection,
0251: "topic", false, Session.DUPS_OK_ACKNOWLEDGE, listener);
0252: assertFalse(module.getTopicSession(1).getTransacted());
0253: assertTrue(module.getTopicSession(1).isAutoAcknowledge());
0254: module.registerTestMessageListenerForTopic(topicConnection,
0255: "topic", false, Session.CLIENT_ACKNOWLEDGE,
0256: "number = 2", listener);
0257: TopicTransmissionManager topicManager = module.getTopicSession(
0258: 2).getTopicTransmissionManager();
0259: MockTopicSubscriber topicSubscriber = topicManager
0260: .getTopicSubscriber(0);
0261: assertEquals("number = 2", topicSubscriber.getMessageSelector());
0262: }
0263:
0264: public void testRegisterMessageListener() throws Exception {
0265: DestinationManager manager = mockFactory
0266: .getDestinationManager();
0267: manager.createQueue("queue");
0268: TestMessageListener listener = new TestMessageListener(true);
0269: module.registerTestMessageListenerForQueue(connection, "queue",
0270: false, Session.CLIENT_ACKNOWLEDGE, listener);
0271: assertEquals(0, module.getQueueSessionList().size());
0272: assertEquals(0, module.getTopicSessionList().size());
0273: assertEquals(1, module.getSessionList().size());
0274: module.registerTestMessageListenerForQueue(topicConnection,
0275: "queue", false, Session.CLIENT_ACKNOWLEDGE, listener);
0276: assertEquals(0, module.getQueueSessionList().size());
0277: assertEquals(1, module.getTopicSessionList().size());
0278: assertEquals(1, module.getSessionList().size());
0279: assertFalse(module.getSession(0) instanceof TopicSession);
0280: assertFalse(module.getSession(0) instanceof QueueSession);
0281: }
0282:
0283: public void testGetQueue() throws Exception {
0284: DestinationManager manager = mockFactory
0285: .getDestinationManager();
0286: manager.createQueue("test1");
0287: manager.createQueue("test2");
0288: assertNotNull(module.getQueue("test1"));
0289: assertNotNull(module.getQueue("test2"));
0290: assertNull(module.getQueue("xyz"));
0291: QueueSession session = queueConnection.createQueueSession(
0292: false, Session.AUTO_ACKNOWLEDGE);
0293: session.createQueue("test2");
0294: manager.removeQueue("test2");
0295: assertNull(module.getQueue("test2"));
0296: try {
0297: session.createQueue("test2");
0298: fail();
0299: } catch (JMSException e) {
0300: //should throw exception
0301: }
0302: }
0303:
0304: public void testGetTopic() throws Exception {
0305: DestinationManager manager = mockFactory
0306: .getDestinationManager();
0307: manager.createTopic("myTopic1");
0308: manager.createTopic("myTopic2");
0309: assertNotNull(module.getTopic("myTopic1"));
0310: assertNotNull(module.getTopic("myTopic2"));
0311: assertNull(module.getTopic("xyz"));
0312: TopicSession session = topicConnection.createTopicSession(
0313: false, Session.AUTO_ACKNOWLEDGE);
0314: session.createTopic("myTopic1");
0315: manager.removeTopic("myTopic1");
0316: assertNull(module.getTopic("myTopic1"));
0317: try {
0318: session.createTopic("myTopic1");
0319: fail();
0320: } catch (JMSException e) {
0321: //should throw exception
0322: }
0323: }
0324:
0325: public void testGetQueueAndTopicDifferentSessions()
0326: throws Exception {
0327: DestinationManager manager = mockFactory
0328: .getDestinationManager();
0329: Queue queue1 = manager.createQueue("queue1");
0330: Queue queue2 = manager.createQueue("queue2");
0331: Queue queue3 = manager.createQueue("queue3");
0332: Topic topic1 = manager.createTopic("topic1");
0333: Topic topic2 = manager.createTopic("topic2");
0334: MockSession session1 = (MockSession) topicConnection
0335: .createSession(false, Session.AUTO_ACKNOWLEDGE);
0336: MockSession session2 = (MockSession) queueConnection
0337: .createSession(false, Session.AUTO_ACKNOWLEDGE);
0338: MockSession session3 = (MockSession) connection.createSession(
0339: true, Session.AUTO_ACKNOWLEDGE);
0340: assertSame(topic1, session1.createTopic("topic1"));
0341: assertSame(topic2, session2.createTopic("topic2"));
0342: assertSame(queue2, session3.createQueue("queue2"));
0343: assertSame(queue1, session2.createQueue("queue1"));
0344: assertSame(queue3, session1.createQueue("queue3"));
0345: try {
0346: session1.createQueue("queue4");
0347: fail();
0348: } catch (JMSException e) {
0349: //should throw exception
0350: }
0351: try {
0352: session3.createTopic("topic3");
0353: fail();
0354: } catch (JMSException e) {
0355: //should throw exception
0356: }
0357: }
0358:
0359: public void testVerifyTemporaryQueue() throws Exception {
0360: queueConnection.createQueueSession(true,
0361: Session.CLIENT_ACKNOWLEDGE);
0362: MockTemporaryQueue queue1 = (MockTemporaryQueue) module
0363: .getQueueSession(0).createTemporaryQueue();
0364: MockTemporaryQueue queue2 = (MockTemporaryQueue) module
0365: .getQueueSession(0).createTemporaryQueue();
0366: assertNotNull(module.getTemporaryQueue(0, 0));
0367: assertNotNull(module.getTemporaryQueue(0, 1));
0368: assertNull(module.getTemporaryQueue(0, 2));
0369: module.verifyNumberTemporaryQueues(0, 2);
0370: try {
0371: module.verifyNumberTemporaryQueues(0, 3);
0372: fail();
0373: } catch (VerifyFailedException exc) {
0374: //should throw exception
0375: }
0376: try {
0377: module.verifyNumberTemporaryQueues(1, 3);
0378: fail();
0379: } catch (VerifyFailedException exc) {
0380: //should throw exception
0381: }
0382: try {
0383: module.verifyTemporaryQueueDeleted(0, 0);
0384: fail();
0385: } catch (VerifyFailedException exc) {
0386: //should throw exception
0387: }
0388: try {
0389: module.verifyAllTemporaryQueuesDeleted(0);
0390: fail();
0391: } catch (VerifyFailedException exc) {
0392: //should throw exception
0393: }
0394: queue1.delete();
0395: module.verifyTemporaryQueueDeleted(0, 0);
0396: try {
0397: module.verifyAllTemporaryQueuesDeleted(0);
0398: fail();
0399: } catch (VerifyFailedException exc) {
0400: //should throw exception
0401: }
0402: queue2.delete();
0403: module.verifyTemporaryQueueDeleted(0, 1);
0404: module.verifyAllTemporaryQueuesDeleted(0);
0405: }
0406:
0407: public void testVerifyTemporaryTopic() throws Exception {
0408: topicConnection.createTopicSession(true,
0409: Session.CLIENT_ACKNOWLEDGE);
0410: MockTemporaryTopic topic1 = (MockTemporaryTopic) module
0411: .getTopicSession(0).createTemporaryTopic();
0412: MockTemporaryTopic topic2 = (MockTemporaryTopic) module
0413: .getTopicSession(0).createTemporaryTopic();
0414: assertNotNull(module.getTemporaryTopic(0, 0));
0415: assertNotNull(module.getTemporaryTopic(0, 1));
0416: assertNull(module.getTemporaryTopic(0, 2));
0417: module.verifyNumberTemporaryTopics(0, 2);
0418: try {
0419: module.verifyNumberTemporaryTopics(0, 3);
0420: fail();
0421: } catch (VerifyFailedException exc) {
0422: //should throw exception
0423: }
0424: try {
0425: module.verifyNumberTemporaryTopics(1, 0);
0426: fail();
0427: } catch (VerifyFailedException exc) {
0428: //should throw exception
0429: }
0430: try {
0431: module.verifyTemporaryTopicDeleted(0, 1);
0432: fail();
0433: } catch (VerifyFailedException exc) {
0434: //should throw exception
0435: }
0436: try {
0437: module.verifyAllTemporaryTopicsDeleted(0);
0438: fail();
0439: } catch (VerifyFailedException exc) {
0440: //should throw exception
0441: }
0442: topic2.delete();
0443: module.verifyTemporaryTopicDeleted(0, 1);
0444: try {
0445: module.verifyAllTemporaryQueuesDeleted(0);
0446: fail();
0447: } catch (VerifyFailedException exc) {
0448: //should throw exception
0449: }
0450: topic1.delete();
0451: module.verifyTemporaryTopicDeleted(0, 0);
0452: module.verifyAllTemporaryTopicsDeleted(0);
0453: }
0454:
0455: public void testTemporaryQueueAndTopicDifferentSessions()
0456: throws Exception {
0457: queueConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0458: topicConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0459: connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0460: MockTemporaryTopic topic1 = (MockTemporaryTopic) module
0461: .getQueueSession(0).createTemporaryTopic();
0462: MockTemporaryTopic topic2 = (MockTemporaryTopic) module
0463: .getQueueSession(0).createTemporaryTopic();
0464: module.verifyNumberTemporaryTopics(0, 0);
0465: try {
0466: module.verifyNumberTemporaryTopics(0, 2);
0467: fail();
0468: } catch (VerifyFailedException exc) {
0469: //should throw exception
0470: }
0471: assertEquals(2, module.getQueueSession(0)
0472: .getTemporaryTopicList().size());
0473: assertSame(topic1, module.getQueueSession(0).getTemporaryTopic(
0474: 0));
0475: assertSame(topic2, module.getQueueSession(0).getTemporaryTopic(
0476: 1));
0477: MockTemporaryQueue queue = (MockTemporaryQueue) module
0478: .getSession(0).createTemporaryQueue();
0479: module.verifyNumberTemporaryQueues(0, 0);
0480: assertEquals(1, module.getSession(0).getTemporaryQueueList()
0481: .size());
0482: assertSame(queue, module.getSession(0).getTemporaryQueue(0));
0483: assertNull(module.getSession(0).getTemporaryQueue(1));
0484: }
0485:
0486: public void testVerifyQueueSender() throws Exception {
0487: queueConnection.createQueueSession(true,
0488: Session.CLIENT_ACKNOWLEDGE);
0489: DestinationManager manager = mockFactory
0490: .getDestinationManager();
0491: manager.createQueue("queue");
0492: module.getQueueSession(0).createSender(
0493: manager.getQueue("queue"));
0494: module.verifyNumberQueueSenders(0, 1);
0495: try {
0496: module.verifyNumberQueueSenders(0, 2);
0497: fail();
0498: } catch (VerifyFailedException exc) {
0499: //should throw exception
0500: }
0501: try {
0502: module.verifyNumberQueueSenders(0, "queue", 2);
0503: fail();
0504: } catch (VerifyFailedException exc) {
0505: //should throw exception
0506: }
0507: try {
0508: module.verifyNumberQueueSenders(1, "queue", 0);
0509: fail();
0510: } catch (VerifyFailedException exc) {
0511: //should throw exception
0512: }
0513: module.getQueueSession(0).createSender(
0514: manager.getQueue("queue"));
0515: module.verifyNumberQueueSenders(0, "queue", 2);
0516: module.verifyNumberQueueSenders(0, 2);
0517: try {
0518: module.verifyNumberQueueSenders(0, "otherQueue", 0);
0519: fail();
0520: } catch (VerifyFailedException exc) {
0521: //should throw exception
0522: }
0523: manager.createQueue("otherQueue");
0524: module.verifyNumberQueueSenders(0, "otherQueue", 0);
0525: QueueTransmissionManager queueManager = module
0526: .getQueueTransmissionManager(0);
0527: assertEquals(2, queueManager.getQueueSenderList().size());
0528: assertEquals(2, queueManager.getQueueSenderList("queue").size());
0529: assertEquals(0, queueManager.getQueueSenderList("otherQueue")
0530: .size());
0531: }
0532:
0533: public void testVerifyTopicPublishers() throws Exception {
0534: topicConnection.createTopicSession(true,
0535: Session.AUTO_ACKNOWLEDGE);
0536: DestinationManager manager = mockFactory
0537: .getDestinationManager();
0538: manager.createTopic("topic");
0539: module.getTopicSession(0).createPublisher(
0540: manager.getTopic("topic"));
0541: module.verifyNumberTopicPublishers(0, 1);
0542: try {
0543: module.verifyNumberTopicPublishers(0, 0);
0544: fail();
0545: } catch (VerifyFailedException exc) {
0546: //should throw exception
0547: }
0548: try {
0549: module.verifyNumberTopicPublishers(0, 2);
0550: fail();
0551: } catch (VerifyFailedException exc) {
0552: //should throw exception
0553: }
0554: try {
0555: module.verifyNumberTopicPublishers(0, "topic", 2);
0556: fail();
0557: } catch (VerifyFailedException exc) {
0558: //should throw exception
0559: }
0560: try {
0561: module.verifyNumberTopicPublishers(1, "topic", 0);
0562: fail();
0563: } catch (VerifyFailedException exc) {
0564: //should throw exception
0565: }
0566: module.getTopicSession(0).createPublisher(
0567: manager.getTopic("topic"));
0568: module.verifyNumberTopicPublishers(0, "topic", 2);
0569: module.verifyNumberTopicPublishers(0, 2);
0570: try {
0571: module.verifyNumberTopicPublishers(0, "topic", 1);
0572: fail();
0573: } catch (VerifyFailedException exc) {
0574: //should throw exception
0575: }
0576: try {
0577: module.verifyNumberTopicPublishers(0, "myTopic", 0);
0578: fail();
0579: } catch (VerifyFailedException exc) {
0580: //should throw exception
0581: }
0582: manager.createTopic("myTopic");
0583: module.verifyNumberTopicPublishers(0, "myTopic", 0);
0584: TopicTransmissionManager topicManager = module
0585: .getTopicTransmissionManager(0);
0586: assertEquals(2, topicManager.getTopicPublisherList().size());
0587: assertEquals(2, topicManager.getTopicPublisherList("topic")
0588: .size());
0589: assertEquals(0, topicManager.getTopicPublisherList("myTopic")
0590: .size());
0591: }
0592:
0593: public void testVerifyMessageProducers() throws Exception {
0594: connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0595: queueConnection.createQueueSession(false,
0596: Session.CLIENT_ACKNOWLEDGE);
0597: topicConnection.createTopicSession(false,
0598: Session.AUTO_ACKNOWLEDGE);
0599: DestinationManager manager = mockFactory
0600: .getDestinationManager();
0601: manager.createQueue("queue");
0602: manager.createTopic("topic");
0603: module.getSession(0).createProducer(manager.getQueue("queue"));
0604: module.getSession(0).createProducer(manager.getTopic("topic"));
0605: module.getSession(0).createProducer(null);
0606: module.verifyNumberQueueSenders(0, 0);
0607: module.verifyNumberTopicPublishers(0, 0);
0608: module.verifyNumberMessageProducers(0, 3);
0609: try {
0610: module.verifyNumberMessageProducers(0, 1);
0611: fail();
0612: } catch (VerifyFailedException exc) {
0613: //should throw exception
0614: }
0615: TransmissionManagerWrapper manager1 = module
0616: .getTransmissionManagerWrapper(0);
0617: QueueTransmissionManager manager2 = manager1
0618: .getQueueTransmissionManager();
0619: TopicTransmissionManager manager3 = manager1
0620: .getTopicTransmissionManager();
0621: GenericTransmissionManager manager4 = manager1
0622: .getGenericTransmissionManager();
0623: QueueTransmissionManager queueManager = module
0624: .getQueueTransmissionManager(0);
0625: TopicTransmissionManager topicManager = module
0626: .getTopicTransmissionManager(0);
0627: assertEquals(3, manager1.getMessageProducerList().size());
0628: assertEquals(1, manager2.getQueueSenderList().size());
0629: assertEquals(1, manager3.getTopicPublisherList().size());
0630: assertEquals(1, manager4.getMessageProducerList().size());
0631: assertEquals(0, queueManager.getQueueSenderList().size());
0632: assertEquals(0, topicManager.getTopicPublisherList().size());
0633: assertTrue(manager1.getMessageProducer(0) instanceof MockQueueSender);
0634: assertTrue(manager1.getMessageProducer(1) instanceof MockTopicPublisher);
0635: }
0636:
0637: public void testVerifyQueueReceiver() throws Exception {
0638: queueConnection.createQueueSession(true,
0639: Session.CLIENT_ACKNOWLEDGE);
0640: DestinationManager manager = mockFactory
0641: .getDestinationManager();
0642: Queue queue1 = manager.createQueue("queue");
0643: Queue queue2 = manager.createQueue("otherQueue");
0644: module.getQueueSession(0).createReceiver(queue1);
0645: module.verifyNumberQueueReceivers(0, 1);
0646: module.verifyNumberQueueReceivers(0, "queue", 1);
0647: try {
0648: module.verifyNumberQueueReceivers(0, 2);
0649: fail();
0650: } catch (VerifyFailedException exc) {
0651: //should throw exception
0652: }
0653: try {
0654: module.verifyNumberQueueReceivers(0, "queue", 0);
0655: fail();
0656: } catch (VerifyFailedException exc) {
0657: //should throw exception
0658: }
0659: module.verifyNumberQueueReceivers(0, "otherQueue", 0);
0660: module.getQueueSession(0).createReceiver(queue2);
0661: module.verifyNumberQueueReceivers(0, 2);
0662: module.verifyNumberQueueReceivers(0, "otherQueue", 1);
0663: try {
0664: module.verifyNumberQueueReceivers(0, "noQueue", 0);
0665: fail();
0666: } catch (VerifyFailedException exc) {
0667: //should throw exception
0668: }
0669: QueueTransmissionManager queueManager = module
0670: .getQueueTransmissionManager(0);
0671: assertEquals(2, queueManager.getQueueReceiverList().size());
0672: assertEquals(1, queueManager.getQueueReceiverList("otherQueue")
0673: .size());
0674: }
0675:
0676: public void testVerifyTopicSubscriber() throws Exception {
0677: topicConnection.createTopicSession(true,
0678: Session.CLIENT_ACKNOWLEDGE);
0679: DestinationManager manager = mockFactory
0680: .getDestinationManager();
0681: Topic topic1 = manager.createTopic("topic1");
0682: Topic topic2 = manager.createTopic("topic2");
0683: module.getTopicSession(0).createSubscriber(topic1);
0684: module.verifyNumberTopicSubscribers(0, 1);
0685: module.verifyNumberTopicSubscribers(0, "topic1", 1);
0686: try {
0687: module.verifyNumberTopicSubscribers(0, 2);
0688: fail();
0689: } catch (VerifyFailedException exc) {
0690: //should throw exception
0691: }
0692: try {
0693: module.verifyNumberTopicSubscribers(0, 0);
0694: fail();
0695: } catch (VerifyFailedException exc) {
0696: //should throw exception
0697: }
0698: try {
0699: module.verifyNumberTopicSubscribers(0, "topic1", 0);
0700: fail();
0701: } catch (VerifyFailedException exc) {
0702: //should throw exception
0703: }
0704: module.verifyNumberTopicSubscribers(0, "topic2", 0);
0705: module.getTopicSession(0).createSubscriber(topic2);
0706: module.verifyNumberTopicSubscribers(0, 2);
0707: module.verifyNumberTopicSubscribers(0, "topic2", 1);
0708: try {
0709: module.verifyNumberTopicSubscribers(0, "noTopic", 0);
0710: fail();
0711: } catch (VerifyFailedException exc) {
0712: //should throw exception
0713: }
0714: TopicTransmissionManager topicManager = module
0715: .getTopicTransmissionManager(0);
0716: assertEquals(2, topicManager.getTopicSubscriberList().size());
0717: assertEquals(1, topicManager.getTopicSubscriberList("topic1")
0718: .size());
0719: assertEquals(0, topicManager.getDurableTopicSubscriberMap(
0720: "topic1").size());
0721: }
0722:
0723: public void testVerifyDurableTopicSubscriber() throws Exception {
0724: topicConnection.createTopicSession(true,
0725: Session.CLIENT_ACKNOWLEDGE);
0726: module.verifyNumberDurableTopicSubscribers(0, 0);
0727: try {
0728: module.verifyDurableTopicSubscriberPresent(0,
0729: "durableSubscriber");
0730: fail();
0731: } catch (VerifyFailedException exc) {
0732: //should throw exception
0733: }
0734: DestinationManager manager = mockFactory
0735: .getDestinationManager();
0736: Topic topic1 = manager.createTopic("topic1");
0737: Topic topic2 = manager.createTopic("topic2");
0738: module.verifyNumberDurableTopicSubscribers(0, "topic1", 0);
0739: module.getTopicSession(0).createDurableSubscriber(topic1,
0740: "durableSubscriber");
0741: module.verifyDurableTopicSubscriberPresent(0,
0742: "durableSubscriber");
0743: module.verifyNumberDurableTopicSubscribers(0, 1);
0744: module.verifyNumberDurableTopicSubscribers(0, "topic1", 1);
0745: try {
0746: module.verifyNumberDurableTopicSubscribers(0,
0747: "anotherDurableSubscriber", 0);
0748: fail();
0749: } catch (VerifyFailedException exc) {
0750: //should throw exception
0751: }
0752: module.getTopicSession(0).createDurableSubscriber(topic1,
0753: "durableSubscriber");
0754: module.verifyDurableTopicSubscriberPresent(0,
0755: "durableSubscriber");
0756: module.verifyNumberDurableTopicSubscribers(0, 1);
0757: module.verifyNumberDurableTopicSubscribers(0, "topic1", 1);
0758: module.getTopicSession(0).createDurableSubscriber(topic2,
0759: "anotherDurableSubscriber");
0760: module.verifyDurableTopicSubscriberPresent(0,
0761: "anotherDurableSubscriber");
0762: module.verifyNumberDurableTopicSubscribers(0, 2);
0763: module.verifyNumberDurableTopicSubscribers(0, "topic1", 1);
0764: module.verifyNumberDurableTopicSubscribers(0, "topic2", 1);
0765: try {
0766: module.verifyNumberDurableTopicSubscribers(0, "topic1", 2);
0767: fail();
0768: } catch (VerifyFailedException exc) {
0769: //should throw exception
0770: }
0771: TopicTransmissionManager topicManager = module
0772: .getTopicTransmissionManager(0);
0773: assertEquals(0, topicManager.getTopicSubscriberList().size());
0774: assertEquals(2, topicManager.getDurableTopicSubscriberMap()
0775: .size());
0776: assertEquals(1, topicManager.getDurableTopicSubscriberMap(
0777: "topic1").size());
0778: assertEquals(1, topicManager.getDurableTopicSubscriberMap(
0779: "topic2").size());
0780: assertEquals(0, topicManager.getDurableTopicSubscriberMap(
0781: "topic3").size());
0782: assertNotNull(topicManager.getDurableTopicSubscriberMap(
0783: "topic2").get("anotherDurableSubscriber"));
0784: }
0785:
0786: public void testVerifyMessageConsumer() throws Exception {
0787: connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0788: queueConnection.createQueueSession(false,
0789: Session.CLIENT_ACKNOWLEDGE);
0790: topicConnection.createTopicSession(false,
0791: Session.AUTO_ACKNOWLEDGE);
0792: DestinationManager manager = mockFactory
0793: .getDestinationManager();
0794: manager.createQueue("queue");
0795: manager.createTopic("topic");
0796: module.getSession(0).createConsumer(manager.getQueue("queue"));
0797: module.getSession(0).createConsumer(manager.getTopic("topic"));
0798: module.getSession(0).createDurableSubscriber(
0799: manager.getTopic("topic"), "subscription");
0800: module.verifyNumberQueueReceivers(0, 0);
0801: module.verifyNumberTopicSubscribers(0, 0);
0802: module.verifyNumberDurableTopicSubscribers(0, 0);
0803: module.verifyNumberMessageConsumers(0, 3);
0804: try {
0805: module.verifyNumberMessageProducers(0, 4);
0806: fail();
0807: } catch (VerifyFailedException exc) {
0808: //should throw exception
0809: }
0810: TransmissionManagerWrapper manager1 = module
0811: .getTransmissionManagerWrapper(0);
0812: QueueTransmissionManager manager2 = manager1
0813: .getQueueTransmissionManager();
0814: TopicTransmissionManager manager3 = manager1
0815: .getTopicTransmissionManager();
0816: QueueTransmissionManager queueManager = module
0817: .getQueueTransmissionManager(0);
0818: TopicTransmissionManager topicManager = module
0819: .getTopicTransmissionManager(0);
0820: assertEquals(3, manager1.getMessageConsumerList().size());
0821: assertEquals(1, manager2.getQueueReceiverList().size());
0822: assertEquals(1, manager3.getTopicSubscriberList().size());
0823: assertEquals(1, manager3.getDurableTopicSubscriberMap().size());
0824: assertEquals(0, queueManager.getQueueReceiverList().size());
0825: assertEquals(0, topicManager.getTopicSubscriberList().size());
0826: assertEquals(0, topicManager.getDurableTopicSubscriberMap()
0827: .size());
0828: assertTrue(manager1.getMessageConsumer(0) instanceof MockQueueReceiver);
0829: assertTrue(manager1.getMessageConsumer(1) instanceof MockTopicSubscriber);
0830: }
0831:
0832: public void testVerifyQueueBrowser() throws Exception {
0833: queueConnection.createQueueSession(true,
0834: Session.CLIENT_ACKNOWLEDGE);
0835: DestinationManager manager = mockFactory
0836: .getDestinationManager();
0837: manager.createQueue("queue");
0838: module.getQueueSession(0).createBrowser(
0839: manager.getQueue("queue"));
0840: module.getQueueSession(0).createBrowser(
0841: manager.getQueue("queue"));
0842: module.verifyNumberQueueBrowsers(0, 2);
0843: module.verifyNumberQueueBrowsers(0, "queue", 2);
0844: try {
0845: module.verifyNumberQueueBrowsers(0, 3);
0846: fail();
0847: } catch (VerifyFailedException exc) {
0848: //should throw exception
0849: }
0850: try {
0851: module.verifyNumberQueueBrowsers(0, "queue", 1);
0852: fail();
0853: } catch (VerifyFailedException exc) {
0854: //should throw exception
0855: }
0856: try {
0857: module.verifyNumberQueueBrowsers(0, "queue", 0);
0858: fail();
0859: } catch (VerifyFailedException exc) {
0860: //should throw exception
0861: }
0862: try {
0863: module.verifyNumberQueueBrowsers(0, "otherQueue", 0);
0864: fail();
0865: } catch (VerifyFailedException exc) {
0866: //should throw exception
0867: }
0868: manager.createQueue("otherQueue");
0869: module.verifyNumberQueueBrowsers(0, "otherQueue", 0);
0870: }
0871:
0872: public void testVerifyQueueBrowserDifferentSessions()
0873: throws Exception {
0874: queueConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
0875: topicConnection
0876: .createSession(false, Session.CLIENT_ACKNOWLEDGE);
0877: connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
0878: DestinationManager manager = mockFactory
0879: .getDestinationManager();
0880: manager.createQueue("queue");
0881: QueueBrowser browser1 = (QueueBrowser) module.getSession(0)
0882: .createBrowser(manager.getQueue("queue"));
0883: QueueBrowser browser2 = (QueueBrowser) module.getSession(0)
0884: .createBrowser(manager.getQueue("queue"));
0885: module.verifyNumberQueueBrowsers(0, 0);
0886: module.verifyNumberQueueBrowsers(0, "queue", 0);
0887: try {
0888: module.verifyNumberQueueBrowsers(0, 2);
0889: fail();
0890: } catch (VerifyFailedException exc) {
0891: //should throw exception
0892: }
0893: QueueTransmissionManager transManager = module
0894: .getTransmissionManagerWrapper(0)
0895: .getQueueTransmissionManager();
0896: assertEquals(2, transManager.getQueueBrowserList().size());
0897: assertSame(browser1, transManager.getQueueBrowser(0));
0898: assertSame(browser2, transManager.getQueueBrowser(1));
0899: QueueBrowser browser3 = (QueueBrowser) module
0900: .getTopicSession(0).createBrowser(
0901: manager.getQueue("queue"));
0902: module.verifyNumberQueueBrowsers(0, 0);
0903: transManager = module.getTopicSession(0)
0904: .getQueueTransmissionManager();
0905: assertEquals(1, transManager.getQueueBrowserList().size());
0906: assertSame(browser3, transManager.getQueueBrowser(0));
0907: }
0908:
0909: public void testVerifyQueueSession() throws Exception {
0910: assertNull(module.getQueueSession(0));
0911: queueConnection.createQueueSession(true,
0912: Session.CLIENT_ACKNOWLEDGE);
0913: assertNotNull(module.getQueueSession(0));
0914: assertNull(module.getQueueSession(1));
0915: module.verifyNumberQueueSessions(1);
0916: try {
0917: module.verifyNumberQueueSessions(2);
0918: fail();
0919: } catch (VerifyFailedException exc) {
0920: //should throw exception
0921: }
0922: queueConnection.createQueueSession(false,
0923: Session.CLIENT_ACKNOWLEDGE);
0924: assertNotNull(module.getQueueSession(1));
0925: module.verifyNumberQueueSessions(2);
0926: }
0927:
0928: public void testVerifyTopicSession() throws Exception {
0929: module.verifyNumberTopicSessions(0);
0930: assertNull(module.getTopicSession(0));
0931: topicConnection.createTopicSession(true,
0932: Session.CLIENT_ACKNOWLEDGE);
0933: assertNotNull(module.getTopicSession(0));
0934: assertNull(module.getTopicSession(1));
0935: module.verifyNumberTopicSessions(1);
0936: try {
0937: module.verifyNumberTopicSessions(0);
0938: fail();
0939: } catch (VerifyFailedException exc) {
0940: //should throw exception
0941: }
0942: try {
0943: module.verifyNumberTopicSessions(2);
0944: fail();
0945: } catch (VerifyFailedException exc) {
0946: //should throw exception
0947: }
0948: topicConnection.createTopicSession(false,
0949: Session.CLIENT_ACKNOWLEDGE);
0950: assertNotNull(module.getTopicSession(1));
0951: assertNull(module.getTopicSession(2));
0952: }
0953:
0954: public void testVerifySession() throws Exception {
0955: module.verifyNumberSessions(0);
0956: module.verifyNumberTopicSessions(0);
0957: module.verifyNumberQueueSessions(0);
0958: assertNull(module.getSession(0));
0959: connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
0960: assertNotNull(module.getSession(0));
0961: assertNull(module.getQueueSession(0));
0962: assertNull(module.getTopicSession(0));
0963: try {
0964: module.verifyNumberSessions(0);
0965: fail();
0966: } catch (VerifyFailedException exc) {
0967: //should throw exception
0968: }
0969: try {
0970: module.verifyNumberSessions(2);
0971: fail();
0972: } catch (VerifyFailedException exc) {
0973: //should throw exception
0974: }
0975: topicConnection
0976: .createSession(false, Session.CLIENT_ACKNOWLEDGE);
0977: assertNotNull(module.getSession(0));
0978: assertNull(module.getQueueSession(0));
0979: assertNotNull(module.getTopicSession(0));
0980: try {
0981: module.verifyNumberQueueSessions(1);
0982: fail();
0983: } catch (VerifyFailedException exc) {
0984: //should throw exception
0985: }
0986: connection.createSession(true, Session.DUPS_OK_ACKNOWLEDGE);
0987: assertEquals(2, module.getSessionList().size());
0988: assertEquals(1, module.getTopicSessionList().size());
0989: assertEquals(0, module.getQueueSessionList().size());
0990: }
0991:
0992: public void testVerifyNumberQueueMessages() throws Exception {
0993: queueConnection.createQueueSession(true,
0994: Session.CLIENT_ACKNOWLEDGE);
0995: DestinationManager manager = mockFactory
0996: .getDestinationManager();
0997: manager.createQueue("queue");
0998: QueueSender sender1 = module.getQueueSession(0).createSender(
0999: manager.getQueue("queue"));
1000: manager.createQueue("otherQueue");
1001: QueueSender sender2 = module.getQueueSession(0).createSender(
1002: manager.getQueue("otherQueue"));
1003: QueueSender sender3 = module.getQueueSession(0).createSender(
1004: module.getQueueSession(0).createTemporaryQueue());
1005: QueueReceiver receiver = module.getQueueSession(0)
1006: .createReceiver(manager.getQueue("otherQueue"));
1007: receiver.setMessageListener(new MessageListener() {
1008: public void onMessage(Message message) {
1009: }
1010: });
1011: sender1.send(module.getQueueSession(0).createTextMessage());
1012: sender1.send(module.getQueueSession(0).createTextMessage());
1013: sender2.send(module.getQueueSession(0).createTextMessage());
1014: sender2.send(module.getQueueSession(0).createObjectMessage());
1015: sender2.send(module.getQueueSession(0).createMapMessage());
1016: sender3.send(module.getQueueSession(0).createMapMessage());
1017: sender3.send(module.getQueueSession(0).createStreamMessage());
1018: module.verifyNumberOfCreatedQueueTextMessages(0, 3);
1019: module.verifyNumberOfCreatedQueueObjectMessages(0, 1);
1020: module.verifyNumberOfCreatedQueueMapMessages(0, 2);
1021: module.verifyNumberOfCreatedQueueStreamMessages(0, 1);
1022: module.verifyNumberOfCreatedQueueBytesMessages(0, 0);
1023: module.verifyNumberOfCreatedQueueMessages(0, 0);
1024: try {
1025: module.verifyNumberOfCreatedQueueMessages(0, 1);
1026: fail();
1027: } catch (VerifyFailedException exc) {
1028: //should throw exception
1029: }
1030: try {
1031: module.verifyNumberOfCreatedQueueMapMessages(1, 2);
1032: fail();
1033: } catch (VerifyFailedException exc) {
1034: //should throw exception
1035: }
1036: module.verifyNumberOfCurrentQueueMessages("queue", 2);
1037: module.verifyNumberOfReceivedQueueMessages("queue", 2);
1038: module.verifyNumberOfCurrentQueueMessages("otherQueue", 0);
1039: module.verifyNumberOfReceivedQueueMessages("otherQueue", 3);
1040: module.verifyNumberOfCurrentQueueMessages(0, 0, 2);
1041: module.verifyNumberOfReceivedQueueMessages(0, 0, 2);
1042: module.verifyNumberTemporaryQueues(0, 1);
1043: try {
1044: module.verifyNumberOfReceivedQueueMessages("queue", 1);
1045: fail();
1046: } catch (VerifyFailedException exc) {
1047: //should throw exception
1048: }
1049: try {
1050: module.verifyNumberOfCurrentQueueMessages(0, 0, 0);
1051: fail();
1052: } catch (VerifyFailedException exc) {
1053: //should throw exception
1054: }
1055: }
1056:
1057: public void testVerifyNumberTopicMessages() throws Exception {
1058: topicConnection.createTopicSession(true,
1059: Session.CLIENT_ACKNOWLEDGE);
1060: DestinationManager manager = mockFactory
1061: .getDestinationManager();
1062: manager.createTopic("topic");
1063: TopicPublisher publisher1 = module.getTopicSession(0)
1064: .createPublisher(manager.getTopic("topic"));
1065: manager.createTopic("otherTopic");
1066: TopicPublisher publisher2 = module.getTopicSession(0)
1067: .createPublisher(manager.getTopic("otherTopic"));
1068: TopicPublisher publisher3 = module.getTopicSession(0)
1069: .createPublisher(
1070: module.getTopicSession(0)
1071: .createTemporaryTopic());
1072: TopicSubscriber subscriber = module.getTopicSession(0)
1073: .createSubscriber(manager.getTopic("otherTopic"));
1074: subscriber.setMessageListener(new MessageListener() {
1075: public void onMessage(Message message) {
1076: }
1077: });
1078: publisher1.publish(module.getTopicSession(0)
1079: .createTextMessage());
1080: publisher2.publish(module.getTopicSession(0)
1081: .createTextMessage());
1082: publisher2.publish(module.getTopicSession(0)
1083: .createObjectMessage());
1084: publisher2.publish(module.getTopicSession(0)
1085: .createObjectMessage());
1086: publisher2
1087: .publish(module.getTopicSession(0).createMapMessage());
1088: publisher3
1089: .publish(module.getTopicSession(0).createMapMessage());
1090: publisher3.publish(module.getTopicSession(0)
1091: .createBytesMessage());
1092: module.verifyNumberOfCreatedTopicTextMessages(0, 2);
1093: module.verifyNumberOfCreatedTopicObjectMessages(0, 2);
1094: module.verifyNumberOfCreatedTopicMapMessages(0, 2);
1095: module.verifyNumberOfCreatedTopicBytesMessages(0, 1);
1096: module.verifyNumberOfCreatedTopicStreamMessages(0, 0);
1097: module.verifyNumberOfCreatedTopicMessages(0, 0);
1098: try {
1099: module.verifyNumberOfCreatedTopicMessages(0, 3);
1100: fail();
1101: } catch (VerifyFailedException exc) {
1102: //should throw exception
1103: }
1104: try {
1105: module.verifyNumberOfCreatedTopicMapMessages(1, 0);
1106: fail();
1107: } catch (VerifyFailedException exc) {
1108: //should throw exception
1109: }
1110: module.verifyNumberOfCurrentTopicMessages("topic", 1);
1111: module.verifyNumberOfReceivedTopicMessages("topic", 1);
1112: module.verifyNumberOfCurrentTopicMessages("otherTopic", 0);
1113: module.verifyNumberOfReceivedTopicMessages("otherTopic", 4);
1114: module.verifyNumberOfCurrentTopicMessages(0, 0, 2);
1115: module.verifyNumberOfReceivedTopicMessages(0, 0, 2);
1116: module.verifyNumberTemporaryTopics(0, 1);
1117: try {
1118: module.verifyNumberOfReceivedTopicMessages("topic", 0);
1119: fail();
1120: } catch (VerifyFailedException exc) {
1121: //should throw exception
1122: }
1123: try {
1124: module.verifyNumberOfCurrentQueueMessages(0, 0, 0);
1125: fail();
1126: } catch (VerifyFailedException exc) {
1127: //should throw exception
1128: }
1129: }
1130:
1131: public void testVerifyNumberMessages() throws Exception {
1132: connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1133: DestinationManager manager = mockFactory
1134: .getDestinationManager();
1135: manager.createQueue("queue");
1136: MockMessageProducer producer1 = (MockMessageProducer) module
1137: .getSession(0)
1138: .createProducer(manager.getQueue("queue"));
1139: manager.createTopic("topic");
1140: MockMessageProducer producer2 = (MockMessageProducer) module
1141: .getSession(0)
1142: .createProducer(manager.getTopic("topic"));
1143: MockMessageProducer producer3 = (MockMessageProducer) module
1144: .getSession(0).createProducer(
1145: module.getSession(0).createTemporaryQueue());
1146: MessageConsumer consumer = module.getSession(0).createConsumer(
1147: manager.getTopic("topic"));
1148: consumer.setMessageListener(new MessageListener() {
1149: public void onMessage(Message message) {
1150: }
1151: });
1152: producer1.send(module.getSession(0).createTextMessage());
1153: producer1.send(module.getSession(0).createTextMessage());
1154: producer2.send(module.getSession(0).createTextMessage());
1155: producer2.send(module.getSession(0).createObjectMessage());
1156: producer2.send(module.getSession(0).createMapMessage());
1157: producer3.send(module.getSession(0).createMapMessage());
1158: producer3.send(module.getSession(0).createStreamMessage());
1159: module.verifyNumberOfCreatedTextMessages(0, 3);
1160: module.verifyNumberOfCreatedObjectMessages(0, 1);
1161: module.verifyNumberOfCreatedMapMessages(0, 2);
1162: module.verifyNumberOfCreatedStreamMessages(0, 1);
1163: module.verifyNumberOfCreatedBytesMessages(0, 0);
1164: module.verifyNumberOfCreatedMessages(0, 0);
1165: try {
1166: module.verifyNumberOfCreatedMessages(0, 1);
1167: fail();
1168: } catch (VerifyFailedException exc) {
1169: //should throw exception
1170: }
1171: try {
1172: module.verifyNumberOfCreatedMapMessages(1, 2);
1173: fail();
1174: } catch (VerifyFailedException exc) {
1175: //should throw exception
1176: }
1177: module.verifyNumberOfCurrentQueueMessages("queue", 2);
1178: module.verifyNumberOfReceivedQueueMessages("queue", 2);
1179: module.verifyNumberOfCurrentTopicMessages("topic", 0);
1180: module.verifyNumberOfReceivedTopicMessages("topic", 3);
1181: try {
1182: module.verifyNumberOfCurrentQueueMessages(0, 0, 2);
1183: fail();
1184: } catch (VerifyFailedException exc) {
1185: //should throw exception
1186: }
1187: assertEquals(2, module.getSession(0).getTemporaryQueue(0)
1188: .getCurrentMessageList().size());
1189: }
1190:
1191: public void testVerifyNumberMessagesDifferentSessions()
1192: throws Exception {
1193: queueConnection.createQueueSession(false,
1194: Session.AUTO_ACKNOWLEDGE);
1195: topicConnection.createTopicSession(true,
1196: Session.CLIENT_ACKNOWLEDGE);
1197: connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
1198: DestinationManager manager = mockFactory
1199: .getDestinationManager();
1200: manager.createQueue("queue");
1201: MockMessageProducer queueProducer = (MockMessageProducer) module
1202: .getQueueSession(0).createProducer(
1203: module.getQueueSession(0)
1204: .createTemporaryTopic());
1205: MockMessageProducer topicProducer = (MockMessageProducer) module
1206: .getTopicSession(0).createProducer(
1207: module.getTopicSession(0)
1208: .createTemporaryQueue());
1209: MockMessageProducer producer = (MockMessageProducer) module
1210: .getSession(0)
1211: .createProducer(manager.getQueue("queue"));
1212: queueProducer.send(new MockTextMessage("testQueue"));
1213: topicProducer.send(new MockTextMessage("testTopic"));
1214: producer.send(new MockTextMessage("test"));
1215: module.verifyNumberOfCurrentQueueMessages("queue", 1);
1216: module.verifyNumberOfReceivedQueueMessages("queue", 1);
1217: try {
1218: module.verifyNumberOfCurrentQueueMessages(0, 0, 1);
1219: fail();
1220: } catch (VerifyFailedException exc) {
1221: //should throw exception
1222: }
1223: try {
1224: module.verifyNumberOfCurrentTopicMessages(0, 0, 1);
1225: fail();
1226: } catch (VerifyFailedException exc) {
1227: //should throw exception
1228: }
1229: assertEquals(1, module.getQueueSession(0).getTemporaryTopic(0)
1230: .getCurrentMessageList().size());
1231: assertEquals(1, module.getTopicSession(0).getTemporaryQueue(0)
1232: .getCurrentMessageList().size());
1233: assertEquals(1, module.getQueueSession(0).getTemporaryTopic(0)
1234: .getReceivedMessageList().size());
1235: assertEquals(1, module.getTopicSession(0).getTemporaryQueue(0)
1236: .getReceivedMessageList().size());
1237: }
1238:
1239: public void testVerifyQueueMessageEquals() throws Exception {
1240: queueConnection.createQueueSession(true,
1241: Session.CLIENT_ACKNOWLEDGE);
1242: DestinationManager manager = mockFactory
1243: .getDestinationManager();
1244: manager.createQueue("queue");
1245: QueueSender sender = module.getQueueSession(0).createSender(
1246: manager.getQueue("queue"));
1247: TextMessage message1 = module.getQueueSession(0)
1248: .createTextMessage();
1249: message1.setText("text1");
1250: ObjectMessage message2 = module.getQueueSession(0)
1251: .createObjectMessage();
1252: message2.setObject(new Integer(1));
1253: MapMessage message3 = module.getQueueSession(0)
1254: .createMapMessage();
1255: message3.setFloat("float1", 1.2f);
1256: message3.setString("string1", "teststring");
1257: sender.send(message1);
1258: sender.send(message2);
1259: sender.send(message3);
1260: module.verifyCurrentQueueMessageEquals("queue", 0,
1261: new MockTextMessage("text1"));
1262: module.verifyCurrentQueueMessageEquals("queue", 1,
1263: new MockObjectMessage(new Integer(1)));
1264: module.verifyReceivedQueueMessageEquals("queue", 0,
1265: new MockTextMessage("text1"));
1266: module.verifyReceivedQueueMessageEquals("queue", 1,
1267: new MockObjectMessage(new Integer(1)));
1268: MockMapMessage testMessage = new MockMapMessage();
1269: testMessage.setFloat("float1", 1.2f);
1270: testMessage.setString("string1", "teststring");
1271: module.verifyCurrentQueueMessageEquals("queue", 2, testMessage);
1272: module
1273: .verifyReceivedQueueMessageEquals("queue", 2,
1274: testMessage);
1275: try {
1276: module.verifyReceivedQueueMessageEquals("queue", 1,
1277: new MockTextMessage("text1"));
1278: fail();
1279: } catch (VerifyFailedException exc) {
1280: //should throw exception
1281: }
1282: try {
1283: module.verifyCurrentQueueMessageEquals("queue", 3,
1284: testMessage);
1285: fail();
1286: } catch (VerifyFailedException exc) {
1287: //should throw exception
1288: }
1289: testMessage.setString("string2", "teststring");
1290: try {
1291: module.verifyCurrentQueueMessageEquals("queue", 2,
1292: testMessage);
1293: fail();
1294: } catch (VerifyFailedException exc) {
1295: //should throw exception
1296: }
1297: QueueReceiver receiver = module.getQueueSession(0)
1298: .createReceiver(manager.getQueue("queue"));
1299: receiver.receive();
1300: testMessage = new MockMapMessage();
1301: testMessage.setFloat("float1", 1.2f);
1302: testMessage.setString("string1", "teststring");
1303: try {
1304: module.verifyCurrentQueueMessageEquals("queue", 0,
1305: new MockTextMessage("text1"));
1306: fail();
1307: } catch (VerifyFailedException exc) {
1308: //should throw exception
1309: }
1310: module.verifyCurrentQueueMessageEquals("queue", 0,
1311: new MockObjectMessage(new Integer(1)));
1312: module.verifyCurrentQueueMessageEquals("queue", 1, testMessage);
1313: module.verifyReceivedQueueMessageEquals("queue", 0,
1314: new MockTextMessage("text1"));
1315: module.verifyReceivedQueueMessageEquals("queue", 1,
1316: new MockObjectMessage(new Integer(1)));
1317: module
1318: .verifyReceivedQueueMessageEquals("queue", 2,
1319: testMessage);
1320: receiver.receive();
1321: try {
1322: module.verifyCurrentQueueMessageEquals("queue", 0,
1323: new MockObjectMessage(new Integer(1)));
1324: fail();
1325: } catch (VerifyFailedException exc) {
1326: //should throw exception
1327: }
1328: module.verifyCurrentQueueMessageEquals("queue", 0, testMessage);
1329: module.verifyReceivedQueueMessageEquals("queue", 0,
1330: new MockTextMessage("text1"));
1331: module.verifyReceivedQueueMessageEquals("queue", 1,
1332: new MockObjectMessage(new Integer(1)));
1333: module
1334: .verifyReceivedQueueMessageEquals("queue", 2,
1335: testMessage);
1336: TemporaryQueue tempQueue = module.getQueueSession(0)
1337: .createTemporaryQueue();
1338: sender = module.getQueueSession(0).createSender(tempQueue);
1339: sender.send(message1);
1340: sender.send(message2);
1341: sender.send(message3);
1342: module.verifyCurrentQueueMessageEquals(0, 0, 0,
1343: new MockTextMessage("text1"));
1344: module.verifyCurrentQueueMessageEquals(0, 0, 1,
1345: new MockObjectMessage(new Integer(1)));
1346: module.verifyCurrentQueueMessageEquals(0, 0, 2, testMessage);
1347: module.verifyReceivedQueueMessageEquals(0, 0, 0,
1348: new MockTextMessage("text1"));
1349: module.verifyReceivedQueueMessageEquals(0, 0, 1,
1350: new MockObjectMessage(new Integer(1)));
1351: module.verifyReceivedQueueMessageEquals(0, 0, 2, testMessage);
1352: try {
1353: module.verifyCurrentQueueMessageEquals(0, 0, 0,
1354: new MockTextMessage("text2"));
1355: fail();
1356: } catch (VerifyFailedException exc) {
1357: //should throw exception
1358: }
1359: receiver = module.getQueueSession(0).createReceiver(tempQueue);
1360: receiver.receive();
1361: try {
1362: module.verifyCurrentQueueMessageEquals(0, 0, 0,
1363: new MockTextMessage("text1"));
1364: fail();
1365: } catch (VerifyFailedException exc) {
1366: //should throw exception
1367: }
1368: module.verifyCurrentQueueMessageEquals(0, 0, 0,
1369: new MockObjectMessage(new Integer(1)));
1370: module.verifyCurrentQueueMessageEquals(0, 0, 1, testMessage);
1371: module.verifyReceivedQueueMessageEquals(0, 0, 0,
1372: new MockTextMessage("text1"));
1373: module.verifyReceivedQueueMessageEquals(0, 0, 1,
1374: new MockObjectMessage(new Integer(1)));
1375: module.verifyReceivedQueueMessageEquals(0, 0, 2, testMessage);
1376: }
1377:
1378: public void testVerifyTopicMessageEquals() throws Exception {
1379: topicConnection.createTopicSession(true,
1380: Session.CLIENT_ACKNOWLEDGE);
1381: DestinationManager manager = mockFactory
1382: .getDestinationManager();
1383: manager.createTopic("topic");
1384: TopicPublisher publisher = module.getTopicSession(0)
1385: .createPublisher(manager.getTopic("topic"));
1386: ObjectMessage message1 = module.getTopicSession(0)
1387: .createObjectMessage();
1388: message1.setObject("testObject");
1389: ObjectMessage message2 = module.getTopicSession(0)
1390: .createObjectMessage();
1391: message2.setObject(new Integer(1));
1392: BytesMessage message3 = module.getTopicSession(0)
1393: .createBytesMessage();
1394: message3.writeInt(1);
1395: message3.writeInt(2);
1396: message3.writeInt(3);
1397: publisher.publish(message1);
1398: publisher.publish(message2);
1399: publisher.publish(message3);
1400: module.verifyCurrentTopicMessageEquals("topic", 0,
1401: new MockObjectMessage("testObject"));
1402: module.verifyCurrentTopicMessageEquals("topic", 1,
1403: new MockObjectMessage(new Integer(1)));
1404: module.verifyReceivedTopicMessageEquals("topic", 0,
1405: new MockObjectMessage("testObject"));
1406: module.verifyReceivedTopicMessageEquals("topic", 1,
1407: new MockObjectMessage(new Integer(1)));
1408: MockBytesMessage testMessage = new MockBytesMessage();
1409: testMessage.writeInt(1);
1410: testMessage.writeInt(2);
1411: testMessage.writeInt(3);
1412: module.verifyCurrentTopicMessageEquals("topic", 2, testMessage);
1413: module
1414: .verifyReceivedTopicMessageEquals("topic", 2,
1415: testMessage);
1416: try {
1417: module.verifyReceivedTopicMessageEquals("topic", 1,
1418: new MockObjectMessage("testObject"));
1419: fail();
1420: } catch (VerifyFailedException exc) {
1421: //should throw exception
1422: }
1423: try {
1424: module.verifyCurrentTopicMessageEquals("topic", 5,
1425: testMessage);
1426: fail();
1427: } catch (VerifyFailedException exc) {
1428: //should throw exception
1429: }
1430: testMessage.writeInt(4);
1431: try {
1432: module.verifyReceivedTopicMessageEquals("topic", 2,
1433: testMessage);
1434: fail();
1435: } catch (VerifyFailedException exc) {
1436: //should throw exception
1437: }
1438: TopicSubscriber subscriber = module.getTopicSession(0)
1439: .createSubscriber(manager.getTopic("topic"));
1440: subscriber.receive();
1441: testMessage = new MockBytesMessage();
1442: testMessage.writeInt(1);
1443: testMessage.writeInt(2);
1444: testMessage.writeInt(3);
1445: try {
1446: module.verifyCurrentTopicMessageEquals("topic", 0,
1447: new MockObjectMessage("testObject"));
1448: fail();
1449: } catch (VerifyFailedException exc) {
1450: //should throw exception
1451: }
1452: module.verifyCurrentTopicMessageEquals("topic", 0,
1453: new MockObjectMessage(new Integer(1)));
1454: module.verifyCurrentTopicMessageEquals("topic", 1, testMessage);
1455: module.verifyReceivedTopicMessageEquals("topic", 0,
1456: new MockObjectMessage("testObject"));
1457: module.verifyReceivedTopicMessageEquals("topic", 1,
1458: new MockObjectMessage(new Integer(1)));
1459: module
1460: .verifyReceivedTopicMessageEquals("topic", 2,
1461: testMessage);
1462: subscriber.receive();
1463: try {
1464: module.verifyCurrentTopicMessageEquals("topic", 0,
1465: new MockObjectMessage(new Integer(1)));
1466: fail();
1467: } catch (VerifyFailedException exc) {
1468: //should throw exception
1469: }
1470: module.verifyCurrentTopicMessageEquals("topic", 0, testMessage);
1471: module.verifyReceivedTopicMessageEquals("topic", 0,
1472: new MockObjectMessage("testObject"));
1473: module.verifyReceivedTopicMessageEquals("topic", 1,
1474: new MockObjectMessage(new Integer(1)));
1475: module
1476: .verifyReceivedTopicMessageEquals("topic", 2,
1477: testMessage);
1478: TemporaryTopic tempTopic = module.getTopicSession(0)
1479: .createTemporaryTopic();
1480: publisher = module.getTopicSession(0)
1481: .createPublisher(tempTopic);
1482: publisher.publish(message1);
1483: publisher.publish(message2);
1484: publisher.publish(message3);
1485: module.verifyCurrentTopicMessageEquals(0, 0, 0,
1486: new MockObjectMessage("testObject"));
1487: module.verifyCurrentTopicMessageEquals(0, 0, 1,
1488: new MockObjectMessage(new Integer(1)));
1489: module.verifyCurrentTopicMessageEquals(0, 0, 2, testMessage);
1490: module.verifyReceivedTopicMessageEquals(0, 0, 0,
1491: new MockObjectMessage("testObject"));
1492: module.verifyReceivedTopicMessageEquals(0, 0, 1,
1493: new MockObjectMessage(new Integer(1)));
1494: module.verifyReceivedTopicMessageEquals(0, 0, 2, testMessage);
1495: try {
1496: module.verifyCurrentTopicMessageEquals(0, 0, 0,
1497: new MockObjectMessage("TestObject"));
1498: fail();
1499: } catch (VerifyFailedException exc) {
1500: //should throw exception
1501: }
1502: subscriber = module.getTopicSession(0).createSubscriber(
1503: tempTopic);
1504: subscriber.receive();
1505: try {
1506: module.verifyCurrentTopicMessageEquals(0, 0, 0,
1507: new MockObjectMessage("testObject"));
1508: fail();
1509: } catch (VerifyFailedException exc) {
1510: //should throw exception
1511: }
1512: module.verifyCurrentTopicMessageEquals(0, 0, 0,
1513: new MockObjectMessage(new Integer(1)));
1514: module.verifyCurrentTopicMessageEquals(0, 0, 1, testMessage);
1515: module.verifyReceivedTopicMessageEquals(0, 0, 0,
1516: new MockObjectMessage("testObject"));
1517: module.verifyReceivedTopicMessageEquals(0, 0, 1,
1518: new MockObjectMessage(new Integer(1)));
1519: module.verifyReceivedTopicMessageEquals(0, 0, 2, testMessage);
1520: subscriber.receive();
1521: module.verifyCurrentTopicMessageEquals(0, 0, 0, testMessage);
1522: module.verifyReceivedTopicMessageEquals(0, 0, 0,
1523: new MockObjectMessage("testObject"));
1524: module.verifyReceivedTopicMessageEquals(0, 0, 1,
1525: new MockObjectMessage(new Integer(1)));
1526: module.verifyReceivedTopicMessageEquals(0, 0, 2, testMessage);
1527: }
1528:
1529: public void testVerifyMessageEqualsDifferentSessions()
1530: throws Exception {
1531: queueConnection.createQueueSession(true,
1532: Session.CLIENT_ACKNOWLEDGE);
1533: topicConnection.createTopicSession(true,
1534: Session.CLIENT_ACKNOWLEDGE);
1535: connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1536: DestinationManager manager = mockFactory
1537: .getDestinationManager();
1538: manager.createQueue("queue");
1539: manager.createTopic("topic");
1540: MockMessageProducer producer1 = (MockMessageProducer) module
1541: .getQueueSession(0).createProducer(
1542: manager.getQueue("queue"));
1543: MockMessageProducer producer2 = (MockMessageProducer) module
1544: .getTopicSession(0).createProducer(
1545: manager.getQueue("queue"));
1546: MockMessageProducer producer3 = (MockMessageProducer) module
1547: .getSession(0)
1548: .createProducer(manager.getQueue("queue"));
1549: MockMapMessage mapMessage = new MockMapMessage();
1550: mapMessage.setInt("prop", 1);
1551: producer1.send(new MockTextMessage("text"));
1552: producer2.send(new MockObjectMessage(new Integer(1)));
1553: producer3.send(mapMessage);
1554: module.verifyCurrentQueueMessageEquals("queue", 0,
1555: new MockTextMessage("text"));
1556: module.verifyCurrentQueueMessageEquals("queue", 1,
1557: new MockObjectMessage(new Integer(1)));
1558: module.verifyCurrentQueueMessageEquals("queue", 2, mapMessage);
1559: producer3 = (MockMessageProducer) module.getSession(0)
1560: .createProducer(manager.getTopic("topic"));
1561: producer3.send(mapMessage);
1562: module.verifyCurrentTopicMessageEquals("topic", 0, mapMessage);
1563: MockTemporaryQueue queue = (MockTemporaryQueue) module
1564: .getSession(0).createTemporaryQueue();
1565: producer3 = (MockMessageProducer) module.getSession(0)
1566: .createProducer(queue);
1567: producer3.send(new MockTextMessage("text"));
1568: try {
1569: module.verifyReceivedQueueMessageEquals(0, 0, 0,
1570: new MockTextMessage("text"));
1571: fail();
1572: } catch (VerifyFailedException e) {
1573: //should throw exception
1574: }
1575: assertEquals(1, queue.getReceivedMessageList().size());
1576: }
1577:
1578: public void testVerifyQueueClosed() throws Exception {
1579: MockQueueSession session1 = (MockQueueSession) queueConnection
1580: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1581: MockQueueSession session2 = (MockQueueSession) queueConnection
1582: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1583: MockQueueSession session3 = (MockQueueSession) queueConnection
1584: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1585: DestinationManager manager = mockFactory
1586: .getDestinationManager();
1587: Queue queue = manager.createQueue("queue");
1588: MockQueueSender sender1 = (MockQueueSender) session1
1589: .createSender(queue);
1590: session1.createSender(queue);
1591: session2.createSender(queue);
1592: MockQueueReceiver receiver1 = (MockQueueReceiver) session3
1593: .createReceiver(queue);
1594: MockQueueReceiver receiver2 = (MockQueueReceiver) session3
1595: .createReceiver(queue);
1596: session2.createBrowser(queue);
1597: sender1.close();
1598: receiver1.close();
1599: receiver2.close();
1600: module.verifyQueueSenderClosed(0, "queue", 0);
1601: module.verifyQueueReceiverClosed(2, "queue", 0);
1602: module.verifyQueueReceiverClosed(2, "queue", 1);
1603: module.verifyAllQueueReceiversClosed(2);
1604: module.verifyAllQueueBrowsersClosed(0);
1605: module.verifyAllQueueSendersClosed(2);
1606: module.verifyAllQueueReceiversClosed(1);
1607: try {
1608: module.verifyQueueConnectionClosed();
1609: fail();
1610: } catch (VerifyFailedException exc) {
1611: //should throw exception
1612: }
1613: try {
1614: module.verifyQueueSessionClosed(2);
1615: fail();
1616: } catch (VerifyFailedException exc) {
1617: //should throw exception
1618: }
1619: try {
1620: module.verifyAllQueueSessionsClosed();
1621: fail();
1622: } catch (VerifyFailedException exc) {
1623: //should throw exception
1624: }
1625: try {
1626: module.verifyQueueBrowserClosed(1, "queue", 0);
1627: fail();
1628: } catch (VerifyFailedException exc) {
1629: //should throw exception
1630: }
1631: try {
1632: module.verifyAllQueueBrowsersClosed(1);
1633: fail();
1634: } catch (VerifyFailedException exc) {
1635: //should throw exception
1636: }
1637: queueConnection.close();
1638: module.verifyQueueConnectionClosed();
1639: module.verifyAllQueueSessionsClosed();
1640: module.verifyAllQueueReceiversClosed(2);
1641: module.verifyAllQueueBrowsersClosed(1);
1642: module.verifyQueueBrowserClosed(1, "queue", 0);
1643: module.verifyAllQueueSendersClosed(0);
1644: module.verifyAllQueueSendersClosed(1);
1645: }
1646:
1647: public void testVerifyTopicClosed() throws Exception {
1648: MockTopicSession session1 = (MockTopicSession) topicConnection
1649: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1650: MockTopicSession session2 = (MockTopicSession) topicConnection
1651: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1652: MockTopicSession session3 = (MockTopicSession) topicConnection
1653: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1654: DestinationManager manager = mockFactory
1655: .getDestinationManager();
1656: Topic topic = manager.createTopic("topic");
1657: MockTopicPublisher publisher1 = (MockTopicPublisher) session1
1658: .createPublisher(topic);
1659: session2.createPublisher(topic);
1660: MockTopicSubscriber subscriber1 = (MockTopicSubscriber) session3
1661: .createSubscriber(topic);
1662: session3.createSubscriber(topic);
1663: session3.createDurableSubscriber(topic, "myDurable");
1664: publisher1.close();
1665: subscriber1.close();
1666: module.verifyTopicPublisherClosed(0, "topic", 0);
1667: module.verifyTopicSubscriberClosed(2, "topic", 0);
1668: module.verifyAllTopicPublishersClosed(2);
1669: module.verifyAllDurableTopicSubscribersClosed(0);
1670: try {
1671: module.verifyAllDurableTopicSubscribersClosed(2);
1672: fail();
1673: } catch (VerifyFailedException exc) {
1674: //should throw exception
1675: }
1676: try {
1677: module.verifyTopicConnectionClosed();
1678: fail();
1679: } catch (VerifyFailedException exc) {
1680: //should throw exception
1681: }
1682: try {
1683: module.verifyTopicSessionClosed(0);
1684: fail();
1685: } catch (VerifyFailedException exc) {
1686: //should throw exception
1687: }
1688: try {
1689: module.verifyAllTopicSessionsClosed();
1690: fail();
1691: } catch (VerifyFailedException exc) {
1692: //should throw exception
1693: }
1694: try {
1695: module.verifyTopicPublisherClosed(1, "topic", 0);
1696: fail();
1697: } catch (VerifyFailedException exc) {
1698: //should throw exception
1699: }
1700: try {
1701: module.verifyAllTopicPublishersClosed(1);
1702: fail();
1703: } catch (VerifyFailedException exc) {
1704: //should throw exception
1705: }
1706: topicConnection.close();
1707: module.verifyTopicConnectionClosed();
1708: module.verifyAllTopicSessionsClosed();
1709: module.verifyDurableTopicSubscriberClosed(2, "myDurable");
1710: module.verifyAllTopicSubscribersClosed(0);
1711: module.verifyAllTopicSubscribersClosed(1);
1712: module.verifyAllTopicSubscribersClosed(2);
1713: module.verifyAllTopicPublishersClosed(0);
1714: module.verifyAllTopicPublishersClosed(1);
1715: module.verifyAllTopicPublishersClosed(2);
1716: module.verifyAllDurableTopicSubscribersClosed(0);
1717: module.verifyAllDurableTopicSubscribersClosed(1);
1718: module.verifyAllDurableTopicSubscribersClosed(2);
1719: }
1720:
1721: public void testVerifyMessageProducersAndConsumersClosed()
1722: throws Exception {
1723: MockSession session1 = (MockSession) connection.createSession(
1724: true, Session.CLIENT_ACKNOWLEDGE);
1725: MockSession session2 = (MockSession) connection.createSession(
1726: true, Session.CLIENT_ACKNOWLEDGE);
1727: MockSession session3 = (MockSession) connection.createSession(
1728: true, Session.CLIENT_ACKNOWLEDGE);
1729: DestinationManager manager = mockFactory
1730: .getDestinationManager();
1731: Topic topic = manager.createTopic("topic");
1732: Queue queue = manager.createQueue("queue");
1733: MockMessageProducer producer1 = (MockMessageProducer) session1
1734: .createProducer(topic);
1735: session2.createProducer(null);
1736: MockMessageConsumer consumer1 = (MockMessageConsumer) session3
1737: .createConsumer(queue);
1738: session3.createConsumer(topic);
1739: session3.createDurableSubscriber(topic, "myDurable");
1740: producer1.close();
1741: module.verifyAllMessageProducersClosed(0);
1742: try {
1743: module.verifyAllMessageProducersClosed(1);
1744: fail();
1745: } catch (VerifyFailedException exc) {
1746: //should throw exception
1747: }
1748: module.verifyAllMessageConsumersClosed(0);
1749: consumer1.close();
1750: try {
1751: module.verifyAllMessageConsumersClosed(2);
1752: fail();
1753: } catch (VerifyFailedException exc) {
1754: //should throw exception
1755: }
1756: session1.close();
1757: session2.close();
1758: try {
1759: module.verifyAllSessionsClosed();
1760: fail();
1761: } catch (VerifyFailedException exc) {
1762: //should throw exception
1763: }
1764: queueConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1765: topicConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1766: session3.close();
1767: module.verifyAllSessionsClosed();
1768: module.verifyAllMessageProducersClosed(0);
1769: module.verifyAllMessageProducersClosed(1);
1770: module.verifyAllMessageProducersClosed(2);
1771: module.verifyAllMessageConsumersClosed(0);
1772: module.verifyAllMessageConsumersClosed(1);
1773: module.verifyAllMessageConsumersClosed(2);
1774: }
1775:
1776: public void testVerifyQueueSessionComitted() throws Exception {
1777: MockQueueSession session1 = (MockQueueSession) queueConnection
1778: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1779: MockQueueSession session2 = (MockQueueSession) queueConnection
1780: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1781: MockQueueSession session3 = (MockQueueSession) queueConnection
1782: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
1783: session1.commit();
1784: session2.rollback();
1785: module.verifyQueueSessionCommitted(0);
1786: module.verifyQueueSessionNotRecovered(0);
1787: module.verifyQueueSessionNotRolledBack(0);
1788: module.verifyQueueSessionNotCommitted(1);
1789: module.verifyQueueSessionRecovered(1);
1790: module.verifyQueueSessionRolledBack(1);
1791: module.verifyQueueSessionNotCommitted(2);
1792: module.verifyQueueSessionNotRecovered(2);
1793: module.verifyQueueSessionNotRolledBack(2);
1794: try {
1795: module.verifyQueueSessionNotCommitted(0);
1796: fail();
1797: } catch (VerifyFailedException exc) {
1798: //should throw exception
1799: }
1800: try {
1801: module.verifyQueueSessionRecovered(0);
1802: fail();
1803: } catch (VerifyFailedException exc) {
1804: //should throw exception
1805: }
1806: try {
1807: module.verifyQueueSessionRolledBack(2);
1808: fail();
1809: } catch (VerifyFailedException exc) {
1810: //should throw exception
1811: }
1812: try {
1813: module.verifyAllQueueSessionsCommitted();
1814: fail();
1815: } catch (VerifyFailedException exc) {
1816: //should throw exception
1817: }
1818: session2.commit();
1819: session3.commit();
1820: module.verifyQueueSessionCommitted(1);
1821: module.verifyAllQueueSessionsCommitted();
1822: try {
1823: module.verifyQueueSessionNotCommitted(2);
1824: fail();
1825: } catch (VerifyFailedException exc) {
1826: //should throw exception
1827: }
1828: try {
1829: module.verifyAllQueueSessionsRecovered();
1830: fail();
1831: } catch (VerifyFailedException exc) {
1832: //should throw exception
1833: }
1834: }
1835:
1836: public void testVerifyTopicSessionComitted() throws Exception {
1837: MockTopicSession session1 = (MockTopicSession) topicConnection
1838: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1839: MockTopicSession session2 = (MockTopicSession) topicConnection
1840: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1841: MockTopicSession session3 = (MockTopicSession) topicConnection
1842: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
1843: session1.commit();
1844: session2.rollback();
1845: module.verifyTopicSessionCommitted(0);
1846: module.verifyTopicSessionNotRecovered(0);
1847: module.verifyTopicSessionNotRolledBack(0);
1848: module.verifyTopicSessionNotCommitted(1);
1849: module.verifyTopicSessionRecovered(1);
1850: module.verifyTopicSessionRolledBack(1);
1851: module.verifyTopicSessionNotCommitted(2);
1852: module.verifyTopicSessionNotRecovered(2);
1853: module.verifyTopicSessionNotRolledBack(2);
1854: try {
1855: module.verifyTopicSessionRecovered(0);
1856: fail();
1857: } catch (VerifyFailedException exc) {
1858: //should throw exception
1859: }
1860: try {
1861: module.verifyTopicSessionNotRolledBack(1);
1862: fail();
1863: } catch (VerifyFailedException exc) {
1864: //should throw exception
1865: }
1866: try {
1867: module.verifyTopicSessionRolledBack(2);
1868: fail();
1869: } catch (VerifyFailedException exc) {
1870: //should throw exception
1871: }
1872: try {
1873: module.verifyAllTopicSessionsRolledBack();
1874: fail();
1875: } catch (VerifyFailedException exc) {
1876: //should throw exception
1877: }
1878: session2.commit();
1879: session3.commit();
1880: module.verifyTopicSessionCommitted(1);
1881: module.verifyTopicSessionCommitted(2);
1882: module.verifyAllTopicSessionsCommitted();
1883: module.verifyAllQueueSessionsCommitted();
1884: try {
1885: module.verifyTopicSessionNotCommitted(2);
1886: fail();
1887: } catch (VerifyFailedException exc) {
1888: //should throw exception
1889: }
1890: try {
1891: module.verifyAllTopicSessionsRecovered();
1892: fail();
1893: } catch (VerifyFailedException exc) {
1894: //should throw exception
1895: }
1896: }
1897:
1898: public void testVerifySessionComitted() throws Exception {
1899: MockSession session1 = (MockSession) connection.createSession(
1900: true, Session.CLIENT_ACKNOWLEDGE);
1901: MockSession session2 = (MockSession) connection.createSession(
1902: true, Session.CLIENT_ACKNOWLEDGE);
1903: MockSession session3 = (MockSession) connection.createSession(
1904: true, Session.CLIENT_ACKNOWLEDGE);
1905: queueConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1906: topicConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
1907: session1.commit();
1908: session2.rollback();
1909: module.verifySessionCommitted(0);
1910: module.verifySessionNotRecovered(0);
1911: module.verifySessionNotRolledBack(0);
1912: module.verifySessionNotCommitted(1);
1913: module.verifySessionRecovered(1);
1914: module.verifySessionRolledBack(1);
1915: module.verifySessionNotCommitted(2);
1916: module.verifySessionNotRecovered(2);
1917: module.verifySessionNotRolledBack(2);
1918: try {
1919: module.verifySessionNotCommitted(0);
1920: fail();
1921: } catch (VerifyFailedException exc) {
1922: //should throw exception
1923: }
1924: try {
1925: module.verifySessionRecovered(0);
1926: fail();
1927: } catch (VerifyFailedException exc) {
1928: //should throw exception
1929: }
1930: try {
1931: module.verifySessionRolledBack(2);
1932: fail();
1933: } catch (VerifyFailedException exc) {
1934: //should throw exception
1935: }
1936: try {
1937: module.verifyAllSessionsCommitted();
1938: fail();
1939: } catch (VerifyFailedException exc) {
1940: //should throw exception
1941: }
1942: session2.commit();
1943: session3.commit();
1944: module.verifySessionCommitted(1);
1945: module.verifyAllSessionsCommitted();
1946: try {
1947: module.verifySessionNotCommitted(2);
1948: fail();
1949: } catch (VerifyFailedException exc) {
1950: //should throw exception
1951: }
1952: try {
1953: module.verifyAllSessionsRecovered();
1954: fail();
1955: } catch (VerifyFailedException exc) {
1956: //should throw exception
1957: }
1958: try {
1959: module.verifyAllQueueSessionsCommitted();
1960: fail();
1961: } catch (VerifyFailedException exc) {
1962: //should throw exception
1963: }
1964: try {
1965: module.verifyAllTopicSessionsCommitted();
1966: fail();
1967: } catch (VerifyFailedException exc) {
1968: //should throw exception
1969: }
1970: }
1971:
1972: public void testVerifyNumberCommitsAndRollbacks() throws Exception {
1973: MockSession session1 = (MockSession) queueConnection
1974: .createSession(true, Session.CLIENT_ACKNOWLEDGE);
1975: MockSession session2 = (MockSession) connection.createSession(
1976: true, Session.CLIENT_ACKNOWLEDGE);
1977: MockSession session3 = (MockSession) topicConnection
1978: .createSession(true, Session.CLIENT_ACKNOWLEDGE);
1979: MockSession session4 = (MockSession) topicConnection
1980: .createSession(true, Session.CLIENT_ACKNOWLEDGE);
1981: session1.commit();
1982: session1.commit();
1983: session2.rollback();
1984: session3.commit();
1985: session3.rollback();
1986: session3.rollback();
1987: session3.rollback();
1988: session4.commit();
1989: module.verifyQueueSessionNumberCommits(0, 2);
1990: module.verifyQueueSessionNumberRollbacks(0, 0);
1991: module.verifyTopicSessionNumberCommits(0, 1);
1992: module.verifyTopicSessionNumberRollbacks(0, 3);
1993: module.verifyTopicSessionNumberCommits(1, 1);
1994: module.verifyTopicSessionNumberRollbacks(1, 0);
1995: module.verifySessionNumberCommits(0, 0);
1996: module.verifySessionNumberRollbacks(0, 1);
1997: try {
1998: module.verifyQueueSessionNumberCommits(0, 1);
1999: fail();
2000: } catch (VerifyFailedException exc) {
2001: //should throw exception
2002: }
2003: try {
2004: module.verifySessionNumberCommits(0, 2);
2005: fail();
2006: } catch (VerifyFailedException exc) {
2007: //should throw exception
2008: }
2009: try {
2010: module.verifyTopicSessionNumberRollbacks(1, 3);
2011: fail();
2012: } catch (VerifyFailedException exc) {
2013: //should throw exception
2014: }
2015: try {
2016: module.verifyQueueSessionNumberRollbacks(2, 0);
2017: fail();
2018: } catch (VerifyFailedException exc) {
2019: //should throw exception
2020: }
2021: }
2022:
2023: public void testVerifyQueueMessagesAcknowledged() throws Exception {
2024: MockQueueSession session1 = (MockQueueSession) queueConnection
2025: .createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
2026: MockQueueSession session2 = (MockQueueSession) queueConnection
2027: .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
2028: DestinationManager manager = mockFactory
2029: .getDestinationManager();
2030: Queue queue = manager.createQueue("queue");
2031: MockQueueSender sender1 = (MockQueueSender) session1
2032: .createSender(queue);
2033: MockQueueSender sender2 = (MockQueueSender) session2
2034: .createSender(queue);
2035: MockQueueReceiver receiver1 = (MockQueueReceiver) session1
2036: .createReceiver(queue);
2037: MockQueueReceiver receiver2 = (MockQueueReceiver) session2
2038: .createReceiver(queue);
2039: MockMessage message1 = (MockMessage) session1
2040: .createTextMessage();
2041: MockMessage message2 = (MockMessage) session1
2042: .createMapMessage();
2043: MockMessage message3 = (MockMessage) session1
2044: .createObjectMessage();
2045: MockMessage message4 = (MockMessage) session2
2046: .createBytesMessage();
2047: MockMessage message5 = (MockMessage) session2
2048: .createStreamMessage();
2049: MockMessage message6 = (MockMessage) session2.createMessage();
2050: module.verifyCreatedQueueTextMessageNotAcknowledged(0, 0);
2051: module.verifyCreatedQueueMapMessageNotAcknowledged(0, 0);
2052: module.verifyCreatedQueueObjectMessageNotAcknowledged(0, 0);
2053: module.verifyCreatedQueueBytesMessageNotAcknowledged(1, 0);
2054: module.verifyCreatedQueueStreamMessageNotAcknowledged(1, 0);
2055: module.verifyCreatedQueueMessageNotAcknowledged(1, 0);
2056: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2057: try {
2058: module.verifyCreatedQueueTextMessageAcknowledged(0, 0);
2059: fail();
2060: } catch (VerifyFailedException exc) {
2061: //should throw exception
2062: }
2063: try {
2064: module.verifyCreatedQueueMessageAcknowledged(1, 0);
2065: fail();
2066: } catch (VerifyFailedException exc) {
2067: //should throw exception
2068: }
2069: try {
2070: module.verifyCreatedQueueMessageAcknowledged(1, 2);
2071: fail();
2072: } catch (VerifyFailedException exc) {
2073: //should throw exception
2074: }
2075: try {
2076: module.verifyCreatedQueueMessageNotAcknowledged(2, 0);
2077: fail();
2078: } catch (VerifyFailedException exc) {
2079: //should throw exception
2080: }
2081: sender1.send(message1);
2082: sender1.send(message2);
2083: sender1.send(message3);
2084: sender2.send(message4);
2085: sender2.send(message5);
2086: sender2.send(message6);
2087: module.verifyCreatedQueueTextMessageNotAcknowledged(0, 0);
2088: module.verifyCreatedQueueMapMessageNotAcknowledged(0, 0);
2089: module.verifyCreatedQueueObjectMessageNotAcknowledged(0, 0);
2090: module.verifyCreatedQueueBytesMessageNotAcknowledged(1, 0);
2091: module.verifyCreatedQueueStreamMessageNotAcknowledged(1, 0);
2092: module.verifyCreatedQueueMessageNotAcknowledged(1, 0);
2093: try {
2094: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2095: fail();
2096: } catch (VerifyFailedException exc) {
2097: //should throw exception
2098: }
2099: receiver1.receive();
2100: receiver1.receive();
2101: receiver1.receive();
2102: receiver2.receive();
2103: receiver2.receive();
2104: receiver2.receive();
2105: module.verifyCreatedQueueTextMessageNotAcknowledged(0, 0);
2106: module.verifyCreatedQueueMapMessageNotAcknowledged(0, 0);
2107: module.verifyCreatedQueueObjectMessageNotAcknowledged(0, 0);
2108: module.verifyCreatedQueueBytesMessageAcknowledged(1, 0);
2109: module.verifyCreatedQueueStreamMessageAcknowledged(1, 0);
2110: module.verifyCreatedQueueMessageAcknowledged(1, 0);
2111: ((MockQueue) queue).reset();
2112: message1 = (MockMessage) session1.createObjectMessage();
2113: message2 = (MockMessage) session1.createMessage();
2114: receiver1.setMessageListener(new TestMessageListener(true));
2115: sender1.send(message1);
2116: sender1.send(message2);
2117: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2118: module.verifyCreatedQueueObjectMessageAcknowledged(0, 1);
2119: module.verifyCreatedQueueMessageAcknowledged(0, 0);
2120: message1 = (MockMessage) session2.createTextMessage();
2121: message2 = (MockMessage) session2.createTextMessage();
2122: receiver2.setMessageListener(new TestMessageListener(false));
2123: sender2.send(message1);
2124: sender2.send(message2);
2125: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2126: module.verifyCreatedQueueTextMessageAcknowledged(1, 1);
2127: module.verifyCreatedQueueTextMessageAcknowledged(1, 1);
2128: TemporaryQueue tempQueue = session2.createTemporaryQueue();
2129: message1 = (MockMessage) session2.createTextMessage();
2130: MockQueueSender sender3 = (MockQueueSender) session2
2131: .createSender(tempQueue);
2132: MockQueueReceiver receiver3 = (MockQueueReceiver) session2
2133: .createReceiver(tempQueue);
2134: sender3.send(message1);
2135: module.verifyReceivedQueueMessageNotAcknowledged(1, 0, 0);
2136: try {
2137: module.verifyReceivedQueueMessageAcknowledged(1, 0, 0);
2138: fail();
2139: } catch (VerifyFailedException exc) {
2140: //should throw exception
2141: }
2142: try {
2143: module.verifyAllReceivedQueueMessagesAcknowledged(1, 0);
2144: fail();
2145: } catch (VerifyFailedException exc) {
2146: //should throw exception
2147: }
2148: receiver3.receive();
2149: module.verifyReceivedQueueMessageAcknowledged(1, 0, 0);
2150: receiver3.setMessageListener(new TestMessageListener(false));
2151: message1 = (MockMessage) session2.createTextMessage();
2152: sender3.send(message1);
2153: module.verifyReceivedQueueMessageAcknowledged(1, 0, 1);
2154: module.verifyAllReceivedQueueMessagesAcknowledged(1, 0);
2155: }
2156:
2157: public void testVerifyTopicMessagesAcknowledged() throws Exception {
2158: MockTopicSession session1 = (MockTopicSession) topicConnection
2159: .createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
2160: MockTopicSession session2 = (MockTopicSession) topicConnection
2161: .createTopicSession(true, Session.DUPS_OK_ACKNOWLEDGE);
2162: DestinationManager manager = mockFactory
2163: .getDestinationManager();
2164: Topic topic = manager.createTopic("topic");
2165: MockTopicPublisher publisher1 = (MockTopicPublisher) session1
2166: .createPublisher(topic);
2167: MockTopicPublisher publisher2 = (MockTopicPublisher) session2
2168: .createPublisher(topic);
2169: MockTopicSubscriber subscriber1 = (MockTopicSubscriber) session1
2170: .createSubscriber(topic);
2171: MockTopicSubscriber subscriber2 = (MockTopicSubscriber) session2
2172: .createSubscriber(topic);
2173: MockMessage message1 = (MockMessage) session1
2174: .createTextMessage();
2175: MockMessage message2 = (MockMessage) session2
2176: .createMapMessage();
2177: MockMessage message3 = (MockMessage) session2
2178: .createObjectMessage();
2179: MockMessage message4 = (MockMessage) session2
2180: .createBytesMessage();
2181: MockMessage message5 = (MockMessage) session2
2182: .createStreamMessage();
2183: MockMessage message6 = (MockMessage) session2.createMessage();
2184: module.verifyCreatedTopicTextMessageNotAcknowledged(0, 0);
2185: module.verifyCreatedTopicMapMessageNotAcknowledged(1, 0);
2186: module.verifyCreatedTopicObjectMessageNotAcknowledged(1, 0);
2187: module.verifyCreatedTopicBytesMessageNotAcknowledged(1, 0);
2188: module.verifyCreatedTopicStreamMessageNotAcknowledged(1, 0);
2189: module.verifyCreatedTopicMessageNotAcknowledged(1, 0);
2190: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2191: try {
2192: module.verifyCreatedTopicTextMessageAcknowledged(1, 0);
2193: fail();
2194: } catch (VerifyFailedException exc) {
2195: //should throw exception
2196: }
2197: try {
2198: module.verifyCreatedTopicMessageAcknowledged(1, 0);
2199: fail();
2200: } catch (VerifyFailedException exc) {
2201: //should throw exception
2202: }
2203: try {
2204: module.verifyCreatedTopicMessageAcknowledged(1, 1);
2205: fail();
2206: } catch (VerifyFailedException exc) {
2207: //should throw exception
2208: }
2209: try {
2210: module.verifyCreatedTopicMessageNotAcknowledged(2, 0);
2211: fail();
2212: } catch (VerifyFailedException exc) {
2213: //should throw exception
2214: }
2215: publisher1.publish(message1);
2216: publisher2.publish(message2);
2217: publisher2.publish(message3);
2218: publisher2.publish(message4);
2219: publisher2.publish(message5);
2220: publisher2.publish(message6);
2221: module.verifyCreatedTopicTextMessageNotAcknowledged(0, 0);
2222: module.verifyCreatedTopicMapMessageNotAcknowledged(1, 0);
2223: module.verifyCreatedTopicObjectMessageNotAcknowledged(1, 0);
2224: module.verifyCreatedTopicBytesMessageNotAcknowledged(1, 0);
2225: module.verifyCreatedTopicStreamMessageNotAcknowledged(1, 0);
2226: module.verifyCreatedTopicMessageNotAcknowledged(1, 0);
2227: try {
2228: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2229: fail();
2230: } catch (VerifyFailedException exc) {
2231: //should throw exception
2232: }
2233: subscriber1.receive();
2234: subscriber2.receive();
2235: subscriber2.receive();
2236: subscriber2.receive();
2237: subscriber2.receive();
2238: module.verifyCreatedTopicTextMessageNotAcknowledged(0, 0);
2239: module.verifyCreatedTopicMapMessageAcknowledged(1, 0);
2240: module.verifyCreatedTopicObjectMessageAcknowledged(1, 0);
2241: module.verifyCreatedTopicBytesMessageAcknowledged(1, 0);
2242: module.verifyCreatedTopicStreamMessageAcknowledged(1, 0);
2243: module.verifyCreatedTopicMessageNotAcknowledged(1, 0);
2244: ((MockTopic) topic).reset();
2245: message1 = (MockTextMessage) session1.createTextMessage();
2246: message2 = (MockTextMessage) session1.createTextMessage();
2247: subscriber1.setMessageListener(new TestMessageListener(true));
2248: publisher1.publish(message1);
2249: publisher1.publish(message2);
2250: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2251: module.verifyCreatedTopicTextMessageAcknowledged(0, 1);
2252: module.verifyCreatedTopicTextMessageAcknowledged(0, 2);
2253: message1 = (MockMessage) session2.createTextMessage();
2254: message2 = (MockMessage) session2.createTextMessage();
2255: subscriber2.setMessageListener(new TestMessageListener(false));
2256: publisher2.publish(message1);
2257: publisher2.publish(message2);
2258: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2259: module.verifyCreatedTopicTextMessageAcknowledged(1, 0);
2260: module.verifyCreatedTopicTextMessageAcknowledged(1, 1);
2261: TemporaryTopic tempTopic = session2.createTemporaryTopic();
2262: message1 = (MockMessage) session2.createObjectMessage();
2263: MockTopicPublisher publisher3 = (MockTopicPublisher) session2
2264: .createPublisher(tempTopic);
2265: MockTopicSubscriber subscriber3 = (MockTopicSubscriber) session2
2266: .createSubscriber(tempTopic);
2267: publisher3.publish(message1);
2268: module.verifyReceivedTopicMessageNotAcknowledged(1, 0, 0);
2269: try {
2270: module.verifyReceivedTopicMessageAcknowledged(1, 0, 0);
2271: fail();
2272: } catch (VerifyFailedException exc) {
2273: //should throw exception
2274: }
2275: try {
2276: module.verifyAllReceivedTopicMessagesAcknowledged(1, 0);
2277: fail();
2278: } catch (VerifyFailedException exc) {
2279: //should throw exception
2280: }
2281: subscriber3.receive();
2282: module.verifyReceivedTopicMessageAcknowledged(1, 0, 0);
2283: subscriber3.setMessageListener(new TestMessageListener(false));
2284: message1 = (MockMessage) session2.createTextMessage();
2285: publisher3.publish(message1);
2286: module.verifyReceivedTopicMessageAcknowledged(1, 0, 1);
2287: module.verifyAllReceivedTopicMessagesAcknowledged(1, 0);
2288: }
2289:
2290: public void testVerifyMessagesAcknowledged() throws Exception {
2291: MockSession session1 = (MockSession) connection.createSession(
2292: true, Session.AUTO_ACKNOWLEDGE);
2293: MockSession session2 = (MockSession) connection.createSession(
2294: true, Session.CLIENT_ACKNOWLEDGE);
2295: MockSession session3 = (MockSession) connection.createSession(
2296: true, Session.DUPS_OK_ACKNOWLEDGE);
2297: queueConnection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
2298: topicConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
2299: DestinationManager manager = mockFactory
2300: .getDestinationManager();
2301: Queue queue = manager.createQueue("queue");
2302: Topic topic = manager.createTopic("topic");
2303: MockMessage message1 = (MockMessage) session1
2304: .createTextMessage();
2305: MockMessage message2 = (MockMessage) session2
2306: .createMapMessage();
2307: MockMessage message3 = (MockMessage) session2
2308: .createObjectMessage();
2309: MockMessage message4 = (MockMessage) session3
2310: .createBytesMessage();
2311: MockMessage message5 = (MockMessage) session3
2312: .createStreamMessage();
2313: MockMessage message6 = (MockMessage) session3.createMessage();
2314: module.verifyCreatedTextMessageNotAcknowledged(0, 0);
2315: module.verifyCreatedMapMessageNotAcknowledged(1, 0);
2316: module.verifyCreatedObjectMessageNotAcknowledged(1, 0);
2317: module.verifyCreatedBytesMessageNotAcknowledged(2, 0);
2318: module.verifyCreatedStreamMessageNotAcknowledged(2, 0);
2319: module.verifyCreatedMessageNotAcknowledged(2, 0);
2320: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2321: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2322: try {
2323: module.verifyCreatedTextMessageAcknowledged(1, 0);
2324: fail();
2325: } catch (VerifyFailedException exc) {
2326: //should throw exception
2327: }
2328: try {
2329: module.verifyCreatedMessageAcknowledged(1, 0);
2330: fail();
2331: } catch (VerifyFailedException exc) {
2332: //should throw exception
2333: }
2334: try {
2335: module.verifyCreatedMessageAcknowledged(1, 1);
2336: fail();
2337: } catch (VerifyFailedException exc) {
2338: //should throw exception
2339: }
2340: try {
2341: module.verifyCreatedMessageNotAcknowledged(3, 0);
2342: fail();
2343: } catch (VerifyFailedException exc) {
2344: //should throw exception
2345: }
2346: MockMessageProducer producer1 = (MockMessageProducer) session1
2347: .createProducer(queue);
2348: MockMessageProducer producer2 = (MockMessageProducer) session2
2349: .createProducer(topic);
2350: MockMessageProducer producer3 = (MockMessageProducer) session3
2351: .createProducer(topic);
2352: MockMessageConsumer consumer1 = (MockMessageConsumer) session1
2353: .createConsumer(queue);
2354: MockMessageConsumer consumer2 = (MockMessageConsumer) session2
2355: .createConsumer(topic);
2356: producer1.send(message1);
2357: producer1.send(message2);
2358: producer2.send(message3);
2359: producer2.send(message4);
2360: producer3.send(message5);
2361: producer3.send(message6);
2362: module.verifyCreatedTextMessageNotAcknowledged(0, 0);
2363: module.verifyCreatedMapMessageNotAcknowledged(1, 0);
2364: module.verifyCreatedObjectMessageNotAcknowledged(1, 0);
2365: module.verifyCreatedBytesMessageNotAcknowledged(2, 0);
2366: module.verifyCreatedStreamMessageNotAcknowledged(2, 0);
2367: module.verifyCreatedMessageNotAcknowledged(2, 0);
2368: try {
2369: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2370: fail();
2371: } catch (VerifyFailedException exc) {
2372: //should throw exception
2373: }
2374: try {
2375: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2376: fail();
2377: } catch (VerifyFailedException exc) {
2378: //should throw exception
2379: }
2380: consumer1.receive();
2381: consumer1.receive();
2382: module.verifyAllReceivedQueueMessagesAcknowledged("queue");
2383: consumer2.receive();
2384: consumer2.receive();
2385: consumer2.receive();
2386: consumer2.receive();
2387: try {
2388: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2389: fail();
2390: } catch (VerifyFailedException exc) {
2391: //should throw exception
2392: }
2393: message3.acknowledge();
2394: message4.acknowledge();
2395: message5.acknowledge();
2396: message6.acknowledge();
2397: module.verifyAllReceivedTopicMessagesAcknowledged("topic");
2398: module.verifyCreatedTextMessageAcknowledged(0, 0);
2399: module.verifyCreatedMapMessageAcknowledged(1, 0);
2400: module.verifyCreatedObjectMessageAcknowledged(1, 0);
2401: module.verifyCreatedBytesMessageAcknowledged(2, 0);
2402: module.verifyCreatedStreamMessageAcknowledged(2, 0);
2403: module.verifyCreatedMessageAcknowledged(2, 0);
2404: }
2405:
2406: public void testGenericFactory() throws Exception {
2407: MockConnectionFactory factory = (MockConnectionFactory) mockFactory
2408: .getMockConnectionFactory();
2409: QueueConnection queueConnection = factory
2410: .createQueueConnection();
2411: TopicConnection topicConnection = factory
2412: .createTopicConnection();
2413: MockConnection connection = (MockConnection) factory
2414: .createConnection();
2415: queueConnection.createQueueSession(true,
2416: Session.AUTO_ACKNOWLEDGE);
2417: topicConnection.createTopicSession(true,
2418: Session.AUTO_ACKNOWLEDGE);
2419: topicConnection.createTopicSession(true,
2420: Session.AUTO_ACKNOWLEDGE);
2421: connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
2422: module.verifyNumberSessions(1);
2423: module.setCurrentConnectionIndex(1);
2424: module.verifyNumberSessions(1);
2425: module.setCurrentConnectionIndex(2);
2426: module.verifyNumberSessions(2);
2427: module.setCurrentConnectionIndex(3);
2428: module.verifyNumberSessions(1);
2429: module.setCurrentConnectionIndex(0);
2430: module.verifyNumberSessions(0);
2431: }
2432:
2433: public void testVerifyQueueSenderWithGenericProducers()
2434: throws Exception {
2435: DestinationManager manager = mockFactory
2436: .getDestinationManager();
2437: Queue queue = manager.createQueue("queue");
2438: MockQueueSession session = (MockQueueSession) queueConnection
2439: .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
2440: QueueSender sender1 = session.createSender(queue);
2441: QueueSender sender2 = (QueueSender) session
2442: .createProducer(queue);
2443: QueueSender sender3 = (QueueSender) session
2444: .createProducer(null);
2445: QueueSender sender4 = session.createSender(queue);
2446: QueueSender sender5 = session.createSender(null);
2447: module.verifyNumberQueueSenders(0, 5);
2448: module.verifyNumberQueueSenders(0, "queue", 3);
2449: sender3.close();
2450: sender4.close();
2451: try {
2452: module.verifyAllQueueSendersClosed(0);
2453: fail();
2454: } catch (VerifyFailedException exc) {
2455: //should throw exception
2456: }
2457: session.close();
2458: module.verifyAllQueueSendersClosed(0);
2459: TransmissionManagerWrapper wrapper = module
2460: .getQueueTransmissionManagerWrapper(0);
2461: assertEquals(5, wrapper.getMessageProducerList().size());
2462: assertEquals(5, wrapper.getQueueSenderList().size());
2463: assertTrue(wrapper.getQueueSenderList().contains(sender1));
2464: assertTrue(wrapper.getQueueSenderList().contains(sender2));
2465: assertTrue(wrapper.getQueueSenderList().contains(sender3));
2466: assertTrue(wrapper.getQueueSenderList().contains(sender4));
2467: assertTrue(wrapper.getQueueSenderList().contains(sender5));
2468: }
2469:
2470: public void testVerifyTopicPublishersWithGenericProducers()
2471: throws Exception {
2472: DestinationManager manager = mockFactory
2473: .getDestinationManager();
2474: Topic topic = manager.createTopic("topic");
2475: MockTopicSession session1 = (MockTopicSession) topicConnection
2476: .createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
2477: MockTopicSession session2 = (MockTopicSession) topicConnection
2478: .createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
2479: TopicPublisher publisher1 = (TopicPublisher) session1
2480: .createProducer(topic);
2481: TopicPublisher publisher2 = session1.createPublisher(null);
2482: TopicPublisher publisher3 = session2.createPublisher(null);
2483: TopicPublisher publisher4 = (TopicPublisher) session2
2484: .createProducer(null);
2485: TopicPublisher publisher5 = (TopicPublisher) session2
2486: .createProducer(topic);
2487: module.verifyNumberTopicPublishers(0, 2);
2488: module.verifyNumberTopicPublishers(1, 3);
2489: module.verifyNumberTopicPublishers(0, "topic", 1);
2490: module.verifyNumberTopicPublishers(1, "topic", 1);
2491: publisher1.close();
2492: try {
2493: module.verifyAllTopicPublishersClosed(0);
2494: fail();
2495: } catch (VerifyFailedException exc) {
2496: //should throw exception
2497: }
2498: publisher2.close();
2499: module.verifyAllTopicPublishersClosed(0);
2500: session2.close();
2501: module.verifyAllTopicPublishersClosed(1);
2502: TransmissionManagerWrapper wrapper = module
2503: .getTopicTransmissionManagerWrapper(1);
2504: assertEquals(3, wrapper.getMessageProducerList().size());
2505: assertEquals(3, wrapper.getTopicPublisherList().size());
2506: assertTrue(wrapper.getTopicPublisherList().contains(publisher3));
2507: assertTrue(wrapper.getTopicPublisherList().contains(publisher4));
2508: assertTrue(wrapper.getTopicPublisherList().contains(publisher5));
2509: }
2510:
2511: public void testSessionsClosedNoConnection() throws Exception {
2512: JMSMockObjectFactory mockFactory = new JMSMockObjectFactory();
2513: JMSTestModule module = new JMSTestModule(mockFactory);
2514: module.verifyAllQueueSessionsClosed();
2515: module.verifyAllQueueSessionsCommitted();
2516: module.verifyAllQueueSessionsRecovered();
2517: module.verifyAllQueueSessionsRolledBack();
2518: module.verifyAllTopicSessionsClosed();
2519: module.verifyAllTopicSessionsCommitted();
2520: module.verifyAllTopicSessionsRecovered();
2521: module.verifyAllTopicSessionsRolledBack();
2522: module.verifyAllSessionsClosed();
2523: module.verifyAllSessionsCommitted();
2524: module.verifyAllSessionsRecovered();
2525: module.verifyAllSessionsRolledBack();
2526: }
2527:
2528: public static class TestMessageListener implements MessageListener {
2529: private Message message;
2530: private boolean doAcknowledge;
2531:
2532: public TestMessageListener(boolean doAcknowledge) {
2533: this .doAcknowledge = doAcknowledge;
2534: }
2535:
2536: public Message getMessage() {
2537: return message;
2538: }
2539:
2540: public void reset() {
2541: message = null;
2542: }
2543:
2544: public void onMessage(Message message) {
2545: this .message = message;
2546: try {
2547: if (doAcknowledge)
2548: message.acknowledge();
2549: } catch (JMSException exc) {
2550: exc.printStackTrace();
2551: throw new RuntimeException("Unexpected failure");
2552: }
2553: }
2554: }
2555: }
|