KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > junit > XmlRpcClientTest


1 package org.apache.ws.jaxme.js.junit;
2
3 import java.io.IOException JavaDoc;
4 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
5 import java.util.Vector JavaDoc;
6
7 import org.apache.ws.jaxme.js.apps.XmlRpcCaller;
8 import org.apache.ws.jaxme.js.junit.xmlrpcclient.Dispatcher;
9
10 import junit.framework.TestCase;
11
12
13 /** A unit test for the
14  * {@link org.apache.ws.jaxme.js.apps.XmlRpcClientGenerator}.
15  */

16 public class XmlRpcClientTest extends TestCase {
17     private final XmlRpcCaller caller = new XmlRpcCaller(){
18         Dispatcher dispatcher = new Dispatcher();
19         public Object JavaDoc xmlRpcCall(String JavaDoc pName, Vector JavaDoc pVector) {
20             try {
21                 return dispatcher.execute(pName, pVector);
22             } catch (RuntimeException JavaDoc e) {
23                 throw e;
24             } catch (Throwable JavaDoc t) {
25                 throw new UndeclaredThrowableException JavaDoc(t);
26             }
27         }
28     };
29     private final XmlRpcClientTestRemoteClass server = new XmlRpcClientTestRemoteClass();
30     private final org.apache.ws.jaxme.js.junit.xmlrpcclient.XmlRpcClientTestRemoteClass client
31         = new org.apache.ws.jaxme.js.junit.xmlrpcclient.XmlRpcClientTestRemoteClass(caller);
32
33     /** Creates a new instance with the given name.
34      */

35     public XmlRpcClientTest(String JavaDoc pArg0) {
36         super(pArg0);
37     }
38
39     private void checkSum(int pSum) {
40         assertEquals(pSum, server.getSum());
41         assertEquals(pSum, client.getSum());
42         String JavaDoc sumAsString = Integer.toString(pSum);
43         try {
44             assertEquals(sumAsString, server.getSumAsString());
45         } catch (IOException JavaDoc e) {
46             // This IOException is never actually thrown.
47
// However, the try .. catch clause ensures, that
48
// it is present in the signature of server.getSumAsString().
49
}
50         try {
51             assertEquals(sumAsString, client.getSumAsString());
52         } catch (IOException JavaDoc e) {
53             // This IOException is never actually thrown.
54
// However, the try .. catch clause ensures, that
55
// it is present in the signature of client.getSumAsString().
56
}
57     }
58
59     /** Creates a dispatcher and uses it to run the
60      * various methods.
61      */

62     public void testXmlRpcClient() {
63         checkSum(0);
64         server.add(1);
65         checkSum(1);
66         client.add(1);
67         checkSum(2);
68         server.add(new int[]{2,3,2});
69         checkSum(9);
70         client.add(new int[]{0,-1,0,2});
71         checkSum(10);
72         server.add("4");
73         checkSum(14);
74         client.add("-8");
75         checkSum(6);
76     }
77 }
78
Popular Tags