Source Code Cross Referenced for JBIClientTransportTest.java in  » ESB » celtix-1.0 » org » objectweb » celtix » jbi » transport » 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 » ESB » celtix 1.0 » org.objectweb.celtix.jbi.transport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.jbi.transport;
002:
003:        import java.io.BufferedReader;
004:        import java.io.ByteArrayInputStream;
005:        import java.io.ByteArrayOutputStream;
006:        import java.io.IOException;
007:        import java.io.InputStream;
008:        import java.io.InputStreamReader;
009:        import java.lang.reflect.Method;
010:
011:        import javax.jbi.messaging.DeliveryChannel;
012:        import javax.jbi.messaging.InOut;
013:        import javax.jbi.messaging.MessageExchangeFactory;
014:        import javax.jbi.messaging.NormalizedMessage;
015:        import javax.jws.WebService;
016:        import javax.xml.namespace.QName;
017:        import javax.xml.transform.Source;
018:        import javax.xml.transform.stream.StreamSource;
019:        import javax.xml.ws.handler.MessageContext;
020:
021:        import junit.framework.TestCase;
022:
023:        import org.easymock.classextension.EasyMock;
024:        import org.objectweb.celtix.bindings.ClientBinding;
025:        import org.objectweb.celtix.bindings.ResponseCallback;
026:        import org.objectweb.celtix.context.InputStreamMessageContext;
027:        import org.objectweb.celtix.context.ObjectMessageContextImpl;
028:        import org.objectweb.celtix.context.OutputStreamMessageContext;
029:        import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
030:        import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
031:        import org.objectweb.hello_world_soap_http.Greeter;
032:
033:        public class JBIClientTransportTest extends TestCase {
034:
035:            private static final String TEST_MESSAGE = "<message>this is the test message</message>";
036:            private static final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
037:
038:            private final DeliveryChannel channel = EasyMock
039:                    .createMock(DeliveryChannel.class);
040:            //private final EndpointReferenceType endpointRef = EasyMock.createMock(EndpointReferenceType.class);
041:            private EndpointReferenceType endpointRef;
042:            //private final MetadataType metaData = EasyMock.createMock(MetadataType.class);
043:            private final ClientBinding clientBinding = EasyMock
044:                    .createMock(ClientBinding.class);
045:
046:            private JBIOutputStreamMessageContext outCtx;
047:
048:            private JBIClientTransport clientTransport;
049:            private QName serviceName;
050:            private Method targetMethod;
051:
052:            public void setUp() throws Exception {
053:
054:                initFixture();
055:                clientTransport = new JBIClientTransport(channel, endpointRef,
056:                        clientBinding);
057:
058:                ObjectMessageContextImpl context = new ObjectMessageContextImpl();
059:
060:                outCtx = (JBIOutputStreamMessageContext) clientTransport
061:                        .createOutputStreamContext(context);
062:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
063:                baos.write(TEST_MESSAGE.getBytes());
064:                outCtx.setOutputStream(baos);
065:
066:                targetMethod = Greeter.class.getMethod("sayHi");
067:                assertNotNull("could not set up target method", targetMethod);
068:                context.setMethod(targetMethod);
069:
070:                WebService ws = Greeter.class.getAnnotation(WebService.class);
071:                assertNotNull(ws);
072:                serviceName = new QName(ws.targetNamespace(), ws.name());
073:                initFixture();
074:            }
075:
076:            public void testJBIClientTransport() {
077:
078:                JBIClientTransport ct = new JBIClientTransport(channel,
079:                        endpointRef, clientBinding);
080:                assertNotNull("server transport must not be null", ct);
081:                assertSame("transport must JBIClientTransport",
082:                        JBIClientTransport.class, ct.getClass());
083:                EasyMock.verify(clientBinding);
084:
085:            }
086:
087:            public void testInvokeOneway() {
088:
089:            }
090:
091:            public void testinvoke() throws Exception {
092:
093:                MessageExchangeFactory factory = EasyMock
094:                        .createMock(MessageExchangeFactory.class);
095:                InOut exchange = EasyMock.createMock(InOut.class);
096:                NormalizedMessage message = EasyMock
097:                        .createMock(NormalizedMessage.class);
098:                ByteArrayInputStream messageStream = new ByteArrayInputStream(
099:                        TEST_MESSAGE.getBytes());
100:
101:                channel.createExchangeFactoryForService(serviceName);
102:                EasyMock.expectLastCall().andReturn(factory);
103:                factory.createInOutExchange();
104:                EasyMock.expectLastCall().andReturn(exchange);
105:                exchange.createMessage();
106:                EasyMock.expectLastCall().andReturn(message);
107:                exchange.getEndpoint();
108:                EasyMock.expectLastCall().andReturn(null);
109:                message.setContent((Source) EasyMock.notNull());
110:                exchange.setService(serviceName);
111:                exchange
112:                        .setInterfaceName(new QName(
113:                                "http://objectweb.org/hello_world_soap_http",
114:                                "Greeter"));
115:                exchange.setOperation(new QName(targetMethod.getName()));
116:                exchange.setInMessage(message);
117:                channel.sendSync(exchange);
118:                EasyMock.expectLastCall().andReturn(Boolean.TRUE);
119:                exchange.getOutMessage();
120:                EasyMock.expectLastCall().andReturn(message);
121:                message.getContent();
122:                EasyMock.expectLastCall().andReturn(
123:                        new StreamSource(messageStream));
124:
125:                EasyMock.replay(channel);
126:                EasyMock.replay(factory);
127:                EasyMock.replay(exchange);
128:                EasyMock.replay(message);
129:
130:                InputStreamMessageContext ret = clientTransport.invoke(outCtx);
131:                assertNotNull("invoke must not return null", ret);
132:                assertNotNull("invoke must not return an emtpy context", ret
133:                        .getInputStream());
134:
135:                EasyMock.verify(channel);
136:                EasyMock.verify(factory);
137:                EasyMock.verify(exchange);
138:                EasyMock.verify(message);
139:
140:                BufferedReader reader = new BufferedReader(
141:                        new InputStreamReader(ret.getInputStream()));
142:                // throw away prolog
143:                String s = reader.readLine();
144:                assertNotNull(s);
145:                // chop off the XML declaration
146:
147:                assertTrue(s.startsWith(XML_DECLARATION));
148:                String result = s.substring(XML_DECLARATION.length());
149:                assertEquals("returned message incorrect", TEST_MESSAGE, result);
150:            }
151:
152:            public void testGetMessageContent() throws IOException {
153:
154:                Source ret = clientTransport.getMessageContent(outCtx);
155:
156:                assertNotNull(ret);
157:                assertEquals("incorrect return type", StreamSource.class, ret
158:                        .getClass());
159:                InputStream in = ((StreamSource) ret).getInputStream();
160:                assertNotNull(in);
161:
162:                BufferedReader reader = new BufferedReader(
163:                        new InputStreamReader(in));
164:                assertEquals(TEST_MESSAGE, reader.readLine());
165:            }
166:
167:            public void testInvokeAsync() {
168:
169:            }
170:
171:            public void testFinalPrepareOutputStreamContext() {
172:
173:            }
174:
175:            public void testShutdown() {
176:
177:            }
178:
179:            public void testCreateOutputStreamContext() throws IOException {
180:
181:                MessageContext messageContext = EasyMock
182:                        .createMock(MessageContext.class);
183:                OutputStreamMessageContext ret = clientTransport
184:                        .createOutputStreamContext(messageContext);
185:
186:                assertNotNull("OutputStreamMessageContext must not be null",
187:                        ret);
188:                assertEquals("OutputStreamMessageContext of incorrect type",
189:                        JBIOutputStreamMessageContext.class, ret.getClass());
190:            }
191:
192:            private void initFixture() {
193:
194:                EasyMock.reset(clientBinding);
195:
196:                endpointRef = new EndpointReferenceType();
197:                EndpointReferenceUtils.setServiceAndPortName(endpointRef,
198:                        new QName("http://objectweb.org/hello_world_soap_http",
199:                                "Greeter"), "SOAPPort");
200:                ResponseCallback responseCallback = EasyMock
201:                        .createMock(ResponseCallback.class);
202:                clientBinding.createResponseCallback();
203:                EasyMock.expectLastCall().andReturn(responseCallback);
204:                EasyMock.replay(clientBinding);
205:
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.