Source Code Cross Referenced for MockConnection.java in  » Testing » mockrunner-0.4 » com » mockrunner » mock » 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.mock.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.mock.jms;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collections;
005:        import java.util.List;
006:
007:        import javax.jms.Connection;
008:        import javax.jms.ConnectionConsumer;
009:        import javax.jms.ConnectionMetaData;
010:        import javax.jms.Destination;
011:        import javax.jms.ExceptionListener;
012:        import javax.jms.JMSException;
013:        import javax.jms.ServerSessionPool;
014:        import javax.jms.Session;
015:        import javax.jms.Topic;
016:
017:        import com.mockrunner.jms.ConfigurationManager;
018:        import com.mockrunner.jms.DestinationManager;
019:
020:        /**
021:         * Mock implementation of JMS <code>Connection</code>.
022:         * Please note: The interfaces <code>ConnectionConsumer</code>,
023:         * <code>ServerSessionPool</code> and <code>ServerSession</code>
024:         * are not meant for application use. Mockrunner provides very
025:         * simple mock implementations but usually you won't need them.
026:         */
027:        public class MockConnection implements  Connection {
028:            private ConnectionMetaData metaData;
029:            private List sessions;
030:            private String clientId;
031:            private boolean started;
032:            private boolean closed;
033:            private ExceptionListener listener;
034:            private JMSException exception;
035:            private DestinationManager destinationManager;
036:            private ConfigurationManager configurationManager;
037:
038:            public MockConnection(DestinationManager destinationManager,
039:                    ConfigurationManager configurationManager) {
040:                metaData = new MockConnectionMetaData();
041:                started = false;
042:                closed = false;
043:                exception = null;
044:                this .destinationManager = destinationManager;
045:                this .configurationManager = configurationManager;
046:                sessions = new ArrayList();
047:            }
048:
049:            /**
050:             * Returns the {@link com.mockrunner.jms.DestinationManager}.
051:             * @return the {@link com.mockrunner.jms.DestinationManager}
052:             */
053:            public DestinationManager getDestinationManager() {
054:                return destinationManager;
055:            }
056:
057:            /**
058:             * Returns the {@link com.mockrunner.jms.ConfigurationManager}.
059:             * @return the {@link com.mockrunner.jms.ConfigurationManager}
060:             */
061:            public ConfigurationManager getConfigurationManager() {
062:                return configurationManager;
063:            }
064:
065:            /**
066:             * Returns the list of {@link MockSession} objects.
067:             * @return the list
068:             */
069:            public List getSessionList() {
070:                return Collections.unmodifiableList(sessions);
071:            }
072:
073:            /**
074:             * Returns a {@link MockSession}. If there's no such
075:             * {@link MockSession}, <code>null</code> is returned.
076:             * @param index the index of the session object
077:             * @return the session object
078:             */
079:            public MockSession getSession(int index) {
080:                if (sessions.size() <= index || index < 0)
081:                    return null;
082:                return (MockSession) sessions.get(index);
083:            }
084:
085:            /**
086:             * Set an exception that will be thrown when calling one
087:             * of the interface methods. Since the mock implementation
088:             * cannot fail like a full blown message server you can use
089:             * this method to simulate server errors. After the exception
090:             * was thrown it will be deleted.
091:             * @param exception the exception to throw
092:             */
093:            public void setJMSException(JMSException exception) {
094:                this .exception = exception;
095:            }
096:
097:            /**
098:             * Throws a <code>JMSException</code> if one is set with
099:             * {@link #setJMSException}. Deletes the exception.
100:             */
101:            public void throwJMSException() throws JMSException {
102:                if (null == exception)
103:                    return;
104:                JMSException tempException = exception;
105:                exception = null;
106:                throw tempException;
107:            }
108:
109:            /**
110:             * Calls the <code>ExceptionListener</code>
111:             * if an exception is set {@link #setJMSException}.
112:             * Deletes the exception after calling the <code>ExceptionListener</code>.
113:             */
114:            public void callExceptionListener() {
115:                JMSException tempException = exception;
116:                exception = null;
117:                callExceptionListener(tempException);
118:            }
119:
120:            /**
121:             * Calls the <code>ExceptionListener</code>
122:             * using the specified exception.
123:             * @param exception the exception
124:             */
125:            public void callExceptionListener(JMSException exception) {
126:                if (listener != null && exception != null) {
127:                    listener.onException(exception);
128:                }
129:            }
130:
131:            /**
132:             * You can use this to set the <code>ConnectionMetaData</code>.
133:             * Usually this should not be necessary. Per default an instance
134:             * of {@link MockConnectionMetaData} is returned when calling
135:             * {@link #getMetaData}.
136:             * @param metaData the meta data
137:             */
138:            public void setMetaData(ConnectionMetaData metaData) {
139:                this .metaData = metaData;
140:            }
141:
142:            public Session createSession(boolean transacted, int acknowledgeMode)
143:                    throws JMSException {
144:                throwJMSException();
145:                MockSession session = new MockSession(this , transacted,
146:                        acknowledgeMode);
147:                sessions().add(session);
148:                return session;
149:            }
150:
151:            public ConnectionConsumer createConnectionConsumer(
152:                    Destination destination, String messageSelector,
153:                    ServerSessionPool sessionPool, int maxMessages)
154:                    throws JMSException {
155:                throwJMSException();
156:                return new MockConnectionConsumer(this , sessionPool);
157:            }
158:
159:            public ConnectionConsumer createDurableConnectionConsumer(
160:                    Topic topic, String subscriptionName,
161:                    String messageSelector, ServerSessionPool sessionPool,
162:                    int maxMessages) throws JMSException {
163:                return createConnectionConsumer(topic, messageSelector,
164:                        sessionPool, maxMessages);
165:            }
166:
167:            public ConnectionMetaData getMetaData() throws JMSException {
168:                throwJMSException();
169:                return metaData;
170:            }
171:
172:            public String getClientID() throws JMSException {
173:                throwJMSException();
174:                return clientId;
175:            }
176:
177:            public void setClientID(String clientId) throws JMSException {
178:                throwJMSException();
179:                this .clientId = clientId;
180:            }
181:
182:            public ExceptionListener getExceptionListener() throws JMSException {
183:                throwJMSException();
184:                return listener;
185:            }
186:
187:            public void setExceptionListener(ExceptionListener listener)
188:                    throws JMSException {
189:                throwJMSException();
190:                this .listener = listener;
191:            }
192:
193:            public void start() throws JMSException {
194:                throwJMSException();
195:                started = true;
196:            }
197:
198:            public void stop() throws JMSException {
199:                throwJMSException();
200:                started = false;
201:            }
202:
203:            public void close() throws JMSException {
204:                throwJMSException();
205:                for (int ii = 0; ii < sessions.size(); ii++) {
206:                    Session session = (Session) sessions.get(ii);
207:                    session.close();
208:                }
209:                closed = true;
210:            }
211:
212:            public boolean isStarted() {
213:                return started;
214:            }
215:
216:            public boolean isStopped() {
217:                return !isStarted();
218:            }
219:
220:            public boolean isClosed() {
221:                return closed;
222:            }
223:
224:            protected List sessions() {
225:                return sessions;
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.