KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > echo2 > Echo2ServiceTestCase


1 /**
2  * Echo2ServiceTestCase.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis 1.2RC3 Mar 22, 2005 (05:08:41 CET) WSDL2Java emitter.
6  */

7 package test.wsdl.echo2;
8
9 import java.util.Iterator JavaDoc;
10 import javax.xml.namespace.QName JavaDoc;
11 import org.apache.axis.MessageContext;
12 import org.apache.axis.message.MessageElement;
13 import org.apache.axis.message.PrefixedQName;
14 import org.apache.axis.message.SOAPBody;
15
16 public class Echo2ServiceTestCase extends junit.framework.TestCase {
17     public Echo2ServiceTestCase(java.lang.String JavaDoc name) {
18         super(name);
19     }
20
21     public void testEcho2WSDL() throws Exception JavaDoc {
22         javax.xml.rpc.ServiceFactory JavaDoc serviceFactory = javax.xml.rpc.ServiceFactory
23                 .newInstance();
24         java.net.URL JavaDoc url = new java.net.URL JavaDoc(
25                 new test.wsdl.echo2.Echo2ServiceLocator().getEcho2Address()
26                         + "?WSDL");
27         javax.xml.rpc.Service JavaDoc service = serviceFactory.createService(url,
28                 new test.wsdl.echo2.Echo2ServiceLocator().getServiceName());
29         assertTrue(service != null);
30     }
31
32     public void test1Echo2EchoMyBase64Bean() throws Exception JavaDoc {
33         test.wsdl.echo2.Echo2SoapBindingStub binding;
34         binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
35                 .getEcho2();
36         assertNotNull("binding is null", binding);
37         // Time out after a minute
38
binding.setTimeout(60000);
39
40         // message is more clear without multiref
41
//binding._setProperty("sendMultiRefs", Boolean.FALSE);
42
// Test operation
43
test.wsdl.echo2.MyBase64Bean input = new test.wsdl.echo2.MyBase64Bean();
44         fillMyBase64Bean(input);
45         test.wsdl.echo2.MyBase64Bean ret = binding.echoMyBase64Bean(input);
46
47         // Body
48
// echoMyBase64BeanResponse
49
// return HREF
50
// multiRef : 1 element, no child
51

52         // Check message format
53
binding._getCall().getResponseMessage().writeTo(System.out);
54         SOAPBody body = (SOAPBody) binding._getCall().getResponseMessage().getSOAPBody();
55
56         QName JavaDoc responseQName = new QName JavaDoc("urn:echo2.wsdl.test", "echoMyBase64BeanResponse");
57         QName JavaDoc returnQName = new QName JavaDoc("", "return");
58         QName JavaDoc xsdByteQName = new QName JavaDoc("", "varXsdByte");
59         QName JavaDoc soapByteQName = new QName JavaDoc("", "varSoapByte");
60         QName JavaDoc xsdBase64BinQName = new QName JavaDoc("", "varXsdBase64Binary");
61         QName JavaDoc soapBase64BinQName = new QName JavaDoc("", "varSoapBase64Binary");
62         QName JavaDoc xsdHexBinQName = new QName JavaDoc("", "varXsdHexBinary");
63         QName JavaDoc soapBase64QName = new QName JavaDoc("", "varSoapBase64");
64
65         MessageElement response = body.getChildElement(responseQName);
66         assertNotNull("no <ns1:echoMyBase64BeanResponse> found", response);
67         MessageElement return1 = response.getChildElement(returnQName);
68         assertNotNull("no <return> found", return1);
69         MessageElement realRet = return1.getRealElement();
70
71         Iterator JavaDoc it = realRet.getChildElements(xsdByteQName);
72         // only 1 element
73
MessageElement one = null;
74         while (it.hasNext()) {
75             assertNull("only 1 element named " + xsdByteQName, one);
76             one = (MessageElement) it.next();
77         }
78         assertNull(xsdByteQName + " is nil and shouldn't have any children", one.getChildren());
79
80         it = realRet.getChildElements(soapByteQName);
81         // only 1 element
82
one = null;
83         while (it.hasNext()) {
84             assertNull("only 1 element named " + soapByteQName, one);
85             one = (MessageElement) it.next();
86         }
87         assertNull(soapByteQName + " is nil and shouldn't have any children", one.getChildren());
88
89         it = realRet.getChildElements(xsdBase64BinQName);
90         // only 1 element
91
one = null;
92         while (it.hasNext()) {
93             assertNull("only 1 element named " + xsdBase64BinQName, one);
94             one = (MessageElement) it.next();
95         }
96         assertEquals(xsdBase64BinQName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());
97
98         it = realRet.getChildElements(soapBase64BinQName);
99         // only 1 element
100
one = null;
101         while (it.hasNext()) {
102             assertNull("only 1 element named " + soapBase64BinQName, one);
103             one = (MessageElement) it.next();
104         }
105         assertEquals(soapBase64BinQName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());
106
107         it = realRet.getChildElements(xsdHexBinQName);
108         // only 1 element
109
one = null;
110         while (it.hasNext()) {
111             assertNull("only 1 element named " + xsdHexBinQName, one);
112             one = (MessageElement) it.next();
113         }
114         assertEquals(xsdHexBinQName + " have wrong value", "7f0081", one.getFirstChild().getNodeValue());
115
116         it = realRet.getChildElements(soapBase64QName);
117         // only 1 element
118
one = null;
119         while (it.hasNext()) {
120             assertNull("only 1 element named " + soapBase64QName, one);
121             one = (MessageElement) it.next();
122         }
123         assertEquals(soapBase64QName + " have wrong value", "fwCB", one.getFirstChild().getNodeValue());
124
125     }
126
127     public void test1Echo2EchoArrayOfMyBase64Bean() throws Exception JavaDoc {
128         test.wsdl.echo2.Echo2SoapBindingStub binding;
129         binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
130                 .getEcho2();
131         assertNotNull("binding is null", binding);
132         // Time out after a minute
133
binding.setTimeout(60000);
134         // Test operation
135
MyBase64Bean[] value = null;
136         MyBase64Bean[] array = new MyBase64Bean[2];
137         array[0] = new MyBase64Bean();
138         fillMyBase64Bean(array[0]);
139         array[1] = new MyBase64Bean();
140         fillMyBase64Bean(array[1]);
141         value = binding.echoArrayOfMyBase64Bean(array);
142         // TBD - validate results
143
}
144
145     /**
146      * @param bean
147      */

148     private void fillMyBase64Bean(MyBase64Bean bean) {
149         bean.setVarSoapBase64(new byte[] {127, 0, -127});
150         bean.setVarSoapBase64Binary(new byte[] {127, 0, -127});
151         bean.setVarXsdBase64Binary(new byte[] {127, 0, -127});
152         bean.setVarXsdHexBinary(new byte[] {127, 0, -127});
153
154     }
155
156     public void test2Echo2EchoArrayOfString_MaxOccursUnbounded()
157             throws Exception JavaDoc {
158         test.wsdl.echo2.Echo2SoapBindingStub binding;
159         Echo2ServiceLocator loc = new test.wsdl.echo2.Echo2ServiceLocator();
160         try {
161             binding = (test.wsdl.echo2.Echo2SoapBindingStub)loc.getEcho2();
162         } catch (javax.xml.rpc.ServiceException JavaDoc jre) {
163             if (jre.getLinkedCause() != null)
164                 jre.getLinkedCause().printStackTrace();
165             throw new junit.framework.AssertionFailedError(
166                     "JAX-RPC ServiceException caught: " + jre);
167         }
168         assertNotNull("binding is null", binding);
169         // Time out after a minute
170
binding.setTimeout(60000);
171         // Test operation
172
String JavaDoc [] args = new String JavaDoc[] {"one", "two", "", null};
173         java.lang.String JavaDoc[] value = null;
174         value = binding
175                 .echoArrayOfString_MaxOccursUnbounded(args);
176
177         // Validate results - NOTE: This checks the XML directly, so if
178
// any changes are made to the WSDL/code for this test, equivalent
179
// changes must be made in this code.
180

181         SOAPBody body = (SOAPBody)binding._getCall().getResponseMessage().getSOAPBody();
182         MessageElement element;
183         QName JavaDoc responseQName = new QName JavaDoc("urn:echo2.wsdl.test", "echoArrayOfString_MaxOccursUnboundedResponse");
184         QName JavaDoc returnQName = new QName JavaDoc("", "return");
185         QName JavaDoc itemQName = new QName JavaDoc("", "varStringArray");
186         element = body.getChildElement(responseQName);
187         assertNotNull("Couldn't find response element", element);
188         element = element.getChildElement(returnQName);
189         assertNotNull("Couldn't find return element", element);
190         Iterator JavaDoc elements = element.getChildElements(itemQName);
191         assertNotNull("Couldn't find items", elements);
192         int count = 0;
193         while (elements.hasNext()) {
194             element = (MessageElement) elements.next();
195             count++;
196         }
197         assertEquals("Wrong # of items", 4, count);
198
199         // OK, now that we know the XML looked right, just for yuks check the values
200
for (int i = 0; i < value.length; i++) {
201             assertEquals("Item " + i + " didn't match!", args[i], value[i]);
202         }
203     }
204
205     public void test3Echo2EchoArrayOfString_SoapEncArray() throws Exception JavaDoc {
206         test.wsdl.echo2.Echo2SoapBindingStub binding;
207         try {
208             binding = (test.wsdl.echo2.Echo2SoapBindingStub) new test.wsdl.echo2.Echo2ServiceLocator()
209                     .getEcho2();
210         } catch (javax.xml.rpc.ServiceException JavaDoc jre) {
211             if (jre.getLinkedCause() != null)
212                 jre.getLinkedCause().printStackTrace();
213             throw new junit.framework.AssertionFailedError(
214                     "JAX-RPC ServiceException caught: " + jre);
215         }
216         assertNotNull("binding is null", binding);
217         // Time out after a minute
218
binding.setTimeout(60000);
219         // Test operation
220
java.lang.String JavaDoc[] value = null;
221         value = binding.echoArrayOfString_SoapEncArray(new java.lang.String JavaDoc[] {
222                 "one", "two", "three", "", null });
223         // TBD - validate results
224
}
225     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
226         Echo2ServiceTestCase tc = new Echo2ServiceTestCase("somehging;");
227         tc.test1Echo2EchoMyBase64Bean();
228     }
229 }
230
Popular Tags