package cz.eman.jsonrpc;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import junit.framework.TestCase;
import org.junit.Before;
import cz.eman.jsonrpc.client.example.WebServiceClientProxy;
import cz.eman.jsonrpc.client.udp.UdpJsonClient;
import cz.eman.jsonrpc.server.example.WebService;
import cz.eman.jsonrpc.server.udp.UdpJsonServer;
public class UDPClientServerTest extends TestCase {
public static final int PORT = 12345;
private static WebService ws = new WebService();
@Before
@Override
protected void setUp() throws Exception {
super.setUp();
new Thread(new Runnable() {
@Override
public void run() {
try {
new UdpJsonServer(ws, InetAddress.getByName("255.255.255.255"), PORT).start();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}).start();
Thread.sleep(1000);
}
public void test1() throws Exception {
WebServiceClientProxy proxy;
UdpJsonClient client = new UdpJsonClient(new InetSocketAddress("255.255.255.255", PORT));
proxy = new WebServiceClientProxy(client);
assertEquals(Integer.valueOf(0), ws.getVariable());
proxy.setVariable(1);
Thread.sleep(1000);
assertEquals(Integer.valueOf(1), ws.getVariable());
proxy.add(1, 2);
proxy.add(null, null);
proxy.touchWithException();
}
}