1 package org.objectweb.celtix.bus.bindings.soap; 2 3 import java.lang.reflect.Method ; 4 5 import javax.jws.WebMethod; 6 import javax.jws.WebParam; 7 import javax.jws.WebResult; 8 import javax.jws.WebService; 9 import javax.jws.soap.SOAPBinding; 10 import javax.jws.soap.SOAPBinding.Style; 11 import javax.xml.namespace.QName ; 12 13 import junit.framework.TestCase; 14 15 import org.objectweb.celtix.bindings.DataBindingCallback; 16 import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback; 17 import org.objectweb.hello_world_rpclit.GreeterRPCLit; 18 import org.objectweb.hello_world_soap_http.Greeter; 19 import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault; 20 21 public class SoapMessageInfoTest extends TestCase { 22 private DataBindingCallback msgInfo; 23 private DataBindingCallback rpcMsgInfo; 24 private final String methodNameString = "greetMe"; 25 26 27 public SoapMessageInfoTest(String arg0) { 28 super(arg0); 29 } 30 31 public static void main(String [] args) { 32 junit.textui.TestRunner.run(SoapMessageInfoTest.class); 33 } 34 35 protected void setUp() throws Exception { 36 super.setUp(); 37 msgInfo = new JAXBDataBindingCallback(SOAPMessageUtil.getMethod(Greeter.class, "greetMe"), 38 DataBindingCallback.Mode.PARTS, 39 null); 40 41 rpcMsgInfo = new JAXBDataBindingCallback(SOAPMessageUtil.getMethod(GreeterRPCLit.class, "greetMe"), 42 DataBindingCallback.Mode.PARTS, 43 null); 44 } 45 46 public void testGetSoapStyle() throws Exception { 47 SOAPBinding.Style style = msgInfo.getSOAPStyle(); 48 assertEquals(SOAPBinding.Style.DOCUMENT, style); 49 } 50 51 public void testGetSoapUse() throws Exception { 52 SOAPBinding.Use use = msgInfo.getSOAPUse(); 53 assertEquals(SOAPBinding.Use.LITERAL, use); 54 } 55 56 public void testGetSOAPParameterStyle() throws Exception { 57 SOAPBinding.ParameterStyle paramStyle = msgInfo.getSOAPParameterStyle(); 58 assertEquals(SOAPBinding.ParameterStyle.WRAPPED, paramStyle); 59 } 60 61 public void testGetWebResult() throws Exception { 62 assertNotNull(msgInfo.getWebResult()); 64 QName returnType = msgInfo.getWebResultQName(); 65 assertEquals( 66 new QName ("http://objectweb.org/hello_world_soap_http/types", "responseType"), 67 returnType); 68 69 assertNotNull(rpcMsgInfo.getWebResult()); 71 QName rpcReturnType = rpcMsgInfo.getWebResultQName(); 72 assertEquals(new QName ("", "out"), rpcReturnType); 73 74 } 75 76 public void testGetWebParam() throws Exception { 77 WebParam inParam = msgInfo.getWebParam(0); 78 assertEquals( 79 new QName ("http://objectweb.org/hello_world_soap_http/types", "requestType"), 80 new QName (inParam.targetNamespace(), inParam.name())); 81 assertEquals(WebParam.Mode.IN, inParam.mode()); 82 assertFalse(inParam.header()); 83 } 84 85 public void testGetOperationName() throws Exception { 86 String opName = msgInfo.getOperationName(); 88 assertEquals(opName, methodNameString); 89 90 String opNameRPC = rpcMsgInfo.getOperationName(); 94 assertEquals(opNameRPC, methodNameString); 95 } 96 97 public void testGetOperationNameCustomised() { 98 99 JAXBDataBindingCallback customMsgInfo = null; 100 Method [] methodList = CustomAnnotationTestHelper.class.getDeclaredMethods(); 101 102 for (Method mt : methodList) { 103 if (mt.getName().equals(methodNameString)) { 104 customMsgInfo = new JAXBDataBindingCallback(mt, 105 DataBindingCallback.Mode.PARTS, 106 null); 107 break; 108 } 109 } 110 111 String opNameRPC = customMsgInfo.getOperationName(); 112 assertEquals(opNameRPC, "customGreetMe"); 113 114 } 115 116 public void testGetRequestWrapperQName() throws Exception { 117 QName reqWrapper = msgInfo.getRequestWrapperQName(); 118 assertNotNull(reqWrapper); 119 assertEquals( 120 new QName ("http://objectweb.org/hello_world_soap_http/types", "greetMe"), 121 reqWrapper); 122 } 123 124 public void testGetResponseWrapperQName() throws Exception { 125 QName respWrapper = msgInfo.getResponseWrapperQName(); 126 assertNotNull(respWrapper); 127 assertEquals( 128 new QName ("http://objectweb.org/hello_world_soap_http/types", "greetMeResponse"), 129 respWrapper); 130 } 131 132 public void testGetResponseWrapperType() throws Exception { 133 String respWrapperType = ((JAXBDataBindingCallback)msgInfo).getResponseWrapperType(); 134 assertNotNull(respWrapperType); 135 assertEquals( 136 "org.objectweb.hello_world_soap_http.types.GreetMeResponse", 137 respWrapperType); 138 } 139 140 public void testDefaults() throws Exception { 141 JAXBDataBindingCallback info = null; 142 143 Method [] declMethods = String .class.getDeclaredMethods(); 144 for (Method method : declMethods) { 145 if (method.getName().equals("length")) { 146 info = new JAXBDataBindingCallback(method, 147 DataBindingCallback.Mode.PARTS, 148 null); 149 break; 150 } 151 } 152 153 assertNotNull(info); 154 assertEquals(SOAPBinding.Style.DOCUMENT, info.getSOAPStyle()); 155 assertEquals(SOAPBinding.Use.LITERAL, info.getSOAPUse()); 156 assertEquals(SOAPBinding.ParameterStyle.WRAPPED, info.getSOAPParameterStyle()); 157 assertEquals("length", info.getOperationName()); 158 assertEquals("", info.getSOAPAction()); 159 assertNull(info.getWebResult()); 160 assertEquals(SOAPConstants.EMPTY_QNAME, info.getWebResultQName()); 161 assertNull(info.getWebParam(1)); 162 assertEquals(SOAPConstants.EMPTY_QNAME, info.getRequestWrapperQName()); 163 assertEquals(SOAPConstants.EMPTY_QNAME, info.getResponseWrapperQName()); 164 assertEquals("", info.getRequestWrapperType()); 165 assertEquals("", info.getResponseWrapperType()); 166 } 167 168 public void testHasWebFault() throws Exception { 169 JAXBDataBindingCallback jaxbmi = (JAXBDataBindingCallback)msgInfo; 170 QName faultName = new QName ("http://objectweb.org/hello_world_soap_http/types", "NoSuchCodeLit"); 171 assertNull(jaxbmi.getWebFault(faultName)); 172 173 jaxbmi = new JAXBDataBindingCallback(SOAPMessageUtil.getMethod(Greeter.class, "testDocLitFault"), 174 DataBindingCallback.Mode.PARTS, 175 null); 176 Class <?> clazz = jaxbmi.getWebFault(faultName); 177 assertNotNull(clazz); 178 assertTrue(NoSuchCodeLitFault.class.isAssignableFrom(clazz)); 179 } 180 181 @WebService(name = "CustomAnnotationTestHelper", 182 targetNamespace = "http://objectweb.org/hello_world_rpclit", 183 wsdlLocation = "C:\\celtix\\rpc-lit\\trunk/test/wsdl/hello_world_rpc_lit.wsdl") 184 @SOAPBinding(style = Style.RPC) 185 public interface CustomAnnotationTestHelper { 186 @WebMethod(operationName = "customGreetMe") 187 @WebResult(name = "out", 188 targetNamespace = "http://objectweb.org/hello_world_rpclit", 189 partName = "out") 190 String greetMe( 191 @WebParam(name = "in", partName = "in") 192 String in); 193 } 194 } 195 | Popular Tags |