Source Code Cross Referenced for MockSessionTest.java in  » Testing » mockrunner-0.4 » com » mockrunner » test » jms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » mockrunner 0.4 » com.mockrunner.test.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.test.jms;
002:
003:        import java.util.List;
004:
005:        import javax.jms.DeliveryMode;
006:        import javax.jms.Destination;
007:        import javax.jms.InvalidDestinationException;
008:        import javax.jms.Message;
009:        import javax.jms.MessageConsumer;
010:        import javax.jms.MessageListener;
011:        import javax.jms.MessageProducer;
012:        import javax.jms.QueueSender;
013:        import javax.jms.Session;
014:
015:        import junit.framework.TestCase;
016:
017:        import com.mockrunner.jms.ConfigurationManager;
018:        import com.mockrunner.jms.DestinationManager;
019:        import com.mockrunner.jms.GenericTransmissionManager;
020:        import com.mockrunner.jms.QueueTransmissionManager;
021:        import com.mockrunner.jms.TopicTransmissionManager;
022:        import com.mockrunner.mock.jms.MockConnection;
023:        import com.mockrunner.mock.jms.MockMessage;
024:        import com.mockrunner.mock.jms.MockMessageProducer;
025:        import com.mockrunner.mock.jms.MockQueue;
026:        import com.mockrunner.mock.jms.MockQueueConnection;
027:        import com.mockrunner.mock.jms.MockQueueReceiver;
028:        import com.mockrunner.mock.jms.MockQueueSender;
029:        import com.mockrunner.mock.jms.MockQueueSession;
030:        import com.mockrunner.mock.jms.MockSession;
031:        import com.mockrunner.mock.jms.MockTextMessage;
032:        import com.mockrunner.mock.jms.MockTopic;
033:        import com.mockrunner.mock.jms.MockTopicConnection;
034:        import com.mockrunner.mock.jms.MockTopicPublisher;
035:        import com.mockrunner.mock.jms.MockTopicSession;
036:        import com.mockrunner.mock.jms.MockTopicSubscriber;
037:
038:        public class MockSessionTest extends TestCase {
039:            public void testTransmissionJMSHeaders() throws Exception {
040:                DestinationManager destManager = new DestinationManager();
041:                ConfigurationManager confManager = new ConfigurationManager();
042:                MockQueueConnection connection = new MockQueueConnection(
043:                        destManager, confManager);
044:                MockQueueSession session = (MockQueueSession) connection
045:                        .createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
046:                destManager.createQueue("Queue1");
047:                MockQueue queue = (MockQueue) session.createQueue("Queue1");
048:                QueueSender sender = session.createSender(queue);
049:                MockMessage message = new MockTextMessage("Text1");
050:                message.setJMSTimestamp(0);
051:                sender.setDisableMessageTimestamp(true);
052:                sender.setDisableMessageID(true);
053:                sender.setTimeToLive(0);
054:                sender.setPriority(9);
055:                sender.setDeliveryMode(DeliveryMode.PERSISTENT);
056:                sender.send(message);
057:                message = (MockMessage) queue.getMessage();
058:                assertEquals(0, message.getJMSTimestamp());
059:                assertNull(message.getJMSMessageID());
060:                assertEquals(0, message.getJMSExpiration());
061:                assertEquals(9, message.getJMSPriority());
062:                assertEquals(DeliveryMode.PERSISTENT, message
063:                        .getJMSDeliveryMode());
064:                assertEquals(queue, message.getJMSDestination());
065:                message.setJMSMessageID("xyz");
066:                sender.send(message);
067:                message = (MockMessage) queue.getMessage();
068:                assertEquals("xyz", message.getJMSMessageID());
069:                message = new MockTextMessage("Text1");
070:                sender.setDisableMessageTimestamp(false);
071:                sender.setDisableMessageID(false);
072:                sender.setPriority(7);
073:                sender.send(message);
074:                message = (MockMessage) queue.getMessage();
075:                assertFalse(0 == message.getJMSTimestamp());
076:                assertFalse("xyz".equals(message.getJMSMessageID()));
077:                assertEquals(7, message.getJMSPriority());
078:                assertEquals(queue, message.getJMSDestination());
079:                message = new MockTextMessage("Text1");
080:                sender.setTimeToLive(10000);
081:                sender.send(message);
082:                message = (MockMessage) queue.getMessage();
083:                assertEquals(message.getJMSTimestamp() + 10000, message
084:                        .getJMSExpiration());
085:                assertEquals(queue, message.getJMSDestination());
086:                message = new MockTextMessage("Text1");
087:                sender.setTimeToLive(0);
088:                sender.send(message);
089:                message = (MockMessage) queue.getMessage();
090:                assertEquals(0, message.getJMSExpiration());
091:                assertEquals(queue, message.getJMSDestination());
092:                message = new MockTextMessage("Text1");
093:                destManager.createTopic("Topic1");
094:                MockTopic topic = (MockTopic) session.createTopic("Topic1");
095:                ((MockMessageProducer) sender).send(topic, message);
096:                assertEquals(topic, message.getJMSDestination());
097:            }
098:
099:            public void testGetAcknowledgeMode() throws Exception {
100:                DestinationManager destManager = new DestinationManager();
101:                ConfigurationManager confManager = new ConfigurationManager();
102:                MockQueueConnection connection = new MockQueueConnection(
103:                        destManager, confManager);
104:                MockSession session = (MockQueueSession) connection
105:                        .createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
106:                assertEquals(Session.CLIENT_ACKNOWLEDGE, session
107:                        .getAcknowledgeMode());
108:                session = (MockQueueSession) connection.createQueueSession(
109:                        false, Session.DUPS_OK_ACKNOWLEDGE);
110:                assertEquals(Session.DUPS_OK_ACKNOWLEDGE, session
111:                        .getAcknowledgeMode());
112:                session = (MockQueueSession) connection.createQueueSession(
113:                        false, Session.AUTO_ACKNOWLEDGE);
114:                assertEquals(Session.AUTO_ACKNOWLEDGE, session
115:                        .getAcknowledgeMode());
116:                session = (MockQueueSession) connection.createQueueSession(
117:                        false, 1234);
118:                assertEquals(1234, session.getAcknowledgeMode());
119:                session = (MockQueueSession) connection.createQueueSession(
120:                        true, Session.CLIENT_ACKNOWLEDGE);
121:                assertEquals(0, session.getAcknowledgeMode());
122:                session = (MockQueueSession) connection.createQueueSession(
123:                        true, 1234);
124:                assertEquals(0, session.getAcknowledgeMode());
125:            }
126:
127:            public void testCreateProducerWithQueueSession() throws Exception {
128:                DestinationManager destManager = new DestinationManager();
129:                ConfigurationManager confManager = new ConfigurationManager();
130:                MockQueueConnection connection = new MockQueueConnection(
131:                        destManager, confManager);
132:                MockSession session = (MockSession) connection
133:                        .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
134:                doTestCreateProducer(session, destManager);
135:            }
136:
137:            public void testCreateProducerWithTopicSession() throws Exception {
138:                DestinationManager destManager = new DestinationManager();
139:                ConfigurationManager confManager = new ConfigurationManager();
140:                MockTopicConnection connection = new MockTopicConnection(
141:                        destManager, confManager);
142:                MockSession session = (MockSession) connection
143:                        .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
144:                doTestCreateProducer(session, destManager);
145:            }
146:
147:            public void testCreateProducerWithSession() throws Exception {
148:                DestinationManager destManager = new DestinationManager();
149:                ConfigurationManager confManager = new ConfigurationManager();
150:                MockConnection connection = new MockConnection(destManager,
151:                        confManager);
152:                MockSession session = (MockSession) connection.createSession(
153:                        false, Session.AUTO_ACKNOWLEDGE);
154:                doTestCreateProducer(session, destManager);
155:            }
156:
157:            public void testCreateNullProducer() throws Exception {
158:                DestinationManager destManager = new DestinationManager();
159:                ConfigurationManager confManager = new ConfigurationManager();
160:                MockQueueConnection queueConnection = new MockQueueConnection(
161:                        destManager, confManager);
162:                MockQueueSession queueSession = (MockQueueSession) queueConnection
163:                        .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
164:                MockTopicConnection topicConnection = new MockTopicConnection(
165:                        destManager, confManager);
166:                MockTopicSession topicSession = (MockTopicSession) topicConnection
167:                        .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
168:                MockConnection connection = new MockConnection(destManager,
169:                        confManager);
170:                MockSession session = (MockSession) connection.createSession(
171:                        false, Session.AUTO_ACKNOWLEDGE);
172:                assertTrue(queueSession.createProducer(null) instanceof  MockQueueSender);
173:                assertTrue(topicSession.createProducer(null) instanceof  MockTopicPublisher);
174:                assertTrue(queueSession.createSender(null) instanceof  MockQueueSender);
175:                assertTrue(topicSession.createPublisher(null) instanceof  MockTopicPublisher);
176:                assertTrue(session.createProducer(null) instanceof  MockMessageProducer);
177:                assertFalse(session.createProducer(null) instanceof  MockQueueSender);
178:                assertFalse(session.createProducer(null) instanceof  MockTopicPublisher);
179:                QueueTransmissionManager queueManager = queueSession
180:                        .getQueueTransmissionManager();
181:                assertEquals(0, queueManager.getQueueSenderList().size());
182:                TopicTransmissionManager topicManager = topicSession
183:                        .getTopicTransmissionManager();
184:                assertEquals(0, topicManager.getTopicPublisherList().size());
185:                GenericTransmissionManager genericManager = queueSession
186:                        .getGenericTransmissionManager();
187:                assertEquals(2, genericManager.getMessageProducerList().size());
188:                genericManager = topicSession.getGenericTransmissionManager();
189:                assertEquals(2, genericManager.getMessageProducerList().size());
190:                genericManager = session.getGenericTransmissionManager();
191:                assertEquals(3, genericManager.getMessageProducerList().size());
192:            }
193:
194:            public void testCreateConsumerWithQueueSession() throws Exception {
195:                DestinationManager destManager = new DestinationManager();
196:                ConfigurationManager confManager = new ConfigurationManager();
197:                MockQueueConnection connection = new MockQueueConnection(
198:                        destManager, confManager);
199:                MockSession session = (MockSession) connection
200:                        .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
201:                doTestCreateConsumer(session, destManager);
202:            }
203:
204:            public void testCreateComsumerWithTopicSession() throws Exception {
205:                DestinationManager destManager = new DestinationManager();
206:                ConfigurationManager confManager = new ConfigurationManager();
207:                MockTopicConnection connection = new MockTopicConnection(
208:                        destManager, confManager);
209:                MockSession session = (MockSession) connection
210:                        .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
211:                doTestCreateConsumer(session, destManager);
212:            }
213:
214:            public void testCreateComsumerWithSession() throws Exception {
215:                DestinationManager destManager = new DestinationManager();
216:                ConfigurationManager confManager = new ConfigurationManager();
217:                MockConnection connection = new MockConnection(destManager,
218:                        confManager);
219:                MockSession session = (MockSession) connection.createSession(
220:                        false, Session.AUTO_ACKNOWLEDGE);
221:                doTestCreateConsumer(session, destManager);
222:            }
223:
224:            private void doTestCreateProducer(MockSession session,
225:                    DestinationManager manager) throws Exception {
226:                MockQueue queue = manager.createQueue("Queue");
227:                MockTopic topic = manager.createTopic("Topic");
228:                MessageProducer producer1 = session.createProducer(queue);
229:                assertTrue(producer1 instanceof  MockQueueSender);
230:                MessageProducer producer2 = session.createProducer(topic);
231:                assertTrue(producer2 instanceof  MockTopicPublisher);
232:                ((MockQueueSender) producer1).send(queue, new MockTextMessage(
233:                        "mytext1"));
234:                ((MockQueueSender) producer1).send(queue, new MockTextMessage(
235:                        "mytext2"));
236:                ((MockTopicPublisher) producer2).send(topic,
237:                        new MockTextMessage("mytext3"));
238:                List messageQueueList = queue.getCurrentMessageList();
239:                assertEquals(2, messageQueueList.size());
240:                assertTrue(messageQueueList.contains(new MockTextMessage(
241:                        "mytext1")));
242:                assertTrue(messageQueueList.contains(new MockTextMessage(
243:                        "mytext2")));
244:                List messageTopicList = topic.getCurrentMessageList();
245:                assertEquals(1, messageTopicList.size());
246:                assertTrue(messageTopicList.contains(new MockTextMessage(
247:                        "mytext3")));
248:                try {
249:                    session.createProducer(new Destination() {
250:                    });
251:                    fail();
252:                } catch (InvalidDestinationException exc) {
253:                    //should throw exception
254:                }
255:            }
256:
257:            private void doTestCreateConsumer(MockSession session,
258:                    DestinationManager manager) throws Exception {
259:                MockQueue queue = manager.createQueue("Queue");
260:                MockTopic topic = manager.createTopic("Topic");
261:                try {
262:                    session.createConsumer(null, "", false);
263:                    fail();
264:                } catch (IllegalArgumentException exc) {
265:                    //should throw exception
266:                }
267:                MessageConsumer consumer1 = session.createConsumer(queue, "",
268:                        false);
269:                assertTrue(consumer1 instanceof  MockQueueReceiver);
270:                MessageConsumer consumer2 = session.createConsumer(topic);
271:                assertTrue(consumer2 instanceof  MockTopicSubscriber);
272:                TestMessageListener listener = new TestMessageListener();
273:                session.setMessageListener(listener);
274:                topic.addMessage(new MockTextMessage("mytext1"));
275:                assertEquals(0, topic.getCurrentMessageList().size());
276:                assertEquals(1, topic.getReceivedMessageList().size());
277:                assertEquals(new MockTextMessage("mytext1"), listener
278:                        .getMessage());
279:                session.setMessageListener(null);
280:                listener = new TestMessageListener();
281:                consumer1.setMessageListener(listener);
282:                topic.addMessage(new MockTextMessage("mytext2"));
283:                assertEquals(1, topic.getCurrentMessageList().size());
284:                assertEquals(2, topic.getReceivedMessageList().size());
285:                assertNull(listener.getMessage());
286:                queue.addMessage(new MockTextMessage("mytext3"));
287:                assertEquals(0, queue.getCurrentMessageList().size());
288:                assertEquals(1, queue.getReceivedMessageList().size());
289:                assertEquals(new MockTextMessage("mytext3"), listener
290:                        .getMessage());
291:                MessageProducer producer = session.createProducer(topic);
292:                listener = new TestMessageListener();
293:                consumer2.setMessageListener(listener);
294:                ((MockTopicPublisher) producer).send(topic,
295:                        new MockTextMessage("mytext4"));
296:                assertEquals(1, topic.getCurrentMessageList().size());
297:                assertEquals(3, topic.getReceivedMessageList().size());
298:                assertEquals(new MockTextMessage("mytext4"), listener
299:                        .getMessage());
300:                try {
301:                    session.createConsumer(new Destination() {
302:                    }, "");
303:                    fail();
304:                } catch (InvalidDestinationException exc) {
305:                    //should throw exception
306:                }
307:            }
308:
309:            public static class TestMessageListener implements  MessageListener {
310:                private Message message;
311:
312:                public Message getMessage() {
313:                    return message;
314:                }
315:
316:                public void onMessage(Message message) {
317:                    this.message = message;
318:                }
319:            }
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.