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));
proxy.touch();
}
}