@Test public void emptyLogs() throws JSONException { LogContainer expectedContainer = new LogContainer(); expectedContainer.setLogs(Collections.<Log>emptyList()); LogSerializer serializer = new DefaultLogSerializer(); String payload = serializer.serializeContainer(expectedContainer); android.util.Log.v(TAG, payload); LogContainer actualContainer = serializer.deserializeContainer(payload, null); assertEquals(expectedContainer, actualContainer); }
@Test public void oneLog() throws JSONException { LogContainer expectedContainer = AndroidTestUtils.generateMockLogContainer(); LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory()); String payload = serializer.serializeContainer(expectedContainer); android.util.Log.v(TAG, payload); LogContainer actualContainer = serializer.deserializeContainer(payload, null); assertEquals(expectedContainer, actualContainer); assertEquals(expectedContainer.hashCode(), actualContainer.hashCode()); }
@Test public void serialize() throws JSONException { LogContainer expectedContainer = new LogContainer(); List<Log> logs = new ArrayList<>(); { PushInstallationLog log = new PushInstallationLog(); log.setTimestamp(new Date()); log.setPushToken("TEST"); logs.add(log); } expectedContainer.setLogs(logs); UUID sid = UUIDUtils.randomUUID(); for (Log log : logs) { log.setSid(sid); } LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(PushInstallationLog.TYPE, new PushInstallationLogFactory()); String payload = serializer.serializeContainer(expectedContainer); LogContainer actualContainer = serializer.deserializeContainer(payload, null); Assert.assertEquals(expectedContainer, actualContainer); } }
@Test public void serialize() throws JSONException { LogContainer expectedContainer = new LogContainer(); List<Log> logs = new ArrayList<>(); { DistributionStartSessionLog log = new DistributionStartSessionLog(); log.setTimestamp(new Date()); logs.add(log); } expectedContainer.setLogs(logs); UUID sid = UUIDUtils.randomUUID(); for (Log log : logs) { log.setSid(sid); } /* Serialize and deserialize logs container. */ LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(DistributionStartSessionLog.TYPE, new DistributionStartSessionLogFactory()); String payload = serializer.serializeContainer(expectedContainer); LogContainer actualContainer = serializer.deserializeContainer(payload, null); /* Verify that logs container successfully deserialized. */ Assert.assertEquals(expectedContainer, actualContainer); } }
String payload = serializer.serializeContainer(expectedContainer); android.util.Log.v(TAG, payload); LogContainer actualContainer = serializer.deserializeContainer(payload, null); Assert.assertEquals(expectedContainer, actualContainer);