1 package org.objectweb.celtix.bus.bindings; 2 3 import java.lang.reflect.Method ; 4 import java.net.URL ; 5 6 import javax.jws.WebParam; 7 import javax.jws.WebResult; 8 import javax.wsdl.Definition; 9 import javax.wsdl.Port; 10 import javax.wsdl.factory.WSDLFactory; 11 import javax.wsdl.xml.WSDLReader; 12 import javax.xml.bind.JAXBContext; 13 import javax.xml.namespace.QName ; 14 15 import org.xml.sax.InputSource ; 16 17 import junit.framework.TestCase; 18 19 import org.objectweb.celtix.bindings.DataBindingCallback; 20 import org.objectweb.celtix.bindings.DataBindingCallback.Mode; 21 import org.objectweb.celtix.bindings.DataReader; 22 import org.objectweb.celtix.bindings.DataWriter; 23 import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback; 24 import org.objectweb.celtix.bus.jaxws.JAXBEncoderDecoder; 25 import org.objectweb.celtix.context.ObjectMessageContext; 26 import org.objectweb.hello_world_doc_lit_bare.PutLastTradedPricePortType; 27 import org.objectweb.hello_world_rpclit.GreeterRPCLit; 28 29 public class WSDLMetaDataCacheTest extends TestCase { 30 31 public WSDLMetaDataCacheTest(String name) { 32 super(name); 33 } 34 35 public void testRpcLit() throws Exception { 36 Class <?> cls = GreeterRPCLit.class; 37 JAXBContext ctx = JAXBEncoderDecoder.createJAXBContextForClass(cls); 38 39 URL url = getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl"); 40 assertNotNull("Could not find wsdl /wsdl/hello_world_rpc_lit.wsdl", url); 41 42 43 WSDLFactory factory = WSDLFactory.newInstance(); 44 WSDLReader reader = factory.newWSDLReader(); 45 reader.setFeature("javax.wsdl.verbose", false); 46 InputSource input = new InputSource (url.openStream()); 47 Definition def = reader.readWSDL(null, input); 48 Port port = def.getService(new QName ("http://objectweb.org/hello_world_rpclit", 49 "SOAPServiceRPCLit1")).getPort("SoapPortRPCLit1"); 50 WSDLMetaDataCache wsdl = new WSDLMetaDataCache(def, port); 51 52 for (Method method : cls.getDeclaredMethods()) { 53 DataBindingCallback c1 = new JAXBDataBindingCallback(method, Mode.PARTS, ctx); 54 WSDLOperationInfo info = wsdl.getOperationInfo(c1.getOperationName()); 55 assertNotNull("Could not find operation info in wsdl: " + c1.getOperationName(), info); 56 DataBindingCallback c2 = new WSDLOperationDataBindingCallback(info); 57 compareDataBindingCallbacks(c1, c2); 58 } 59 } 60 61 88 89 public void testDocLitBare() throws Exception { 90 Class <?> cls = PutLastTradedPricePortType.class; 91 JAXBContext ctx = JAXBEncoderDecoder.createJAXBContextForClass(cls); 92 93 URL url = getClass().getResource("/wsdl/doc_lit_bare.wsdl"); 94 assertNotNull("Could not find wsdl /wsdl/doc_lit_bare.wsdl", url); 95 96 97 WSDLFactory factory = WSDLFactory.newInstance(); 98 WSDLReader reader = factory.newWSDLReader(); 99 reader.setFeature("javax.wsdl.verbose", false); 100 InputSource input = new InputSource (url.openStream()); 101 Definition def = reader.readWSDL(null, input); 102 Port port = def.getService(new QName ("http://objectweb.org/hello_world_doc_lit_bare", 103 "SOAPService")).getPort("SoapPort"); 104 WSDLMetaDataCache wsdl = new WSDLMetaDataCache(def, port); 105 106 for (Method method : cls.getDeclaredMethods()) { 107 DataBindingCallback c1 = new JAXBDataBindingCallback(method, Mode.PARTS, ctx); 108 WSDLOperationInfo info = wsdl.getOperationInfo(c1.getOperationName()); 109 assertNotNull("Could not find operation info in wsdl: " + c1.getOperationName(), info); 110 DataBindingCallback c2 = new WSDLOperationDataBindingCallback(info); 111 compareDataBindingCallbacks(c1, c2); 112 } 113 } 114 115 private void compareDataBindingCallbacks(DataBindingCallback c1, DataBindingCallback c2) { 116 assertEquals(c1.getSOAPAction(), c2.getSOAPAction()); 117 118 assertEquals(c1.getSOAPStyle(), c2.getSOAPStyle()); 119 assertEquals(c1.getSOAPUse(), c2.getSOAPUse()); 120 assertEquals(c1.getSOAPParameterStyle(), c2.getSOAPParameterStyle()); 121 122 assertEquals(c1.getOperationName(), c2.getOperationName()); 123 assertEquals(c1.getTargetNamespace(), c2.getTargetNamespace()); 124 assertEquals(c1.getRequestWrapperQName(), c2.getRequestWrapperQName()); 125 assertEquals(c1.getResponseWrapperQName(), c2.getResponseWrapperQName()); 126 127 assertEquals(c1.getParamsLength(), c2.getParamsLength()); 128 assertEquals(c1.getWebResultQName(), c2.getWebResultQName()); 129 130 WebResult w1 = c1.getWebResult(); 131 WebResult w2 = c2.getWebResult(); 132 if (w1 != null || w2 != null) { 133 assertNotNull(w1); 134 assertNotNull(w2); 135 assertEquals(w1.name(), w2.name()); 136 assertEquals(w1.header(), w2.header()); 137 assertEquals(w1.partName(), w2.partName()); 138 assertEquals(w1.targetNamespace(), w2.targetNamespace()); 139 } 140 141 for (int x = 0; x < c1.getParamsLength(); x++) { 142 WebParam wp1 = c1.getWebParam(x); 143 WebParam wp2 = c2.getWebParam(x); 144 if (wp1 != null || wp2 != null) { 145 assertNotNull(wp1); 146 assertNotNull(wp2); 147 assertEquals(wp1.name(), wp2.name()); 148 assertEquals(wp1.header(), wp2.header()); 149 assertEquals(wp1.partName(), wp2.partName()); 150 assertEquals(wp1.targetNamespace(), wp2.targetNamespace()); 151 } 152 } 153 } 154 155 156 class WSDLOperationDataBindingCallback extends AbstractWSDLOperationDataBindingCallback { 157 public WSDLOperationDataBindingCallback(WSDLOperationInfo info) { 158 super(info); 159 } 160 161 public Mode getMode() { 162 return null; 163 } 164 public Class <?>[] getSupportedFormats() { 165 return null; 166 } 167 public <T> DataWriter<T> createWriter(Class <T> cls) { 168 return null; 169 } 170 public <T> DataReader<T> createReader(Class <T> cls) { 171 return null; 172 } 173 174 public void initObjectContext(ObjectMessageContext octx) { 175 177 } 178 } 179 } 180 | Popular Tags |