KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > soap > SOAPClientBindingTest


1 package org.objectweb.celtix.bus.bindings.soap;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.io.InputStreamReader JavaDoc;
7 import java.lang.reflect.Method JavaDoc;
8 import java.net.URL JavaDoc;
9 import java.util.concurrent.Executor JavaDoc;
10 import java.util.concurrent.Future JavaDoc;
11
12 import javax.wsdl.Port;
13 import javax.wsdl.WSDLException;
14 import javax.xml.namespace.QName JavaDoc;
15 import javax.xml.soap.MessageFactory JavaDoc;
16 import javax.xml.soap.SOAPMessage JavaDoc;
17 import javax.xml.ws.handler.MessageContext;
18 import javax.xml.ws.handler.soap.SOAPMessageContext;
19
20 import junit.framework.TestCase;
21
22 import org.objectweb.celtix.Bus;
23 import org.objectweb.celtix.bindings.DataBindingCallback;
24 import org.objectweb.celtix.bindings.ResponseCallback;
25 import org.objectweb.celtix.bus.bindings.TestInputStreamContext;
26 import org.objectweb.celtix.bus.bindings.TestOutputStreamContext;
27 import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
28 import org.objectweb.celtix.context.GenericMessageContext;
29 import org.objectweb.celtix.context.InputStreamMessageContext;
30 import org.objectweb.celtix.context.ObjectMessageContext;
31 import org.objectweb.celtix.context.OutputStreamMessageContext;
32 import org.objectweb.celtix.transports.ClientTransport;
33 import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
34 import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
35 import org.objectweb.hello_world_soap_http.Greeter;
36
37 public class SOAPClientBindingTest extends TestCase {
38     Bus bus;
39     EndpointReferenceType epr;
40     
41     public SOAPClientBindingTest(String JavaDoc arg0) {
42         super(arg0);
43     }
44
45     public static void main(String JavaDoc[] args) {
46         junit.textui.TestRunner.run(SOAPClientBindingTest.class);
47     }
48     
49     protected void setUp() throws Exception JavaDoc {
50         super.setUp();
51         bus = Bus.init();
52         epr = new EndpointReferenceType();
53         
54         URL JavaDoc wsdlUrl = getClass().getResource("/wsdl/hello_world.wsdl");
55         QName JavaDoc serviceName = new QName JavaDoc("http://objectweb.org/hello_world_soap_http", "SOAPService");
56         epr = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName, "SoapPort");
57     }
58
59     public void testGetBinding() throws Exception JavaDoc {
60         SOAPClientBinding clientBinding = new SOAPClientBinding(bus, epr);
61         assertNotNull(clientBinding.getBinding());
62     }
63
64     public void testCreateObjectContext() throws Exception JavaDoc {
65         SOAPClientBinding clientBinding = new SOAPClientBinding(bus, epr);
66         assertNotNull(clientBinding.createObjectContext());
67     }
68     
69     public void testInvokeOneWay() throws Exception JavaDoc {
70         TestClientBinding clientBinding = new TestClientBinding(bus, epr);
71         ObjectMessageContext objContext = clientBinding.createObjectContext();
72         assertNotNull(objContext);
73         Method JavaDoc method = SOAPMessageUtil.getMethod(Greeter.class, "greetMe");
74         
75         String JavaDoc arg0 = new String JavaDoc("TestSOAPInputPMessage");
76         objContext.setMessageObjects(arg0);
77         
78         clientBinding.invokeOneWay(objContext,
79                                    new JAXBDataBindingCallback(method,
80                                                                DataBindingCallback.Mode.PARTS, null));
81     }
82
83     public void testhasFault() throws Exception JavaDoc {
84         TestClientBinding clientBinding = new TestClientBinding(bus, epr);
85         SOAPMessageContext soapCtx = new SOAPMessageContextImpl(new GenericMessageContext());
86
87         InputStream JavaDoc is = getClass().getResourceAsStream("resources/NoSuchCodeDocLiteral.xml");
88         MessageFactory JavaDoc msgFactory = MessageFactory.newInstance();
89         SOAPMessage JavaDoc faultMsg = msgFactory.createMessage(null, is);
90         soapCtx.setMessage(faultMsg);
91         assertTrue(clientBinding.getBindingImpl().hasFault(soapCtx));
92         
93         is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
94         faultMsg = msgFactory.createMessage(null, is);
95         soapCtx.setMessage(faultMsg);
96         assertFalse(clientBinding.getBindingImpl().hasFault(soapCtx));
97     }
98
99     public void testRead() throws Exception JavaDoc {
100         TestClientBinding clientBinding = new TestClientBinding(bus, epr);
101         InputStream JavaDoc is = getClass().getResourceAsStream("resources/GreetMeDocLiteralResp.xml");
102         TestInputStreamContext tisc = new TestInputStreamContext(null);
103         tisc.setInputStream(is);
104         
105         SOAPMessageContext soapCtx = new SOAPMessageContextImpl(new GenericMessageContext());
106         clientBinding.getBindingImpl().read(tisc, soapCtx);
107         assertNotNull(soapCtx.getMessage());
108     }
109
110     public void testWrite() throws Exception JavaDoc {
111         TestClientBinding clientBinding = new TestClientBinding(bus, epr);
112         
113         InputStream JavaDoc is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
114         
115         MessageFactory JavaDoc msgFactory = MessageFactory.newInstance();
116         SOAPMessage JavaDoc greetMeMsg = msgFactory.createMessage(null, is);
117         is.close();
118         
119         BufferedReader JavaDoc br =
120             new BufferedReader JavaDoc(
121                 new InputStreamReader JavaDoc(
122                     getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml")));
123         
124         SOAPMessageContext soapCtx = new SOAPMessageContextImpl(new GenericMessageContext());
125         soapCtx.setMessage(greetMeMsg);
126         
127         TestOutputStreamContext tosc = new TestOutputStreamContext(null, soapCtx);
128         clientBinding.getBindingImpl().write(soapCtx, tosc);
129
130         byte[] bArray = tosc.getOutputStreamBytes();
131         assertEquals(br.readLine(), (new String JavaDoc(bArray)).trim());
132     }
133     
134     class TestClientBinding extends SOAPClientBinding {
135
136         public TestClientBinding(Bus b, EndpointReferenceType ref)
137             throws WSDLException, IOException JavaDoc {
138             super(b, ref);
139         }
140
141         protected ClientTransport createTransport(EndpointReferenceType ref)
142             throws WSDLException, IOException JavaDoc {
143             // REVISIT: non-null response callback
144
return new TestClientTransport(bus, ref);
145         }
146
147     }
148     
149     class TestClientTransport implements ClientTransport {
150         
151         public TestClientTransport(Bus b, EndpointReferenceType ref) {
152         }
153
154         public EndpointReferenceType getTargetEndpoint() {
155             return null;
156         }
157         
158         public EndpointReferenceType getDecoupledEndpoint() throws IOException JavaDoc {
159             return null;
160         }
161         
162         public Port getPort() {
163             return null;
164         }
165
166         public OutputStreamMessageContext createOutputStreamContext(MessageContext context)
167             throws IOException JavaDoc {
168             return new TestOutputStreamContext(null, context);
169         }
170
171         public void finalPrepareOutputStreamContext(OutputStreamMessageContext context) throws IOException JavaDoc {
172         }
173
174         public void invokeOneway(OutputStreamMessageContext context) throws IOException JavaDoc {
175             //nothing to do
176
}
177
178         public InputStreamMessageContext invoke(OutputStreamMessageContext context) throws IOException JavaDoc {
179             return context.getCorrespondingInputStreamContext();
180         }
181
182         public Future JavaDoc<InputStreamMessageContext> invokeAsync(OutputStreamMessageContext context, Executor JavaDoc ex)
183             throws IOException JavaDoc {
184             return null;
185         }
186         
187         public ResponseCallback getResponseCallback() {
188             return null;
189         }
190
191         public void shutdown() {
192             //nothing to do
193
}
194     }
195     
196     
197 }
198
Popular Tags