01: package org.objectweb.celtix.tools.processors.wsdl2;
02:
03: import java.io.File;
04: import java.lang.reflect.Method;
05: import java.net.URLClassLoader;
06:
07: import javax.jws.WebParam;
08: import javax.jws.WebResult;
09: import javax.jws.soap.SOAPBinding;
10: import javax.xml.ws.Holder;
11:
12: import org.objectweb.celtix.tools.WSDLToJava;
13: import org.objectweb.celtix.tools.processors.ProcessorTestBase;
14: import org.objectweb.celtix.tools.utils.AnnotationUtil;
15:
16: public class WSDLToJavaExSoapHeaderTest extends ProcessorTestBase {
17:
18: private URLClassLoader classLoader;
19:
20: public void setUp() throws Exception {
21: super .setUp();
22: File classFile = new java.io.File(output.getCanonicalPath());
23: System.setProperty("java.class.path", getClassPath()
24: + classFile.getCanonicalPath() + File.separatorChar);
25: classLoader = AnnotationUtil.getClassLoader(Thread
26: .currentThread().getContextClassLoader());
27: }
28:
29: public void testSoapBindingDiffMessage() throws Exception {
30: String[] args = new String[] { "-d", output.getCanonicalPath(),
31: "-exsh", "true", "-compile",
32: getLocation("/wsdl/soapheader_test.wsdl") };
33: WSDLToJava.main(args);
34:
35: Class clz = classLoader
36: .loadClass("org.objectweb.header_test.TestHeader");
37: Method method = clz.getMethod("testHeader4", new Class[] {
38: java.lang.String.class, Holder.class });
39: if (method == null) {
40: fail("Missing method testHeader4 of TestHeader class!");
41: }
42: WebParam webParamAnno = AnnotationUtil.getWebParam(method,
43: "testHeaderMessage");
44: if (webParamAnno == null) {
45: fail("Missing 'inoutHeader' WebParam Annotation of method testHeader4!");
46: }
47: assertEquals("INOUT", webParamAnno.mode().name());
48: assertEquals(true, webParamAnno.header());
49: assertEquals("inoutHeader", webParamAnno.partName());
50: }
51:
52: public void testSoapHeaderBinding() throws Exception {
53: String[] args = new String[] { "-d", output.getCanonicalPath(),
54: "-compile", getLocation("/wsdl/soapheader_test.wsdl") };
55: WSDLToJava.main(args);
56:
57: Class clz = classLoader
58: .loadClass("org.objectweb.header_test.TestHeader");
59: Class paramClz = classLoader
60: .loadClass("org.objectweb.header_test.types.TestHeader5");
61: assertEquals(5, clz.getMethods().length);
62:
63: Method method = clz.getMethod("testHeader5",
64: new Class[] { paramClz });
65: if (method == null) {
66: fail("Missing method testHeader5 of TestHeader class!");
67: }
68:
69: SOAPBinding soapBindingAnno = AnnotationUtil
70: .getPrivMethodAnnotation(method, SOAPBinding.class);
71: assertEquals("BARE", soapBindingAnno.parameterStyle().name());
72:
73: WebResult webResultAnno = AnnotationUtil.getWebResult(method);
74: if (webResultAnno == null) {
75: fail("Missing 'in' WebParam Annotation of method testHeader5!");
76: }
77: assertEquals(true, webResultAnno.header());
78: assertEquals("outHeader", webResultAnno.partName());
79: assertEquals("testHeader5", webResultAnno.name());
80: }
81:
82: private String getLocation(String wsdlFile) {
83: return WSDLToJavaExSoapHeaderTest.class.getResource(wsdlFile)
84: .getFile();
85: }
86: }
|