Menu

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

Download this file

67 lines (46 with data), 1.4 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
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;
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(WebService.class, 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));
}
}