KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > esr > EsrTestServiceTestCase


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 JavaDoc;
14
15 public class EsrTestServiceTestCase extends junit.framework.TestCase {
16     public EsrTestServiceTestCase(java.lang.String JavaDoc name) {
17         super(name);
18     }
19
20     public void testEsrTestWSDL() throws Exception JavaDoc {
21         javax.xml.rpc.ServiceFactory JavaDoc serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
22         java.net.URL JavaDoc url = new java.net.URL JavaDoc(new test.wsdl.esr.EsrTestServiceLocator().getEsrTestAddress() + "?WSDL");
23         javax.xml.rpc.Service JavaDoc 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 JavaDoc thisHost = NetworkUtils.getLocalHostname();
31             String JavaDoc thisPort = System.getProperty("test.functional.ServicePort", "8080");
32
33             //load wsdl file
34
String JavaDoc wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/EsrTest?WSDL";
35             javax.xml.rpc.Service JavaDoc svc =
36                     new org.apache.axis.client.Service(
37                             wsdlLocation,
38                             new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
39                                     "EsrTestService")
40                     );
41             
42             //setting up the call
43
javax.xml.rpc.Call JavaDoc call = svc.createCall(
44                     new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
45                             "EsrTest"),
46                     new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
47                                     "esrInOut")
48             );
49             
50             //init in params
51
Object JavaDoc[] soapInParams = new Object JavaDoc[]{new Short JavaDoc((short) 5)};
52             
53             //calling soap service
54
Object JavaDoc ret = call.invoke(soapInParams);
55             
56             //printing output params
57
java.util.Map JavaDoc 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 JavaDoc s = outParams.get(new QName JavaDoc("echoVal"));
72             assertNotNull("echoVal paramter is null", s);
73             assertEquals("echoVal parameter is incorrect", (Short JavaDoc)s, new Short JavaDoc((short) 5) );
74             Object JavaDoc sq = outParams.get(new QName JavaDoc("sqrtVal"));
75             assertNotNull("sqrtVal paramter is null", sq);
76             assertEquals("sqrtVal parameter is incorrect", ((Double JavaDoc)sq).doubleValue(), Math.sqrt(5), 0.001D );
77
78         } catch (Exception JavaDoc 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 JavaDoc thisHost = NetworkUtils.getLocalHostname();
89             String JavaDoc thisPort = System.getProperty("test.functional.ServicePort", "8080");
90
91             //load wsdl file
92
String JavaDoc wsdlLocation = "http://" + thisHost + ":" + thisPort + "/axis/services/EsrTest?WSDL";
93             javax.xml.rpc.Service JavaDoc svc =
94                     new org.apache.axis.client.Service(
95                             wsdlLocation,
96                             new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
97                                     "EsrTestService")
98                     );
99             
100             //setting up the call
101
javax.xml.rpc.Call JavaDoc call = svc.createCall(
102                     new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
103                             "EsrTest"),
104                     new javax.xml.namespace.QName JavaDoc("urn:esr.wsdl.test",
105                                     "esrInOut2")
106             );
107             
108             //init in params
109
Object JavaDoc[] soapInParams = new Object JavaDoc[] {
110                                               "token1",
111                                               "token2",
112                                               new Short JavaDoc((short)5) };
113             
114             //calling soap service
115
Object JavaDoc ret = call.invoke(soapInParams);
116             
117             //printing output params
118
java.util.Map JavaDoc 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 JavaDoc s = outParams.get(new QName JavaDoc("echoVal"));
133             assertNotNull("echoVal paramter is null", s);
134             assertEquals("echoVal parameter is incorrect", (Short JavaDoc)s, new Short JavaDoc((short) 5) );
135             Object JavaDoc sq = outParams.get(new QName JavaDoc("sqrtVal"));
136             assertNotNull("sqrtVal paramter is null", sq);
137             assertEquals("sqrtVal parameter is incorrect", ((Double JavaDoc)sq).doubleValue(), Math.sqrt(5), 0.001D );
138
139         } catch (Exception JavaDoc e) {
140             e.printStackTrace(System.out);
141             throw new junit.framework.AssertionFailedError("Exception caught: " + e);
142         }
143
144     }
145 }
146
Popular Tags