Debian Codegraph @

test/wsdl/esr/EsrTestServiceTestCase.java

raw
1 /**
2 * EsrTestServiceTestCase.java
3 *
4 * Test for bug 12636
5 * Uses the Service interface to deal with WSDL instead of stubs.
6 */
7
8 package test.wsdl.esr;
9
10 import org.apache.axis.transport.http.SimpleAxisWorker;
11 import org.apache.axis.utils.NetworkUtils;
12
13 import javax.xml.namespace.QName;
14
15 public class EsrTestServiceTestCase extends junit.framework.TestCase {
16 public EsrTestServiceTestCase(java.lang.String name) {
17 super(name);
18 }
19
20 public void testEsrTestWSDL() throws Exception {
21 javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
22 java.net.URL url = new java.net.URL(new test.wsdl.esr.EsrTestServiceLocator().getEsrTestAddress() + "?WSDL");
23 javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.esr.EsrTestServiceLocator().getServiceName());
24 assertTrue(service != null);
25 }
26
27 public void test1EsrTestEsrInOut() {
28 // Using WSDL file to make a SOAP call
29 try {
30 String thisHost = NetworkUtils.getLocalHostname();
31 String thisPort = System.getProperty("test.functional.ServicePort", "8080");
32
33 //load wsdl file
34 String wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/EsrTest?WSDL";
35 javax.xml.rpc.Service svc =
36 new org.apache.axis.client.Service(
37 wsdlLocation,
38 new javax.xml.namespace.QName("urn:esr.wsdl.test",
39 "EsrTestService")
40 );
41
42 //setting up the call
43 javax.xml.rpc.Call call = svc.createCall(
44 new javax.xml.namespace.QName("urn:esr.wsdl.test",
45 "EsrTest"),
46 new javax.xml.namespace.QName("urn:esr.wsdl.test",
47 "esrInOut")
48 );
49
50 //init in params
51 Object[] soapInParams = new Object[]{new Short((short) 5)};
52
53 //calling soap service
54 Object ret = call.invoke(soapInParams);
55
56 //printing output params
57 java.util.Map outParams = call.getOutputParams();
58
59 // Debug code if you need it
60 /*
61 java.util.Collection outs = outParams.values();
62 java.util.Iterator it = outs.iterator();
63 int i = 1;
64 while (it.hasNext()) {
65 System.out.println(i++ + ". " + it.next().toString());
66 }
67 */
68
69 // Expecting a short and a double back
70 assertEquals("Number of output parameters is wrong", outParams.size(), 2);
71 Object s = outParams.get(new QName("echoVal"));
72 assertNotNull("echoVal paramter is null", s);
73 assertEquals("echoVal parameter is incorrect", (Short)s, new Short((short) 5) );
74 Object sq = outParams.get(new QName("sqrtVal"));
75 assertNotNull("sqrtVal paramter is null", sq);
76 assertEquals("sqrtVal parameter is incorrect", ((Double)sq).doubleValue(), Math.sqrt(5), 0.001D );
77
78 } catch (Exception e) {
79 e.printStackTrace(System.out);
80 throw new junit.framework.AssertionFailedError("Exception caught: " + e);
81 }
82
83 }
84
85 public void test1EsrTestEsrInOut2() {
86 // Using WSDL file to make a SOAP call
87 try {
88 String thisHost = NetworkUtils.getLocalHostname();
89 String thisPort = System.getProperty("test.functional.ServicePort", "8080");
90
91 //load wsdl file
92 String wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/EsrTest?WSDL";
93 javax.xml.rpc.Service svc =
94 new org.apache.axis.client.Service(
95 wsdlLocation,
96 new javax.xml.namespace.QName("urn:esr.wsdl.test",
97 "EsrTestService")
98 );
99
100 //setting up the call
101 javax.xml.rpc.Call call = svc.createCall(
102 new javax.xml.namespace.QName("urn:esr.wsdl.test",
103 "EsrTest"),
104 new javax.xml.namespace.QName("urn:esr.wsdl.test",
105 "esrInOut2")
106 );
107
108 //init in params
109 Object[] soapInParams = new Object[] {
110 "token1",
111 "token2",
112 new Short((short)5) };
113
114 //calling soap service
115 Object ret = call.invoke(soapInParams);
116
117 //printing output params
118 java.util.Map outParams = call.getOutputParams();
119
120 // Debug code if you need it
121 /*
122 java.util.Collection outs = outParams.values();
123 java.util.Iterator it = outs.iterator();
124 int i = 1;
125 while (it.hasNext()) {
126 System.out.println(i++ + ". " + it.next().toString());
127 }
128 */
129
130 // Expecting a short and a double back
131 assertEquals("Number of output parameters is wrong", outParams.size(), 2);
132 Object s = outParams.get(new QName("echoVal"));
133 assertNotNull("echoVal paramter is null", s);
134 assertEquals("echoVal parameter is incorrect", (Short)s, new Short((short) 5) );
135 Object sq = outParams.get(new QName("sqrtVal"));
136 assertNotNull("sqrtVal paramter is null", sq);
137 assertEquals("sqrtVal parameter is incorrect", ((Double)sq).doubleValue(), Math.sqrt(5), 0.001D );
138
139 } catch (Exception e) {
140 e.printStackTrace(System.out);
141 throw new junit.framework.AssertionFailedError("Exception caught: " + e);
142 }
143
144 }
145 }