Source Code Cross Referenced for MockDestination.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.HashSet;
006:        import java.util.List;
007:        import java.util.Set;
008:
009:        import javax.jms.Destination;
010:        import javax.jms.JMSException;
011:        import javax.jms.Message;
012:        import javax.jms.Session;
013:
014:        import org.activemq.filter.mockrunner.Filter;
015:
016:        import com.mockrunner.base.NestedApplicationException;
017:
018:        /**
019:         * Mock implementation of JMS <code>Destination</code>.
020:         */
021:        public abstract class MockDestination implements  Destination {
022:            private Set sessions;
023:            private List currentMessages;
024:            private List receivedMessages;
025:
026:            public MockDestination() {
027:                sessions = new HashSet();
028:                currentMessages = new ArrayList();
029:                receivedMessages = new ArrayList();
030:            }
031:
032:            /**
033:             * Adds a message and delivers it to the corresponding consumers. 
034:             * Implemented by {@link MockQueue} and {@link MockTopic}.
035:             * @param message the message
036:             */
037:            public abstract void addMessage(Message message)
038:                    throws JMSException;
039:
040:            /**
041:             * Adds a message to the list of current messages in this
042:             * destination. The message is not delivered to registered
043:             * consumers. Can be used to preload destinations with
044:             * test messages.
045:             * @param message the message
046:             */
047:            public void loadMessage(Message message) {
048:                addCurrentMessage(message);
049:            }
050:
051:            /**
052:             * Returns if this destination contains messages.
053:             * @return <code>false</code> if there's at least one message,
054:             *         <code>true</code> otherwise
055:             */
056:            public boolean isEmpty() {
057:                return currentMessages.size() <= 0;
058:            }
059:
060:            /**
061:             * Clears all current messages.
062:             */
063:            public void clear() {
064:                currentMessages.clear();
065:            }
066:
067:            /**
068:             * Clears all current messages and resets the list of received messages.
069:             */
070:            public void reset() {
071:                currentMessages.clear();
072:                receivedMessages.clear();
073:            }
074:
075:            /**
076:             * Returns the next message. The message will be removed from the list
077:             * of current messages. 
078:             * If there's no message, <code>null</code> will be returned.
079:             * @return the <code>Message</code>
080:             */
081:            public Message getMessage() {
082:                if (currentMessages.size() <= 0)
083:                    return null;
084:                return (Message) currentMessages.remove(0);
085:            }
086:
087:            /**
088:             * Returns the next message that matches the filter. 
089:             * The message will be removed from the list of current messages. 
090:             * If there's no matching message, <code>null</code> will be returned.
091:             * @param filter the message filter
092:             * @return the <code>Message</code>
093:             */
094:            public Message getMatchingMessage(Filter filter) {
095:                for (int ii = 0; ii < currentMessages.size(); ii++) {
096:                    Message currentMessage = (Message) currentMessages.get(ii);
097:                    try {
098:                        if (filter.matches(currentMessage)) {
099:                            currentMessages.remove(ii);
100:                            return currentMessage;
101:                        }
102:                    } catch (JMSException exc) {
103:                        throw new NestedApplicationException(exc);
104:                    }
105:                }
106:                return null;
107:            }
108:
109:            /**
110:             * Returns a <code>List</code> of all current messages.
111:             * @return the <code>List</code> of messages
112:             */
113:            public List getCurrentMessageList() {
114:                return Collections.unmodifiableList(currentMessages);
115:            }
116:
117:            /**
118:             * Returns a <code>List</code> of all received messages.
119:             * @return the <code>List</code> of messages
120:             */
121:            public List getReceivedMessageList() {
122:                return Collections.unmodifiableList(receivedMessages);
123:            }
124:
125:            /**
126:             * Adds a <code>Session</code>.
127:             * @param session the session
128:             */
129:            public void addSession(Session session) {
130:                sessions.add(session);
131:            }
132:
133:            /**
134:             * Removes a <code>Session</code>.
135:             * @param session the session
136:             */
137:            public void removeSession(Session session) {
138:                sessions.remove(session);
139:            }
140:
141:            /**
142:             * Return a <code>Set</code> of all sessions.
143:             * @return a <code>Set</code> of all sessions
144:             */
145:            public Set sessionSet() {
146:                return Collections.unmodifiableSet(sessions);
147:            }
148:
149:            protected void addReceivedMessage(Message message) {
150:                receivedMessages.add(message);
151:            }
152:
153:            protected void addCurrentMessage(Message message) {
154:                currentMessages.add(message);
155:            }
156:
157:            protected void acknowledgeMessage(Message message,
158:                    MockSession session) throws JMSException {
159:                if (session.isAutoAcknowledge()) {
160:                    message.acknowledge();
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.