• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package autotest.moblab.rpc;
2 
3 import com.google.gwt.json.client.JSONObject;
4 import com.google.gwt.json.client.JSONValue;
5 
6 import autotest.moblab.MoblabTest;
7 import autotest.moblab.rpc.NetworkInfo;
8 
9 public class NetworkInfoTest extends MoblabTest {
testSerialization()10   public void testSerialization() {
11     // Test null
12     NetworkInfo info = new NetworkInfo(null, true);
13     JSONObject jsonInfo = info.toJson();
14     JSONValue ips = jsonInfo.get(NetworkInfo.JSON_FIELD_SERVER_IPS);
15     assertEquals(0, ips.isArray().size());
16     assertTrue(jsonInfo.get(NetworkInfo.JSON_FIELD_IS_CONNECTED).isBoolean()
17         .booleanValue());
18 
19     info = new NetworkInfo();
20     info.fromJson(jsonInfo);
21     assertEquals(0, info.getServerIps().length);
22     assertTrue(info.isConnectedToGoogle());
23 
24     // Test serialization
25     String[] serverIps = new String[] { "10.0.0.1", "10.0.0.2"};
26     info = new NetworkInfo(serverIps, true);
27     jsonInfo = info.toJson();
28     ips = jsonInfo.get(NetworkInfo.JSON_FIELD_SERVER_IPS);
29     assertEquals(2, ips.isArray().size());
30     assertEquals("10.0.0.1", ips.isArray().get(0).isString().stringValue());
31     assertEquals("10.0.0.2", ips.isArray().get(1).isString().stringValue());
32     assertTrue(jsonInfo.get(NetworkInfo.JSON_FIELD_IS_CONNECTED).isBoolean()
33         .booleanValue());
34 
35     // Test de-serialization.
36     info = new NetworkInfo();
37     info.fromJson(jsonInfo);
38     assertEquals(2, info.getServerIps().length);
39     assertEquals("10.0.0.1", info.getServerIps()[0]);
40     assertEquals("10.0.0.2", info.getServerIps()[1]);
41     assertTrue(info.isConnectedToGoogle());
42   }
43 }
44