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


001:        package org.objectweb.celtix.geronimo.container;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.io.OutputStream;
006:        import java.io.Serializable;
007:        import java.net.URI;
008:        import java.util.HashMap;
009:        import java.util.List;
010:        import java.util.Map;
011:        import java.util.concurrent.Executor;
012:
013:        import javax.xml.namespace.QName;
014:        import javax.xml.ws.Holder;
015:        import javax.xml.ws.handler.MessageContext;
016:
017:        import junit.framework.TestCase;
018:
019:        import org.apache.geronimo.webservices.WebServiceContainer.Request;
020:        import org.apache.geronimo.webservices.WebServiceContainer.Response;
021:        import org.easymock.classextension.EasyMock;
022:        import org.objectweb.celtix.Bus;
023:        import org.objectweb.celtix.configuration.Configuration;
024:        import org.objectweb.celtix.context.InputStreamMessageContext;
025:        import org.objectweb.celtix.context.OutputStreamMessageContext;
026:        import org.objectweb.celtix.geronimo.MockBusFactory;
027:        import org.objectweb.celtix.transports.ServerTransport;
028:        import org.objectweb.celtix.transports.ServerTransportCallback;
029:        import org.objectweb.celtix.ws.addressing.AttributedURIType;
030:        import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
031:        import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
032:
033:        public class GeronimoServerTransportTest extends TestCase {
034:
035:            private Bus mockBus;
036:            private EndpointReferenceType address;
037:            private Holder<InputStreamMessageContext> ctxHolder = new Holder<InputStreamMessageContext>();
038:            private Holder<ServerTransport> transportHolder = new Holder<ServerTransport>();
039:            private Holder<Boolean> invokedHolder = new Holder<Boolean>();
040:            private MockBusFactory busFactory = new MockBusFactory();
041:            private GeronimoServerTransport transport;
042:
043:            public void setUp() throws Exception {
044:
045:                mockBus = busFactory.createMockBus();
046:
047:                address = new EndpointReferenceType();
048:                AttributedURIType uri = new AttributedURIType();
049:                uri.setValue("http://foo.bar.iona.com/wibbly/wobbly/wonder");
050:                address.setAddress(uri);
051:                QName serviceName = new QName("http://www.w3.org/2004/08/wsdl",
052:                        "testServiceName");
053:                EndpointReferenceUtils.setServiceAndPortName(address,
054:                        serviceName, "");
055:
056:                Configuration child = busFactory
057:                        .addChildConfig(
058:                                "http://celtix.objectweb.org/bus/jaxws/endpoint-config",
059:                                null, null);
060:                EasyMock.replay(child);
061:                busFactory.replay();
062:
063:                transport = new GeronimoServerTransport(mockBus, address);
064:
065:            }
066:
067:            public void testTransportIsSerializable() {
068:
069:                assertTrue("transport must be serializable", Serializable.class
070:                        .isAssignableFrom(GeronimoServerTransport.class));
071:            }
072:
073:            public void testCopyHeaders() {
074:
075:                DummyRequest req = new DummyRequest();
076:                req.setHeader("Accept", "text/plain, text/html");
077:                req.setHeader("Host", "localhost");
078:                req.setHeader("Content-Type", "text/html");
079:
080:                GeronimoInputStreamMessageContext ctx = transport
081:                        .createInputStreamMessageContext();
082:                ctx.setRequest(req);
083:
084:                Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
085:                assertTrue(ctx instanceof  MessageContext);
086:                transport.copyRequestHeaders(ctx, headerMap);
087:
088:                assertEquals("unexpected number of headers", 3, headerMap
089:                        .size());
090:                checkHeader(headerMap, "Host", "localhost");
091:                checkHeader(headerMap, "Content-Type", "text/html");
092:                checkHeader(headerMap, "Accept", "text/plain", "text/html");
093:            }
094:
095:            private void checkHeader(Map<String, List<String>> headers,
096:                    String name, String... expectedValues) {
097:
098:                List<String> values = headers.get(name);
099:
100:                int valueCount = 0;
101:
102:                for (String expectedValue : expectedValues) {
103:                    assertTrue("unexpected header value: [" + expectedValue
104:                            + "] " + values, values.contains(expectedValue));
105:                    ++valueCount;
106:                }
107:                assertEquals("unexpected number of header values", valueCount,
108:                        values.size());
109:            }
110:
111:            public void testInvoke() throws Exception {
112:
113:                final Request request = EasyMock.createMock(Request.class);
114:                final Response response = EasyMock.createMock(Response.class);
115:
116:                transport.activate(new ServerTransportCallback() {
117:
118:                    public void dispatch(InputStreamMessageContext ctx,
119:                            ServerTransport tport) {
120:                        invokedHolder.value = Boolean.TRUE;
121:                        ctxHolder.value = ctx;
122:                        transportHolder.value = tport;
123:                    }
124:
125:                    public Executor getExecutor() {
126:                        return null;
127:                    }
128:
129:                });
130:
131:                transport.invoke(request, response);
132:
133:                assertTrue("ServerTransportCallback.dispatch was not called",
134:                        invokedHolder.value);
135:                assertSame("transport not passed to ServerTransportCallback",
136:                        transport, transportHolder.value);
137:
138:                assertNotNull("no context passed from transport",
139:                        ctxHolder.value);
140:                InputStreamMessageContext ctx = ctxHolder.value;
141:                assertTrue("context is of incorrect type: " + ctx.getClass(),
142:                        ctx instanceof  GeronimoInputStreamMessageContext);
143:                GeronimoInputStreamMessageContext inctx = (GeronimoInputStreamMessageContext) ctx;
144:                assertNotNull("request not available in context", inctx
145:                        .getRequest());
146:
147:                assertNotNull("response not available in context", inctx
148:                        .getResponse());
149:            }
150:
151:            public void testCreateOutputStreamContext() throws IOException {
152:
153:                MessageContext mc = EasyMock.createMock(MessageContext.class);
154:                Response resp = EasyMock.createNiceMock(Response.class);
155:                resp.setStatusCode(200);
156:                EasyMock.expect(resp.getOutputStream()).andReturn(
157:                        EasyMock.createNiceMock(OutputStream.class));
158:
159:                EasyMock.expect(
160:                        mc.get(GeronimoInputStreamMessageContext.RESPONSE))
161:                        .andReturn(resp);
162:
163:                EasyMock.expect(mc.get("foo")).andReturn("ret");
164:                EasyMock.replay(mc);
165:                EasyMock.replay(resp);
166:
167:                OutputStreamMessageContext outctx = transport
168:                        .createOutputStreamContext(mc);
169:
170:                assertNotNull("received null context from the transoprt",
171:                        outctx);
172:                assertTrue(
173:                        "incorrect type for context" + outctx.getClass(),
174:                        outctx instanceof  GeronimoOutputStreamServerMessageContext);
175:
176:                assertNotNull("no outputstream in context", outctx
177:                        .getOutputStream());
178:
179:                // check that context passed in has been wrapped.
180:
181:                outctx.get("foo");
182:                EasyMock.verify(mc);
183:
184:            }
185:
186:            static class DummyRequest implements  Request {
187:
188:                private Map<String, String> headers = new HashMap<String, String>();
189:
190:                public void setHeader(String header, String value) {
191:                    headers.put(header, value);
192:                }
193:
194:                public String getHeader(String header) {
195:                    return headers.get(header);
196:                }
197:
198:                public URI getURI() {
199:                    // TODO Auto-generated method stub
200:                    return null;
201:                }
202:
203:                public int getContentLength() {
204:                    // TODO Auto-generated method stub
205:                    return 0;
206:                }
207:
208:                public String getContentType() {
209:                    // TODO Auto-generated method stub
210:                    return null;
211:                }
212:
213:                public InputStream getInputStream() throws IOException {
214:                    // TODO Auto-generated method stub
215:                    return null;
216:                }
217:
218:                public int getMethod() {
219:                    // TODO Auto-generated method stub
220:                    return 0;
221:                }
222:
223:                public String getParameter(String arg0) {
224:                    // TODO Auto-generated method stub
225:                    return null;
226:                }
227:
228:                public Map getParameters() {
229:                    // TODO Auto-generated method stub
230:                    return null;
231:                }
232:
233:                public Object getAttribute(String arg0) {
234:                    // TODO Auto-generated method stub
235:                    return null;
236:                }
237:
238:                public void setAttribute(String arg0, Object arg1) {
239:                    // TODO Auto-generated method stub
240:
241:                }
242:
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.