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


001:        package com.mockrunner.test.connector;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.IOException;
005:        import java.io.InputStream;
006:        import java.io.OutputStream;
007:        import java.util.Arrays;
008:
009:        import javax.resource.cci.InteractionSpec;
010:        import javax.resource.cci.Record;
011:        import javax.resource.cci.Streamable;
012:
013:        import junit.framework.TestCase;
014:
015:        import com.mockrunner.connector.StreamableRecordByteArrayInteraction;
016:        import com.mockrunner.mock.connector.cci.MockIndexedRecord;
017:        import com.mockrunner.mock.connector.cci.MockMappedRecord;
018:        import com.mockrunner.mock.connector.cci.MockStreamableByteArrayRecord;
019:
020:        public class StreamableRecordByteArrayInteractionTest extends TestCase {
021:            public void testSetResponseArguments() {
022:                StreamableRecordByteArrayInteraction interaction = new StreamableRecordByteArrayInteraction();
023:                try {
024:                    interaction.setResponse(new byte[0], String.class);
025:                    fail();
026:                } catch (IllegalArgumentException exc) {
027:                    //should throw exception
028:                }
029:                try {
030:                    interaction.setResponse(new byte[0], Streamable.class);
031:                    fail();
032:                } catch (IllegalArgumentException exc) {
033:                    //should throw exception
034:                }
035:                try {
036:                    interaction.setResponse(new ByteArrayInputStream(
037:                            new byte[0]), Record.class);
038:                    fail();
039:                } catch (IllegalArgumentException exc) {
040:                    //should throw exception
041:                }
042:                interaction.setResponse(new ByteArrayInputStream(new byte[0]),
043:                        null);
044:                interaction.setResponse(new ByteArrayInputStream(new byte[0]),
045:                        TestRecord.class);
046:                interaction.setResponse(new ByteArrayInputStream(new byte[0]),
047:                        MockStreamableByteArrayRecord.class);
048:                try {
049:                    interaction = new StreamableRecordByteArrayInteraction(
050:                            new byte[0], Integer.class);
051:                    fail();
052:                } catch (IllegalArgumentException exc) {
053:                    //should throw exception
054:                }
055:                try {
056:                    interaction = new StreamableRecordByteArrayInteraction(
057:                            new byte[0], Record.class);
058:                    fail();
059:                } catch (IllegalArgumentException exc) {
060:                    //should throw exception
061:                }
062:                interaction = new StreamableRecordByteArrayInteraction(
063:                        new byte[0], (Class) null);
064:            }
065:
066:            public void testCanHandle() {
067:                StreamableRecordByteArrayInteraction interaction = new StreamableRecordByteArrayInteraction();
068:                InteractionSpec spec = new InteractionSpec() {
069:                };
070:                assertTrue(interaction.canHandle(spec, null, null));
071:                assertTrue(interaction.canHandle(spec, null,
072:                        new MockStreamableByteArrayRecord()));
073:                assertFalse(interaction.canHandle(spec, null,
074:                        new MockIndexedRecord()));
075:                assertTrue(interaction.canHandle(spec,
076:                        new MockStreamableByteArrayRecord(),
077:                        new MockStreamableByteArrayRecord()));
078:                interaction.setExpectedRequest(new byte[] { 1, 2, 3 });
079:                assertFalse(interaction.canHandle(spec, null,
080:                        new MockStreamableByteArrayRecord()));
081:                assertFalse(interaction.canHandle(spec,
082:                        new MockStreamableByteArrayRecord(),
083:                        new MockStreamableByteArrayRecord()));
084:                MockStreamableByteArrayRecord request = new MockStreamableByteArrayRecord();
085:                request.setContent(new byte[] { 1, 2, 3 });
086:                assertTrue(interaction.canHandle(spec, request,
087:                        new MockStreamableByteArrayRecord()));
088:                request.setContent(new byte[] { 1, 2, 3, 4 });
089:                assertFalse(interaction.canHandle(spec, request,
090:                        new MockStreamableByteArrayRecord()));
091:                interaction.setExpectedRequest(new ByteArrayInputStream(
092:                        new byte[] { 1, 2, 3, 4 }));
093:                assertTrue(interaction.canHandle(spec, request,
094:                        new MockStreamableByteArrayRecord()));
095:                interaction = new StreamableRecordByteArrayInteraction(
096:                        new byte[] { 5, 6, 7 },
097:                        new MockStreamableByteArrayRecord());
098:                assertFalse(interaction.canHandle(spec, request,
099:                        new MockStreamableByteArrayRecord()));
100:                request.setContent(new byte[] { 5, 6, 7 });
101:                assertTrue(interaction.canHandle(spec, request,
102:                        new MockStreamableByteArrayRecord()));
103:                interaction = new StreamableRecordByteArrayInteraction(
104:                        new byte[] { 1 }, MockStreamableByteArrayRecord.class);
105:                assertTrue(interaction.canHandle(spec, request,
106:                        new MockStreamableByteArrayRecord()));
107:            }
108:
109:            public void testEnableAndDisable() {
110:                StreamableRecordByteArrayInteraction interaction = new StreamableRecordByteArrayInteraction();
111:                InteractionSpec spec = new InteractionSpec() {
112:                };
113:                assertTrue(interaction.canHandle(spec, null, null));
114:                interaction.disable();
115:                assertFalse(interaction.canHandle(spec, null, null));
116:                interaction.enable();
117:                assertTrue(interaction.canHandle(spec, null, null));
118:            }
119:
120:            public void testExecuteReturnsRecord() throws Exception {
121:                StreamableRecordByteArrayInteraction interaction = new StreamableRecordByteArrayInteraction();
122:                InteractionSpec spec = new InteractionSpec() {
123:                };
124:                interaction.setExpectedRequest(new byte[] { 1 });
125:                assertNull(interaction.execute(spec, new MockIndexedRecord()));
126:                MockStreamableByteArrayRecord request = new MockStreamableByteArrayRecord();
127:                request.setContent(new byte[] { 1 });
128:                MockStreamableByteArrayRecord response = (MockStreamableByteArrayRecord) interaction
129:                        .execute(spec, request);
130:                assertNull(response.getContent());
131:                MockMappedRecord mappedResponse = new MockMappedRecord();
132:                interaction.setResponse(mappedResponse);
133:                assertSame(mappedResponse, interaction.execute(spec, request));
134:                interaction.setResponse(new byte[] { 1, 2, 3 },
135:                        TestRecord.class);
136:                interaction.setResponse((Record) null);
137:                assertTrue(interaction.execute(spec, request) instanceof  TestRecord);
138:                interaction.setResponse(new byte[] { 1, 2, 3, 4, 5 });
139:                response = (MockStreamableByteArrayRecord) interaction.execute(
140:                        spec, request);
141:                assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, response
142:                        .getContent()));
143:                interaction.setResponse(new TestRecord());
144:                assertTrue(interaction.execute(spec, request) instanceof  TestRecord);
145:                assertNull(interaction.execute(spec,
146:                        new MockStreamableByteArrayRecord()));
147:                interaction = new StreamableRecordByteArrayInteraction(
148:                        new byte[] { 1 }, MockStreamableByteArrayRecord.class);
149:                response = (MockStreamableByteArrayRecord) interaction.execute(
150:                        spec, request);
151:                assertTrue(Arrays.equals(new byte[] { 1 }, response
152:                        .getContent()));
153:                interaction = new StreamableRecordByteArrayInteraction(
154:                        new byte[] { 1, 2 }, (Class) null);
155:                response = (MockStreamableByteArrayRecord) interaction.execute(
156:                        spec, request);
157:                assertTrue(Arrays.equals(new byte[] { 1, 2 }, response
158:                        .getContent()));
159:                interaction.setResponse(mappedResponse);
160:                assertSame(mappedResponse, interaction.execute(spec, request));
161:                interaction.setResponse((Record) null);
162:                response = (MockStreamableByteArrayRecord) interaction.execute(
163:                        spec, request);
164:                assertTrue(Arrays.equals(new byte[] { 1, 2 }, response
165:                        .getContent()));
166:            }
167:
168:            public void testExecuteReturnsBoolean() throws Exception {
169:                StreamableRecordByteArrayInteraction interaction = new StreamableRecordByteArrayInteraction();
170:                InteractionSpec spec = new InteractionSpec() {
171:                };
172:                interaction.setExpectedRequest(new byte[] { 1 });
173:                assertFalse(interaction.execute(spec, new MockIndexedRecord(),
174:                        null));
175:                MockStreamableByteArrayRecord request = new MockStreamableByteArrayRecord();
176:                request.setContent(new byte[] { 1 });
177:                assertTrue(interaction.execute(spec, request, null));
178:                MockStreamableByteArrayRecord response = new MockStreamableByteArrayRecord();
179:                assertTrue(interaction.execute(spec, request, response));
180:                assertNull(response.getContent());
181:                interaction.setResponse(new byte[] { 1, 2, 3 });
182:                assertTrue(interaction.execute(spec, request, response));
183:                assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, response
184:                        .getContent()));
185:                assertFalse(interaction.execute(spec, request,
186:                        new MockMappedRecord()));
187:                assertTrue(interaction.execute(spec, request, new TestRecord()));
188:                interaction.setResponse((byte[]) null);
189:                interaction.setResponse(new TestRecord());
190:                response = new MockStreamableByteArrayRecord();
191:                assertTrue(interaction.execute(spec, request, response));
192:                assertNull(response.getContent());
193:                interaction = new StreamableRecordByteArrayInteraction(null,
194:                        new byte[] { 1 });
195:                assertTrue(interaction.execute(spec, request, response));
196:                assertTrue(Arrays.equals(new byte[] { 1 }, response
197:                        .getContent()));
198:                interaction.setResponse(new TestRecord());
199:                assertTrue(interaction.execute(spec, request, response));
200:                assertTrue(Arrays.equals(new byte[] { 1 }, response
201:                        .getContent()));
202:            }
203:
204:            public static class TestRecord implements  Record, Streamable {
205:                public String getRecordName() {
206:                    return "";
207:                }
208:
209:                public String getRecordShortDescription() {
210:                    return "";
211:                }
212:
213:                public void setRecordName(String name) {
214:
215:                }
216:
217:                public void setRecordShortDescription(String description) {
218:
219:                }
220:
221:                public void read(InputStream stream) throws IOException {
222:
223:                }
224:
225:                public void write(OutputStream stream) throws IOException {
226:
227:                }
228:
229:                public Object clone() throws CloneNotSupportedException {
230:                    return super.clone();
231:                }
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.