KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > soap > SoapMessageInfoTest


1 package org.objectweb.celtix.bus.bindings.soap;
2
3 import java.lang.reflect.Method JavaDoc;
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 JavaDoc;
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 JavaDoc methodNameString = "greetMe";
25       
26     
27     public SoapMessageInfoTest(String JavaDoc arg0) {
28         super(arg0);
29     }
30
31     public static void main(String JavaDoc[] args) {
32         junit.textui.TestRunner.run(SoapMessageInfoTest.class);
33     }
34     
35     protected void setUp() throws Exception JavaDoc {
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 JavaDoc {
47         SOAPBinding.Style style = msgInfo.getSOAPStyle();
48         assertEquals(SOAPBinding.Style.DOCUMENT, style);
49     }
50
51     public void testGetSoapUse() throws Exception JavaDoc {
52         SOAPBinding.Use use = msgInfo.getSOAPUse();
53         assertEquals(SOAPBinding.Use.LITERAL, use);
54     }
55
56     public void testGetSOAPParameterStyle() throws Exception JavaDoc {
57         SOAPBinding.ParameterStyle paramStyle = msgInfo.getSOAPParameterStyle();
58         assertEquals(SOAPBinding.ParameterStyle.WRAPPED, paramStyle);
59     }
60
61     public void testGetWebResult() throws Exception JavaDoc {
62        //Wrapped Doc-Lit. : Should consider Namespace.
63
assertNotNull(msgInfo.getWebResult());
64         QName JavaDoc returnType = msgInfo.getWebResultQName();
65         assertEquals(
66                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http/types", "responseType"),
67                 returnType);
68          
69         // RPC-Lit Test if WebResult returns the partname with no namespce associated.
70
assertNotNull(rpcMsgInfo.getWebResult());
71         QName JavaDoc rpcReturnType = rpcMsgInfo.getWebResultQName();
72         assertEquals(new QName JavaDoc("", "out"), rpcReturnType);
73         
74     }
75    
76     public void testGetWebParam() throws Exception JavaDoc {
77         WebParam inParam = msgInfo.getWebParam(0);
78         assertEquals(
79                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http/types", "requestType"),
80                 new QName JavaDoc(inParam.targetNamespace(), inParam.name()));
81         assertEquals(WebParam.Mode.IN, inParam.mode());
82         assertFalse(inParam.header());
83     }
84     
85     public void testGetOperationName() throws Exception JavaDoc {
86         //Wrapped Doc Lit. Case.
87
String JavaDoc opName = msgInfo.getOperationName();
88         assertEquals(opName, methodNameString);
89         
90         //RPC-Lit case without any customisation.
91
//(It contains WebMethod annotation without any operationName
92
//so should return method name)
93
String JavaDoc opNameRPC = rpcMsgInfo.getOperationName();
94         assertEquals(opNameRPC, methodNameString);
95     }
96     
97     public void testGetOperationNameCustomised() {
98     
99         JAXBDataBindingCallback customMsgInfo = null;
100         Method JavaDoc [] methodList = CustomAnnotationTestHelper.class.getDeclaredMethods();
101         
102         for (Method JavaDoc 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 JavaDoc opNameRPC = customMsgInfo.getOperationName();
112         assertEquals(opNameRPC, "customGreetMe");
113         
114     }
115
116     public void testGetRequestWrapperQName() throws Exception JavaDoc {
117         QName JavaDoc reqWrapper = msgInfo.getRequestWrapperQName();
118         assertNotNull(reqWrapper);
119         assertEquals(
120                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http/types", "greetMe"),
121                 reqWrapper);
122     }
123     
124     public void testGetResponseWrapperQName() throws Exception JavaDoc {
125         QName JavaDoc respWrapper = msgInfo.getResponseWrapperQName();
126         assertNotNull(respWrapper);
127         assertEquals(
128                 new QName JavaDoc("http://objectweb.org/hello_world_soap_http/types", "greetMeResponse"),
129                 respWrapper);
130     }
131     
132     public void testGetResponseWrapperType() throws Exception JavaDoc {
133         String JavaDoc 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 JavaDoc {
141         JAXBDataBindingCallback info = null;
142         
143         Method JavaDoc[] declMethods = String JavaDoc.class.getDeclaredMethods();
144         for (Method JavaDoc 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 JavaDoc {
169         JAXBDataBindingCallback jaxbmi = (JAXBDataBindingCallback)msgInfo;
170         QName JavaDoc faultName = new QName JavaDoc("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 JavaDoc<?> 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 JavaDoc greetMe(
191             @WebParam(name = "in", partName = "in")
192             String JavaDoc in);
193     }
194 }
195
Popular Tags