001: package org.objectweb.celtix.bus.bindings.xml;
002:
003: import java.io.*;
004: import java.lang.reflect.Method;
005: import javax.wsdl.WSDLException;
006:
007: import org.w3c.dom.*;
008:
009: import junit.framework.TestCase;
010:
011: import org.objectweb.celtix.Bus;
012: import org.objectweb.celtix.bindings.DataBindingCallback;
013: import org.objectweb.celtix.bus.bindings.TestClientTransport;
014: import org.objectweb.celtix.bus.bindings.TestInputStreamContext;
015: import org.objectweb.celtix.bus.bindings.TestOutputStreamContext;
016: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
017: import org.objectweb.celtix.context.GenericMessageContext;
018: import org.objectweb.celtix.context.ObjectMessageContext;
019: import org.objectweb.celtix.helpers.XMLUtils;
020: import org.objectweb.celtix.transports.ClientTransport;
021: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
022: import org.objectweb.hello_world_xml_http.wrapped.Greeter;
023:
024: public class XMLClientBindingTest extends TestCase {
025: Bus bus;
026: EndpointReferenceType epr;
027: XMLUtils xmlUtils;
028:
029: public XMLClientBindingTest(String arg0) {
030: super (arg0);
031: }
032:
033: public static void main(String[] args) {
034: junit.textui.TestRunner.run(XMLClientBindingTest.class);
035: }
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039: bus = Bus.init();
040:
041: xmlUtils = new XMLUtils();
042: TestUtils testUtils = new TestUtils();
043:
044: epr = testUtils.getWrappedReference();
045: }
046:
047: public void testGetBinding() throws Exception {
048: XMLClientBinding clientBinding = new XMLClientBinding(bus, epr);
049: assertNotNull(clientBinding.getBinding());
050: }
051:
052: public void testCreateObjectContext() throws Exception {
053: XMLClientBinding clientBinding = new XMLClientBinding(bus, epr);
054: assertNotNull(clientBinding.createObjectContext());
055: }
056:
057: public void testRead() throws Exception {
058: TestClientBinding clientBinding = new TestClientBinding(bus,
059: epr);
060: InputStream is = getClass().getResourceAsStream(
061: "resources/SayHiWrappedResp.xml");
062: TestInputStreamContext tisc = new TestInputStreamContext(null);
063: tisc.setInputStream(is);
064: XMLMessageContext xmlContext = new XMLMessageContextImpl(
065: new GenericMessageContext());
066: clientBinding.getBindingImpl().read(tisc, xmlContext);
067:
068: assertNotNull(xmlContext.getMessage());
069:
070: is = getClass().getResourceAsStream(
071: "resources/SayHiWrappedResp.xml");
072: Document expectDOM = xmlUtils.parse(is);
073: assertNotNull(expectDOM);
074: Document resultDOM = xmlContext.getMessage().getRoot();
075: assertNotNull(resultDOM);
076: is.close();
077:
078: assertTrue(expectDOM.isEqualNode(resultDOM));
079: }
080:
081: public void testWrite() throws Exception {
082: TestClientBinding clientBinding = new TestClientBinding(bus,
083: epr);
084: String resource = "resources/SayHiWrappedReq.xml";
085: InputStream is = getClass().getResourceAsStream(resource);
086: assertNotNull(resource + " is not exist.", is);
087:
088: XMLMessageFactory msgFactory = XMLMessageFactory.newInstance();
089: XMLMessage greetMeMsg = msgFactory.createMessage(is);
090: is.close();
091:
092: BufferedReader br = new BufferedReader(new InputStreamReader(
093: getClass().getResourceAsStream(resource)));
094: String expectString = br.readLine();
095:
096: XMLMessageContext xmlContext = new XMLMessageContextImpl(
097: new GenericMessageContext());
098: xmlContext.setMessage(greetMeMsg);
099:
100: TestOutputStreamContext tosc = new TestOutputStreamContext(
101: null, xmlContext);
102: clientBinding.getBindingImpl().write(xmlContext, tosc);
103:
104: byte[] bArray = tosc.getOutputStreamBytes();
105:
106: Document expectDOM = xmlUtils.parse(expectString);
107: Document resultDOM = xmlUtils.parse(bArray);
108:
109: assertTrue(expectDOM.isEqualNode(resultDOM));
110: }
111:
112: public void testInvokeOneWay() throws Exception {
113: TestClientBinding clientBinding = new TestClientBinding(bus,
114: epr);
115: ObjectMessageContext objContext = clientBinding
116: .createObjectContext();
117: assertNotNull(objContext);
118:
119: Method method = ClassUtils.getMethod(Greeter.class,
120: "greetMeOneWay");
121:
122: String arg0 = new String("TestXMLInputMessage");
123: objContext.setMessageObjects(arg0);
124:
125: clientBinding.invokeOneWay(objContext,
126: new JAXBDataBindingCallback(method,
127: DataBindingCallback.Mode.PARTS, null));
128: }
129:
130: class TestClientBinding extends XMLClientBinding {
131:
132: public TestClientBinding(Bus b, EndpointReferenceType ref)
133: throws WSDLException, IOException {
134: super (b, ref);
135: }
136:
137: protected ClientTransport createTransport(
138: EndpointReferenceType ref) throws WSDLException,
139: IOException {
140: // REVISIT: non-null response callback
141: return new TestClientTransport(bus, ref);
142: }
143:
144: }
145: }
|