001: package org.objectweb.celtix.bus.bindings;
002:
003: import java.lang.reflect.Method;
004: import java.net.URL;
005:
006: import javax.jws.WebParam;
007: import javax.jws.WebResult;
008: import javax.wsdl.Definition;
009: import javax.wsdl.Port;
010: import javax.wsdl.factory.WSDLFactory;
011: import javax.wsdl.xml.WSDLReader;
012: import javax.xml.bind.JAXBContext;
013: import javax.xml.namespace.QName;
014:
015: import org.xml.sax.InputSource;
016:
017: import junit.framework.TestCase;
018:
019: import org.objectweb.celtix.bindings.DataBindingCallback;
020: import org.objectweb.celtix.bindings.DataBindingCallback.Mode;
021: import org.objectweb.celtix.bindings.DataReader;
022: import org.objectweb.celtix.bindings.DataWriter;
023: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
024: import org.objectweb.celtix.bus.jaxws.JAXBEncoderDecoder;
025: import org.objectweb.celtix.context.ObjectMessageContext;
026: import org.objectweb.hello_world_doc_lit_bare.PutLastTradedPricePortType;
027: import org.objectweb.hello_world_rpclit.GreeterRPCLit;
028:
029: public class WSDLMetaDataCacheTest extends TestCase {
030:
031: public WSDLMetaDataCacheTest(String name) {
032: super (name);
033: }
034:
035: public void testRpcLit() throws Exception {
036: Class<?> cls = GreeterRPCLit.class;
037: JAXBContext ctx = JAXBEncoderDecoder
038: .createJAXBContextForClass(cls);
039:
040: URL url = getClass().getResource(
041: "/wsdl/hello_world_rpc_lit.wsdl");
042: assertNotNull(
043: "Could not find wsdl /wsdl/hello_world_rpc_lit.wsdl",
044: url);
045:
046: WSDLFactory factory = WSDLFactory.newInstance();
047: WSDLReader reader = factory.newWSDLReader();
048: reader.setFeature("javax.wsdl.verbose", false);
049: InputSource input = new InputSource(url.openStream());
050: Definition def = reader.readWSDL(null, input);
051: Port port = def.getService(
052: new QName("http://objectweb.org/hello_world_rpclit",
053: "SOAPServiceRPCLit1")).getPort(
054: "SoapPortRPCLit1");
055: WSDLMetaDataCache wsdl = new WSDLMetaDataCache(def, port);
056:
057: for (Method method : cls.getDeclaredMethods()) {
058: DataBindingCallback c1 = new JAXBDataBindingCallback(
059: method, Mode.PARTS, ctx);
060: WSDLOperationInfo info = wsdl.getOperationInfo(c1
061: .getOperationName());
062: assertNotNull("Could not find operation info in wsdl: "
063: + c1.getOperationName(), info);
064: DataBindingCallback c2 = new WSDLOperationDataBindingCallback(
065: info);
066: compareDataBindingCallbacks(c1, c2);
067: }
068: }
069:
070: /*REVISIT - the OperationInfo thing doesn't support wrapped doc/lit yet
071: public void testDocLit() throws Exception {
072: Class<?> cls = org.objectweb.hello_world_doc_lit.Greeter.class;
073: JAXBContext ctx = JAXBEncoderDecoder.createJAXBContextForClass(cls);
074:
075: URL url = getClass().getResource("/wsdl/hello_world_doc_lit.wsdl");
076: assertNotNull("Could not find wsdl /wsdl/hello_world_doc_lit.wsdl", url);
077:
078:
079: WSDLFactory factory = WSDLFactory.newInstance();
080: WSDLReader reader = factory.newWSDLReader();
081: reader.setFeature("javax.wsdl.verbose", false);
082: InputSource input = new InputSource(url.openStream());
083: Definition def = reader.readWSDL(null, input);
084: Port port = def.getService(new QName("http://objectweb.org/hello_world_doc_lit",
085: "SOAPService")).getPort("SoapPort");
086: WSDLMetaDataCache wsdl = new WSDLMetaDataCache(def, port);
087:
088: for (Method method : cls.getDeclaredMethods()) {
089: DataBindingCallback c1 = new JAXBDataBindingCallback(method, Mode.PARTS, ctx);
090: WSDLOperationInfo info = wsdl.getOperationInfo(c1.getOperationName());
091: assertNotNull("Could not find operation info in wsdl: " + c1.getOperationName(), info);
092: DataBindingCallback c2 = new WSDLOperationDataBindingCallback(info);
093: compareDataBindingCallbacks(c1, c2);
094: }
095: }
096: */
097:
098: public void testDocLitBare() throws Exception {
099: Class<?> cls = PutLastTradedPricePortType.class;
100: JAXBContext ctx = JAXBEncoderDecoder
101: .createJAXBContextForClass(cls);
102:
103: URL url = getClass().getResource("/wsdl/doc_lit_bare.wsdl");
104: assertNotNull("Could not find wsdl /wsdl/doc_lit_bare.wsdl",
105: url);
106:
107: WSDLFactory factory = WSDLFactory.newInstance();
108: WSDLReader reader = factory.newWSDLReader();
109: reader.setFeature("javax.wsdl.verbose", false);
110: InputSource input = new InputSource(url.openStream());
111: Definition def = reader.readWSDL(null, input);
112: Port port = def
113: .getService(
114: new QName(
115: "http://objectweb.org/hello_world_doc_lit_bare",
116: "SOAPService")).getPort("SoapPort");
117: WSDLMetaDataCache wsdl = new WSDLMetaDataCache(def, port);
118:
119: for (Method method : cls.getDeclaredMethods()) {
120: DataBindingCallback c1 = new JAXBDataBindingCallback(
121: method, Mode.PARTS, ctx);
122: WSDLOperationInfo info = wsdl.getOperationInfo(c1
123: .getOperationName());
124: assertNotNull("Could not find operation info in wsdl: "
125: + c1.getOperationName(), info);
126: DataBindingCallback c2 = new WSDLOperationDataBindingCallback(
127: info);
128: compareDataBindingCallbacks(c1, c2);
129: }
130: }
131:
132: private void compareDataBindingCallbacks(DataBindingCallback c1,
133: DataBindingCallback c2) {
134: assertEquals(c1.getSOAPAction(), c2.getSOAPAction());
135:
136: assertEquals(c1.getSOAPStyle(), c2.getSOAPStyle());
137: assertEquals(c1.getSOAPUse(), c2.getSOAPUse());
138: assertEquals(c1.getSOAPParameterStyle(), c2
139: .getSOAPParameterStyle());
140:
141: assertEquals(c1.getOperationName(), c2.getOperationName());
142: assertEquals(c1.getTargetNamespace(), c2.getTargetNamespace());
143: assertEquals(c1.getRequestWrapperQName(), c2
144: .getRequestWrapperQName());
145: assertEquals(c1.getResponseWrapperQName(), c2
146: .getResponseWrapperQName());
147:
148: assertEquals(c1.getParamsLength(), c2.getParamsLength());
149: assertEquals(c1.getWebResultQName(), c2.getWebResultQName());
150:
151: WebResult w1 = c1.getWebResult();
152: WebResult w2 = c2.getWebResult();
153: if (w1 != null || w2 != null) {
154: assertNotNull(w1);
155: assertNotNull(w2);
156: assertEquals(w1.name(), w2.name());
157: assertEquals(w1.header(), w2.header());
158: assertEquals(w1.partName(), w2.partName());
159: assertEquals(w1.targetNamespace(), w2.targetNamespace());
160: }
161:
162: for (int x = 0; x < c1.getParamsLength(); x++) {
163: WebParam wp1 = c1.getWebParam(x);
164: WebParam wp2 = c2.getWebParam(x);
165: if (wp1 != null || wp2 != null) {
166: assertNotNull(wp1);
167: assertNotNull(wp2);
168: assertEquals(wp1.name(), wp2.name());
169: assertEquals(wp1.header(), wp2.header());
170: assertEquals(wp1.partName(), wp2.partName());
171: assertEquals(wp1.targetNamespace(), wp2
172: .targetNamespace());
173: }
174: }
175: }
176:
177: class WSDLOperationDataBindingCallback extends
178: AbstractWSDLOperationDataBindingCallback {
179: public WSDLOperationDataBindingCallback(WSDLOperationInfo info) {
180: super (info);
181: }
182:
183: public Mode getMode() {
184: return null;
185: }
186:
187: public Class<?>[] getSupportedFormats() {
188: return null;
189: }
190:
191: public <T> DataWriter<T> createWriter(Class<T> cls) {
192: return null;
193: }
194:
195: public <T> DataReader<T> createReader(Class<T> cls) {
196: return null;
197: }
198:
199: public void initObjectContext(ObjectMessageContext octx) {
200: // TODO Auto-generated method stub
201:
202: }
203: }
204: }
|