Menu

[r16]: / trunk / test / cz / eman / jsonrpc / UDPClientServerTest.java  Maximize  Restore  History

Download this file

58 lines (43 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
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();
}
}