001: package org.objectweb.celtix.bus.bindings.soap;
002:
003: import java.lang.reflect.Method;
004:
005: import javax.jws.WebMethod;
006: import javax.jws.WebParam;
007: import javax.jws.WebResult;
008: import javax.jws.WebService;
009: import javax.jws.soap.SOAPBinding;
010: import javax.jws.soap.SOAPBinding.Style;
011: import javax.xml.namespace.QName;
012:
013: import junit.framework.TestCase;
014:
015: import org.objectweb.celtix.bindings.DataBindingCallback;
016: import org.objectweb.celtix.bus.jaxws.JAXBDataBindingCallback;
017: import org.objectweb.hello_world_rpclit.GreeterRPCLit;
018: import org.objectweb.hello_world_soap_http.Greeter;
019: import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault;
020:
021: public class SoapMessageInfoTest extends TestCase {
022: private DataBindingCallback msgInfo;
023: private DataBindingCallback rpcMsgInfo;
024: private final String methodNameString = "greetMe";
025:
026: public SoapMessageInfoTest(String arg0) {
027: super (arg0);
028: }
029:
030: public static void main(String[] args) {
031: junit.textui.TestRunner.run(SoapMessageInfoTest.class);
032: }
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: msgInfo = new JAXBDataBindingCallback(SOAPMessageUtil
037: .getMethod(Greeter.class, "greetMe"),
038: DataBindingCallback.Mode.PARTS, null);
039:
040: rpcMsgInfo = new JAXBDataBindingCallback(SOAPMessageUtil
041: .getMethod(GreeterRPCLit.class, "greetMe"),
042: DataBindingCallback.Mode.PARTS, null);
043: }
044:
045: public void testGetSoapStyle() throws Exception {
046: SOAPBinding.Style style = msgInfo.getSOAPStyle();
047: assertEquals(SOAPBinding.Style.DOCUMENT, style);
048: }
049:
050: public void testGetSoapUse() throws Exception {
051: SOAPBinding.Use use = msgInfo.getSOAPUse();
052: assertEquals(SOAPBinding.Use.LITERAL, use);
053: }
054:
055: public void testGetSOAPParameterStyle() throws Exception {
056: SOAPBinding.ParameterStyle paramStyle = msgInfo
057: .getSOAPParameterStyle();
058: assertEquals(SOAPBinding.ParameterStyle.WRAPPED, paramStyle);
059: }
060:
061: public void testGetWebResult() throws Exception {
062: //Wrapped Doc-Lit. : Should consider Namespace.
063: assertNotNull(msgInfo.getWebResult());
064: QName returnType = msgInfo.getWebResultQName();
065: assertEquals(new QName(
066: "http://objectweb.org/hello_world_soap_http/types",
067: "responseType"), returnType);
068:
069: // RPC-Lit Test if WebResult returns the partname with no namespce associated.
070: assertNotNull(rpcMsgInfo.getWebResult());
071: QName rpcReturnType = rpcMsgInfo.getWebResultQName();
072: assertEquals(new QName("", "out"), rpcReturnType);
073:
074: }
075:
076: public void testGetWebParam() throws Exception {
077: WebParam inParam = msgInfo.getWebParam(0);
078: assertEquals(new QName(
079: "http://objectweb.org/hello_world_soap_http/types",
080: "requestType"), new QName(inParam.targetNamespace(),
081: inParam.name()));
082: assertEquals(WebParam.Mode.IN, inParam.mode());
083: assertFalse(inParam.header());
084: }
085:
086: public void testGetOperationName() throws Exception {
087: //Wrapped Doc Lit. Case.
088: String opName = msgInfo.getOperationName();
089: assertEquals(opName, methodNameString);
090:
091: //RPC-Lit case without any customisation.
092: //(It contains WebMethod annotation without any operationName
093: //so should return method name)
094: String opNameRPC = rpcMsgInfo.getOperationName();
095: assertEquals(opNameRPC, methodNameString);
096: }
097:
098: public void testGetOperationNameCustomised() {
099:
100: JAXBDataBindingCallback customMsgInfo = null;
101: Method[] methodList = CustomAnnotationTestHelper.class
102: .getDeclaredMethods();
103:
104: for (Method mt : methodList) {
105: if (mt.getName().equals(methodNameString)) {
106: customMsgInfo = new JAXBDataBindingCallback(mt,
107: DataBindingCallback.Mode.PARTS, null);
108: break;
109: }
110: }
111:
112: String opNameRPC = customMsgInfo.getOperationName();
113: assertEquals(opNameRPC, "customGreetMe");
114:
115: }
116:
117: public void testGetRequestWrapperQName() throws Exception {
118: QName reqWrapper = msgInfo.getRequestWrapperQName();
119: assertNotNull(reqWrapper);
120: assertEquals(new QName(
121: "http://objectweb.org/hello_world_soap_http/types",
122: "greetMe"), reqWrapper);
123: }
124:
125: public void testGetResponseWrapperQName() throws Exception {
126: QName respWrapper = msgInfo.getResponseWrapperQName();
127: assertNotNull(respWrapper);
128: assertEquals(new QName(
129: "http://objectweb.org/hello_world_soap_http/types",
130: "greetMeResponse"), respWrapper);
131: }
132:
133: public void testGetResponseWrapperType() throws Exception {
134: String respWrapperType = ((JAXBDataBindingCallback) msgInfo)
135: .getResponseWrapperType();
136: assertNotNull(respWrapperType);
137: assertEquals(
138: "org.objectweb.hello_world_soap_http.types.GreetMeResponse",
139: respWrapperType);
140: }
141:
142: public void testDefaults() throws Exception {
143: JAXBDataBindingCallback info = null;
144:
145: Method[] declMethods = String.class.getDeclaredMethods();
146: for (Method method : declMethods) {
147: if (method.getName().equals("length")) {
148: info = new JAXBDataBindingCallback(method,
149: DataBindingCallback.Mode.PARTS, null);
150: break;
151: }
152: }
153:
154: assertNotNull(info);
155: assertEquals(SOAPBinding.Style.DOCUMENT, info.getSOAPStyle());
156: assertEquals(SOAPBinding.Use.LITERAL, info.getSOAPUse());
157: assertEquals(SOAPBinding.ParameterStyle.WRAPPED, info
158: .getSOAPParameterStyle());
159: assertEquals("length", info.getOperationName());
160: assertEquals("", info.getSOAPAction());
161: assertNull(info.getWebResult());
162: assertEquals(SOAPConstants.EMPTY_QNAME, info
163: .getWebResultQName());
164: assertNull(info.getWebParam(1));
165: assertEquals(SOAPConstants.EMPTY_QNAME, info
166: .getRequestWrapperQName());
167: assertEquals(SOAPConstants.EMPTY_QNAME, info
168: .getResponseWrapperQName());
169: assertEquals("", info.getRequestWrapperType());
170: assertEquals("", info.getResponseWrapperType());
171: }
172:
173: public void testHasWebFault() throws Exception {
174: JAXBDataBindingCallback jaxbmi = (JAXBDataBindingCallback) msgInfo;
175: QName faultName = new QName(
176: "http://objectweb.org/hello_world_soap_http/types",
177: "NoSuchCodeLit");
178: assertNull(jaxbmi.getWebFault(faultName));
179:
180: jaxbmi = new JAXBDataBindingCallback(SOAPMessageUtil.getMethod(
181: Greeter.class, "testDocLitFault"),
182: DataBindingCallback.Mode.PARTS, null);
183: Class<?> clazz = jaxbmi.getWebFault(faultName);
184: assertNotNull(clazz);
185: assertTrue(NoSuchCodeLitFault.class.isAssignableFrom(clazz));
186: }
187:
188: @WebService(name="CustomAnnotationTestHelper",targetNamespace="http://objectweb.org/hello_world_rpclit",wsdlLocation="C:\\celtix\\rpc-lit\\trunk/test/wsdl/hello_world_rpc_lit.wsdl")
189: @SOAPBinding(style=Style.RPC)
190: public interface CustomAnnotationTestHelper {
191: @WebMethod(operationName="customGreetMe")
192: @WebResult(name="out",targetNamespace="http://objectweb.org/hello_world_rpclit",partName="out")
193: String greetMe(@WebParam(name="in",partName="in")
194: String in);
195: }
196: }
|