KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > rpcParams > RpcParamsServiceTestCase


1 /**
2  * RpcParamsServiceTestCase.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis WSDL2Java emitter.
6  */

7
8 package test.wsdl.rpcParams;
9
10 import javax.xml.rpc.ServiceException JavaDoc;
11
12 import junit.framework.TestCase;
13
14 public class RpcParamsServiceTestCase extends TestCase {
15     public RpcParamsServiceTestCase(String JavaDoc name) {
16         super(name);
17     }
18
19     public void testRpcParamsWSDL() throws Exception JavaDoc {
20         javax.xml.rpc.ServiceFactory JavaDoc serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
21         java.net.URL JavaDoc url = new java.net.URL JavaDoc(new test.wsdl.rpcParams.RpcParamsServiceLocator().getRpcParamsAddress() + "?WSDL");
22         javax.xml.rpc.Service JavaDoc service = serviceFactory.createService(url, new test.wsdl.rpcParams.RpcParamsServiceLocator().getServiceName());
23         assertTrue(service != null);
24     }
25
26     /**
27      * Send parameters in the order that they are specified in
28      * the wsdl. Also omits null parameters.
29      */

30     public void testEcho() throws Exception JavaDoc {
31         RpcParamsBindingStub binding = getBinding();
32
33         EchoStruct result;
34         // test sending both
35
result = binding.echo("first", "second");
36         assertNotNull("returned struct is null", result);
37         assertEquals("first parameter marshalled wrong when both sent", "first", result.getFirst());
38         assertEquals("second parameter marshalled wrong when both sent", "second", result.getSecond());
39
40         // test ommitting the first, since it's null
41
result = binding.echo(null, "second");
42         assertNotNull("returned struct is null", result);
43         assertNull("first parameter should be null", result.getFirst());
44         assertEquals("second parameter marshalled wrong first is null", "second", result.getSecond());
45
46         // test ommitting the second, since it's null
47
result = binding.echo("first", null);
48         assertNotNull("returned struct is null", result);
49         assertEquals("first parameter marshalled wrong when second is null", "first", result.getFirst());
50         assertNull("second parameter should be null", result.getSecond());
51
52         // test ommitting both, since they're null
53
result = binding.echo(null, null);
54         assertNotNull("returned struct is null", result);
55         assertNull("first parameter should be null", result.getFirst());
56         assertNull("second parameter should be null", result.getSecond());
57     }
58
59     /**
60      * Send parameters in the reverse order that they are specified in
61      * the wsdl. Also omits null parameters.
62      */

63     public void testEchoReverse() throws Exception JavaDoc {
64         RpcParamsBindingStub binding = getBinding();
65
66         EchoStruct result;
67         // test sending both
68
result = binding.echoReverse("first", "second");
69         assertNotNull("returned struct is null", result);
70         assertEquals("first parameter marshalled wrong when both sent", "first", result.getFirst());
71         assertEquals("second parameter marshalled wrong when both sent", "second", result.getSecond());
72
73         // test ommitting the first, since it's null
74
result = binding.echoReverse(null, "second");
75         assertNotNull("returned struct is null", result);
76         assertNull("first parameter should be null", result.getFirst());
77         assertEquals("second parameter marshalled wrong first is null", "second", result.getSecond());
78
79         // test ommitting the second, since it's null
80
result = binding.echoReverse("first", null);
81         assertNotNull("returned struct is null", result);
82         assertEquals("first parameter marshalled wrong when second is null", "first", result.getFirst());
83         assertNull("second parameter should be null", result.getSecond());
84
85         // test ommitting both, since they're null
86
result = binding.echoReverse(null, null);
87         assertNotNull("returned struct is null", result);
88         assertNull("first parameter should be null", result.getFirst());
89         assertNull("second parameter should be null", result.getSecond());
90     }
91
92     private RpcParamsBindingStub getBinding() {
93         RpcParamsBindingStub binding = null;
94         try {
95             binding = (RpcParamsBindingStub) new RpcParamsServiceLocator().getRpcParams();
96         }
97         catch (ServiceException JavaDoc jre) {
98             if(jre.getLinkedCause()!=null)
99                 jre.getLinkedCause().printStackTrace();
100             fail("JAX-RPC ServiceException caught: " + jre);
101         }
102         assertNotNull("binding is null", binding);
103
104         // Time out after a minute
105
binding.setTimeout(60000);
106         return binding;
107     }
108 }
109
Popular Tags