Menu

[r6]: / trunk / test / cz / eman / jsonrpc / TCPClientServerTest.java  Maximize  Restore  History

Download this file

87 lines (64 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cz.eman.jsonrpc;
import java.io.IOException;
import java.net.Socket;
import junit.framework.TestCase;
import org.junit.Test;
import cz.eman.jsonrpc.client.TcpJsonClient;
import cz.eman.jsonrpc.client.example.WebServiceClientProxy;
import cz.eman.jsonrpc.server.example.B;
import cz.eman.jsonrpc.server.example.WebService;
import cz.eman.jsonrpc.server.tcp.TcpJsonMultiServer;
import cz.eman.jsonrpc.shared.exception.RpcErrorException;
public class TCPClientServerTest extends TestCase {
public static final int PORT = 33333;
@Override
protected void setUp() throws Exception {
super.setUp();
new Thread(new Runnable() {
@Override
public void run() {
try {
new TcpJsonMultiServer(new WebService(), PORT);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Thread.sleep(1000);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
@Test
public void testClient() throws IOException {
WebServiceClientProxy proxy;
proxy = new WebServiceClientProxy(new TcpJsonClient(new Socket("localhost", PORT)));
WebService service = new WebService();
assertEquals(Integer.valueOf(3), proxy.add(1, 2));
assertEquals(Integer.valueOf(3), service.add(1, 2));
assertEquals(proxy.add(1, 2), service.add(1, 2));
B b = new B();
b.setA("ASDF");
b.setB("FDSA");
assertEquals(b, service.echo(b));
assertEquals(b, proxy.echo(b));
proxy.touch();
try {
proxy.addWithException(1, 2);
fail("should not reach here!");
} catch (RpcErrorException e) {
// should happen
} catch (Throwable e) {
fail("shoudl not reach here!");
}
try {
proxy.touchWithException();
fail("should not reach here!");
} catch (RpcErrorException e) {
// should happen
} catch (Throwable e) {
fail("shoudl not reach here!");
}
}
}