01: package org.objectweb.celtix.bus.ws.rm.persistence;
02:
03: import java.io.InputStream;
04:
05: import javax.xml.soap.SOAPMessage;
06: import javax.xml.ws.handler.MessageContext;
07: import javax.xml.ws.handler.soap.SOAPMessageContext;
08:
09: import junit.framework.TestCase;
10:
11: import org.objectweb.celtix.bindings.DataBindingCallback;
12: import org.objectweb.celtix.bus.bindings.soap.SOAPBindingImpl;
13: import org.objectweb.celtix.bus.bindings.soap.SOAPMessageUtil;
14: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
15: import org.objectweb.celtix.context.ObjectMessageContext;
16: import org.objectweb.celtix.context.ObjectMessageContextImpl;
17: import org.objectweb.hello_world_soap_http.Greeter;
18:
19: public class PersistenceUtilsTest extends TestCase {
20:
21: public void testContext() throws Exception {
22:
23: SOAPBindingImpl binding = new SOAPBindingImpl(false);
24: ObjectMessageContextImpl objContext = new ObjectMessageContextImpl();
25: objContext.setMethod(SOAPMessageUtil.getMethod(Greeter.class,
26: "greetMe"));
27: SOAPMessageContext soapContext = (SOAPMessageContext) binding
28: .createBindingMessageContext(objContext);
29: soapContext.put(ObjectMessageContext.MESSAGE_INPUT, false);
30: String arg0 = new String("TestSOAPInputPMessage");
31: objContext.setMessageObjects(arg0);
32:
33: binding.marshal(objContext, soapContext,
34: new JAXBDataBindingCallback(objContext.getMethod(),
35: DataBindingCallback.Mode.PARTS, null));
36: SOAPMessage msg = soapContext.getMessage();
37:
38: PersistenceUtils pu = new PersistenceUtils();
39: InputStream is = pu.getContextAsInputStream(soapContext);
40: assert null != is;
41: MessageContext restored = pu.getContext(is);
42: assertEquals(3, restored.keySet().size());
43: assertEquals(soapContext
44: .get(ObjectMessageContext.MESSAGE_INPUT), restored
45: .get(ObjectMessageContext.MESSAGE_INPUT));
46: Object[] params = (Object[]) soapContext
47: .get(ObjectMessageContext.METHOD_PARAMETERS);
48: Object[] restoredParams = (Object[]) restored
49: .get(ObjectMessageContext.METHOD_PARAMETERS);
50: assertEquals(params.length, restoredParams.length);
51: assertEquals(params[0], restoredParams[0]);
52: SOAPMessage restoredMsg = ((SOAPMessageContext) binding
53: .createBindingMessageContext(objContext)).getMessage();
54: assertEquals(msg.getSOAPBody().getChildNodes().getLength(),
55: restoredMsg.getSOAPBody().getChildNodes().getLength());
56: assertNull(msg.getSOAPHeader());
57: assertNull(restoredMsg.getSOAPHeader());
58:
59: InputStream is2 = pu.getContextAsInputStream(restored);
60: is.reset();
61: is2.reset();
62: assertEquals(is.available(), is2.available());
63: }
64:
65: }
|