Source Code Cross Referenced for MockTopicTest.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 javax.jms.Message;
004:        import javax.jms.MessageListener;
005:        import javax.jms.Session;
006:
007:        import junit.framework.TestCase;
008:
009:        import com.mockrunner.jms.ConfigurationManager;
010:        import com.mockrunner.jms.DestinationManager;
011:        import com.mockrunner.mock.jms.MockMessage;
012:        import com.mockrunner.mock.jms.MockTextMessage;
013:        import com.mockrunner.mock.jms.MockTopic;
014:        import com.mockrunner.mock.jms.MockTopicConnection;
015:        import com.mockrunner.mock.jms.MockTopicSession;
016:        import com.mockrunner.mock.jms.MockTopicSubscriber;
017:
018:        public class MockTopicTest extends TestCase {
019:            private MockTopicConnection connection;
020:            private MockTopic topic;
021:
022:            protected void setUp() throws Exception {
023:                super .setUp();
024:                DestinationManager destManager = new DestinationManager();
025:                ConfigurationManager confManager = new ConfigurationManager();
026:                connection = new MockTopicConnection(destManager, confManager);
027:                topic = new MockTopic("TestTopic");
028:            }
029:
030:            public void testGetMessageList() throws Exception {
031:                assertTrue(topic.isEmpty());
032:                assertEquals(0, topic.getCurrentMessageList().size());
033:                assertEquals(0, topic.getReceivedMessageList().size());
034:                assertNull(topic.getMessage());
035:                topic.addMessage(new MockTextMessage("test1"));
036:                topic.addMessage(new MockTextMessage("test2"));
037:                topic.addMessage(new MockTextMessage("test3"));
038:                assertFalse(topic.isEmpty());
039:                assertEquals(3, topic.getCurrentMessageList().size());
040:                assertEquals(3, topic.getReceivedMessageList().size());
041:                assertEquals(new MockTextMessage("test1"), topic.getMessage());
042:                assertFalse(topic.isEmpty());
043:                assertEquals(2, topic.getCurrentMessageList().size());
044:                assertEquals(3, topic.getReceivedMessageList().size());
045:                assertEquals(new MockTextMessage("test2"), topic.getMessage());
046:                assertFalse(topic.isEmpty());
047:                assertEquals(1, topic.getCurrentMessageList().size());
048:                assertEquals(3, topic.getReceivedMessageList().size());
049:                assertEquals(new MockTextMessage("test3"), topic.getMessage());
050:                assertTrue(topic.isEmpty());
051:                assertEquals(0, topic.getCurrentMessageList().size());
052:                assertEquals(3, topic.getReceivedMessageList().size());
053:                assertNull(topic.getMessage());
054:            }
055:
056:            public void testLoadMessage() throws Exception {
057:                MockTopicSession session = new MockTopicSession(connection,
058:                        false, Session.CLIENT_ACKNOWLEDGE);
059:                topic.addSession(session);
060:                topic.loadMessage(new MockTextMessage("test"));
061:                assertEquals(1, topic.getCurrentMessageList().size());
062:                assertEquals(0, topic.getReceivedMessageList().size());
063:                assertEquals(new MockTextMessage("test"), topic
064:                        .getCurrentMessageList().get(0));
065:            }
066:
067:            public void testAddMessage() throws Exception {
068:                MockTopicSession session = new MockTopicSession(connection,
069:                        false, Session.CLIENT_ACKNOWLEDGE);
070:                topic.addSession(session);
071:                topic.addMessage(new MockTextMessage("test"));
072:                assertEquals(1, topic.getCurrentMessageList().size());
073:                assertEquals(1, topic.getReceivedMessageList().size());
074:                assertEquals(new MockTextMessage("test"), topic.getMessage());
075:                TestMessageListener listener1 = new TestMessageListener();
076:                TestMessageListener listener2 = new TestMessageListener();
077:                MockTopicSubscriber subscriber1 = (MockTopicSubscriber) session
078:                        .createSubscriber(topic);
079:                session.setMessageListener(listener1);
080:                subscriber1.setMessageListener(listener2);
081:                topic.reset();
082:                topic.addMessage(new MockTextMessage("test"));
083:                assertEquals(0, topic.getCurrentMessageList().size());
084:                assertEquals(1, topic.getReceivedMessageList().size());
085:                assertNull(topic.getMessage());
086:                assertEquals(new MockTextMessage("test"), listener1
087:                        .getMessage());
088:                assertFalse(((MockMessage) listener1.getMessage())
089:                        .isAcknowledged());
090:                assertNull(listener2.getMessage());
091:                session.setMessageListener(null);
092:                topic.reset();
093:                listener1.reset();
094:                listener2.reset();
095:                MockTopicSubscriber subscriber2 = (MockTopicSubscriber) session
096:                        .createSubscriber(topic);
097:                subscriber2.setMessageListener(listener1);
098:                topic.addMessage(new MockTextMessage("test"));
099:                assertEquals(0, topic.getCurrentMessageList().size());
100:                assertEquals(1, topic.getReceivedMessageList().size());
101:                assertNull(topic.getMessage());
102:                assertEquals(new MockTextMessage("test"), listener1
103:                        .getMessage());
104:                assertEquals(new MockTextMessage("test"), listener2
105:                        .getMessage());
106:                assertFalse(((MockMessage) listener1.getMessage())
107:                        .isAcknowledged());
108:                assertFalse(((MockMessage) listener2.getMessage())
109:                        .isAcknowledged());
110:                topic.reset();
111:                listener1.reset();
112:                listener2.reset();
113:                subscriber2.close();
114:                topic.addMessage(new MockTextMessage("test"));
115:                assertEquals(0, topic.getCurrentMessageList().size());
116:                assertEquals(1, topic.getReceivedMessageList().size());
117:                assertNull(topic.getMessage());
118:                assertEquals(new MockTextMessage("test"), listener2
119:                        .getMessage());
120:                assertNull(listener1.getMessage());
121:                topic.reset();
122:                listener1.reset();
123:                listener2.reset();
124:                subscriber1.close();
125:                topic.addMessage(new MockTextMessage("test"));
126:                assertEquals(1, topic.getCurrentMessageList().size());
127:                assertEquals(1, topic.getReceivedMessageList().size());
128:                assertEquals(new MockTextMessage("test"), topic.getMessage());
129:                assertNull(topic.getMessage());
130:                assertEquals(0, topic.getCurrentMessageList().size());
131:                topic.reset();
132:                listener1.reset();
133:                listener2.reset();
134:                subscriber1 = (MockTopicSubscriber) session
135:                        .createSubscriber(topic);
136:                subscriber2 = (MockTopicSubscriber) session
137:                        .createDurableSubscriber(topic, "durable");
138:                subscriber1.setMessageListener(listener1);
139:                subscriber2.setMessageListener(listener2);
140:                topic.addMessage(new MockTextMessage("test"));
141:                assertEquals(0, topic.getCurrentMessageList().size());
142:                assertEquals(1, topic.getReceivedMessageList().size());
143:                assertEquals(new MockTextMessage("test"), listener1
144:                        .getMessage());
145:                assertEquals(new MockTextMessage("test"), listener2
146:                        .getMessage());
147:                assertFalse(((MockMessage) listener1.getMessage())
148:                        .isAcknowledged());
149:                assertFalse(((MockMessage) listener2.getMessage())
150:                        .isAcknowledged());
151:                listener1.reset();
152:                listener2.reset();
153:                subscriber1 = (MockTopicSubscriber) session
154:                        .createSubscriber(topic);
155:                subscriber1.setMessageListener(listener1);
156:                topic.addMessage(new MockTextMessage("test"));
157:                assertEquals(0, topic.getCurrentMessageList().size());
158:                assertEquals(2, topic.getReceivedMessageList().size());
159:            }
160:
161:            public void testAddMessageAutoAcknowledge() throws Exception {
162:                MockTopicSession session = new MockTopicSession(connection,
163:                        false, Session.AUTO_ACKNOWLEDGE);
164:                doTestAcknowledge(session);
165:            }
166:
167:            public void testAddMessageDupOkAcknowledge() throws Exception {
168:                MockTopicSession session = new MockTopicSession(connection,
169:                        false, Session.DUPS_OK_ACKNOWLEDGE);
170:                doTestAcknowledge(session);
171:            }
172:
173:            private void doTestAcknowledge(MockTopicSession session)
174:                    throws Exception {
175:                topic.addSession(session);
176:                MockTextMessage message = new MockTextMessage("text");
177:                topic.addMessage(message);
178:                assertFalse(message.isAcknowledged());
179:                message = new MockTextMessage("text");
180:                TestMessageListener listener = new TestMessageListener();
181:                session.setMessageListener(listener);
182:                topic.addMessage(message);
183:                assertTrue(message.isAcknowledged());
184:                session.setMessageListener(null);
185:                message = new MockTextMessage("text");
186:                MockTopicSubscriber subscriber = (MockTopicSubscriber) session
187:                        .createSubscriber(topic);
188:                subscriber.setMessageListener(listener);
189:                topic.addMessage(message);
190:                assertTrue(message.isAcknowledged());
191:                subscriber.setMessageListener(null);
192:                message = new MockTextMessage("text");
193:                topic.addMessage(message);
194:                assertFalse(message.isAcknowledged());
195:                subscriber = (MockTopicSubscriber) session
196:                        .createDurableSubscriber(topic, "myDurable");
197:                subscriber.setMessageListener(listener);
198:                message = new MockTextMessage("text");
199:                topic.addMessage(message);
200:                assertTrue(message.isAcknowledged());
201:            }
202:
203:            public static class TestMessageListener implements  MessageListener {
204:                private Message message;
205:
206:                public Message getMessage() {
207:                    return message;
208:                }
209:
210:                public void reset() {
211:                    message = null;
212:                }
213:
214:                public void onMessage(Message message) {
215:                    this.message = message;
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.