Source Code Cross Referenced for MockStreamMessageTest.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.Arrays;
004:
005:        import javax.jms.JMSException;
006:        import javax.jms.MessageEOFException;
007:        import javax.jms.MessageFormatException;
008:        import javax.jms.MessageNotReadableException;
009:        import javax.jms.MessageNotWriteableException;
010:
011:        import junit.framework.TestCase;
012:
013:        import com.mockrunner.mock.jms.MockStreamMessage;
014:
015:        public class MockStreamMessageTest extends TestCase {
016:            public void testReadWrite() throws Exception {
017:                MockStreamMessage message = new MockStreamMessage();
018:                message.writeString("test");
019:                try {
020:                    message.readString();
021:                    fail();
022:                } catch (MessageNotReadableException exc) {
023:                    //should throw exception
024:                }
025:                message.reset();
026:                try {
027:                    message.writeByte((byte) 1);
028:                    fail();
029:                } catch (MessageNotWriteableException exc) {
030:                    //should throw exception
031:                }
032:                assertEquals("test", message.readString());
033:                try {
034:                    message.readInt();
035:                    fail();
036:                } catch (MessageEOFException exc) {
037:                    //should throw exception
038:                }
039:                message = new MockStreamMessage();
040:                message.writeString("123");
041:                message.writeString("456");
042:                message.writeString("789");
043:                message.writeString("111");
044:                message.writeString("222");
045:                message.writeString("333");
046:                message.reset();
047:                assertEquals(123, message.readByte());
048:                assertEquals(456, message.readShort());
049:                assertEquals(789, message.readInt());
050:                assertEquals(111, message.readLong());
051:                assertEquals(222, message.readFloat(), 0);
052:                assertEquals(333, message.readDouble(), 0);
053:                try {
054:                    message.readBoolean();
055:                    fail();
056:                } catch (MessageEOFException exc) {
057:                    //should throw exception
058:                }
059:                message = new MockStreamMessage();
060:                message.writeLong(1);
061:                message.reset();
062:                try {
063:                    message.readInt();
064:                    fail();
065:                } catch (MessageFormatException exc) {
066:                    //should throw exception
067:                }
068:                message = new MockStreamMessage();
069:                message.writeByte((byte) 1);
070:                message.writeByte((byte) 1);
071:                message.writeByte((byte) 1);
072:                message.writeByte((byte) 1);
073:                message.reset();
074:                assertEquals(1, message.readByte());
075:                assertEquals(1, message.readShort());
076:                assertEquals(1, message.readInt());
077:                assertEquals(1, message.readLong());
078:                message = new MockStreamMessage();
079:                message.writeBoolean(false);
080:                message.reset();
081:                try {
082:                    message.readFloat();
083:                    fail();
084:                } catch (MessageFormatException exc) {
085:                    //should throw exception
086:                }
087:                message = new MockStreamMessage();
088:                message.writeBoolean(false);
089:                message.writeBoolean(true);
090:                message.reset();
091:                assertEquals(false, message.readBoolean());
092:                assertEquals("true", message.readString());
093:                message.clearBody();
094:                message.writeDouble(123.4);
095:                message.reset();
096:                assertEquals("123.4", message.readString());
097:                message.clearBody();
098:                message.writeString("a");
099:                message.reset();
100:                try {
101:                    message.readChar();
102:                    fail();
103:                } catch (MessageFormatException exc) {
104:                    //should throw exception
105:                }
106:                message.clearBody();
107:                message.writeChar('a');
108:                message.reset();
109:                assertEquals("a", message.readString());
110:                message = new MockStreamMessage();
111:                byte[] data = new byte[] { 1, 2, 3, 4 };
112:                message.writeBytes(data);
113:                message.writeBytes(data);
114:                message.reset();
115:                data = new byte[4];
116:                int number = message.readBytes(data);
117:                assertEquals(4, number);
118:                assertTrue(Arrays.equals(data, new byte[] { 1, 2, 3, 4 }));
119:                data = (byte[]) message.readObject();
120:                assertTrue(Arrays.equals(data, new byte[] { 1, 2, 3, 4 }));
121:                message = new MockStreamMessage();
122:                data = new byte[] { 1, 2, 3, 4 };
123:                message.writeBytes(data);
124:                message.reset();
125:                data = new byte[5];
126:                number = message.readBytes(data);
127:                assertEquals(4, number);
128:                assertTrue(Arrays.equals(data, new byte[] { 1, 2, 3, 4, 0 }));
129:                data = new byte[] { 1, 2, 3, 4 };
130:                message.clearBody();
131:                message.writeBytes(data, 3, 1);
132:                message.reset();
133:                data = new byte[5];
134:                number = message.readBytes(data);
135:                assertEquals(1, number);
136:                assertTrue(Arrays.equals(data, new byte[] { 4, 0, 0, 0, 0 }));
137:                data = new byte[] { 1, 2, 3, 4 };
138:                message.clearBody();
139:                message.writeBytes(data);
140:                message.reset();
141:                data = new byte[1];
142:                number = message.readBytes(data);
143:                assertEquals(1, number);
144:                assertTrue(Arrays.equals(data, new byte[] { 1 }));
145:                data = new byte[] { 1, 2, 3, 4 };
146:                message.clearBody();
147:                message.writeBytes(data);
148:                message.reset();
149:                data = new byte[0];
150:                number = message.readBytes(data);
151:                assertEquals(0, number);
152:                data = new byte[] { 1, 2, 3, 4 };
153:                message.clearBody();
154:                message.writeBytes(data);
155:                message.reset();
156:                number = message.readBytes(null);
157:                assertEquals(-1, number);
158:                message = new MockStreamMessage();
159:                message.writeObject(null);
160:                message.writeObject(null);
161:                message.writeObject(null);
162:                message.writeObject(new Integer(3));
163:                message.writeObject("4");
164:                message.writeObject(new Byte((byte) 5));
165:                message.reset();
166:                try {
167:                    message.readChar();
168:                    fail();
169:                } catch (NullPointerException exc) {
170:                    //should throw exception
171:                }
172:                try {
173:                    message.readDouble();
174:                    fail();
175:                } catch (NullPointerException exc) {
176:                    //should throw exception
177:                }
178:                assertNull(message.readObject());
179:                assertEquals(3, message.readLong());
180:                assertEquals(4, message.readByte());
181:                try {
182:                    message.readFloat();
183:                    fail();
184:                } catch (MessageFormatException exc) {
185:                    //should throw exception
186:                }
187:
188:                try {
189:                    message.readFloat();
190:                    fail();
191:                } catch (MessageEOFException exc) {
192:                    //should throw exception
193:                }
194:            }
195:
196:            public void testEquals() throws Exception {
197:                MockStreamMessage message1 = new MockStreamMessage();
198:                message1.writeString("test");
199:                message1.writeObject(new Long(1));
200:                message1.writeBytes(new byte[] { 1, 2, 3 });
201:                assertTrue(message1.equals(message1));
202:                MockStreamMessage message2 = null;
203:                assertFalse(message1.equals(message2));
204:                message2 = new MockStreamMessage();
205:                assertFalse(message1.equals(message2));
206:                assertFalse(message2.equals(message1));
207:                message2.writeString("test");
208:                message2.writeBytes(new byte[] { 1, 2, 3 });
209:                message2.writeObject(new Long(1));
210:                assertFalse(message1.equals(message2));
211:                assertFalse(message2.equals(message1));
212:                message2 = new MockStreamMessage();
213:                message2.writeString("test");
214:                message2.writeObject(new Long(1));
215:                message2.writeBytes(new byte[] {});
216:                assertFalse(message1.equals(message2));
217:                assertFalse(message2.equals(message1));
218:                message2 = new MockStreamMessage();
219:                message2.writeString("test");
220:                message2.writeObject(new Long(1));
221:                message2.writeBytes(new byte[] { 1, 2, 3 });
222:                assertTrue(message1.equals(message2));
223:                assertTrue(message2.equals(message1));
224:                assertEquals(message1.hashCode(), message2.hashCode());
225:                message2.writeString(null);
226:                assertFalse(message1.equals(message2));
227:                assertFalse(message2.equals(message1));
228:                message1.writeString(null);
229:                assertTrue(message1.equals(message2));
230:                assertTrue(message2.equals(message1));
231:                assertEquals(message1.hashCode(), message2.hashCode());
232:                message1.reset();
233:                assertTrue(message1.equals(message2));
234:                assertTrue(message2.equals(message1));
235:                assertEquals(message1.hashCode(), message2.hashCode());
236:            }
237:
238:            public void testClone() throws Exception {
239:                MockStreamMessage message = new MockStreamMessage();
240:                MockStreamMessage newMessage = (MockStreamMessage) message
241:                        .clone();
242:                assertNotSame(message, newMessage);
243:                assertEquals(message, newMessage);
244:                message = new MockStreamMessage();
245:                message.writeByte((byte) 1);
246:                message.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
247:                message.writeBoolean(true);
248:                newMessage = (MockStreamMessage) message.clone();
249:                assertNotSame(message, newMessage);
250:                assertEquals(message, newMessage);
251:                try {
252:                    newMessage.readBoolean();
253:                    fail();
254:                } catch (JMSException exc) {
255:                    //should throw exception
256:                }
257:                newMessage.reset();
258:                assertEquals(1, newMessage.readByte());
259:                byte[] myArray = new byte[5];
260:                newMessage.readBytes(myArray);
261:                assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, myArray));
262:                assertTrue(newMessage.readBoolean());
263:                message = new MockStreamMessage();
264:                message.writeString("test1");
265:                message.writeString("test2");
266:                message.reset();
267:                newMessage = (MockStreamMessage) message.clone();
268:                assertEquals("test1", message.readString());
269:                assertEquals("test2", message.readString());
270:            }
271:
272:            public void testToString() throws Exception {
273:                MockStreamMessage message = new MockStreamMessage();
274:                assertEquals(MockStreamMessage.class.getName() + ": []",
275:                        message.toString());
276:                message.writeInt(12);
277:                message.writeString("abc");
278:                assertEquals(MockStreamMessage.class.getName() + ": [12, abc]",
279:                        message.toString());
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.