@NonNull @Override public LogContainer deserializeContainer(@NonNull String json, String type) throws JSONException { JSONObject jContainer = new JSONObject(json); LogContainer container = new LogContainer(); JSONArray jLogs = jContainer.getJSONArray(LOGS); List<Log> logs = new ArrayList<>(); for (int i = 0; i < jLogs.length(); i++) { JSONObject jLog = jLogs.getJSONObject(i); Log log = readLog(jLog, type); logs.add(log); } container.setLogs(logs); return container; }
@NonNull public static LogContainer generateMockLogContainer() { LogContainer container = new LogContainer(); List<Log> logs = new ArrayList<>(); logs.add(generateMockLog()); container.setLogs(logs); return container; }
logContainer.setLogs(batch); groupState.mIngestion.sendAsync(mAppSecret, mInstallId, logContainer, new ServiceCallback() {
@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); }
log1.setSid(UUID.randomUUID()); container1.setLogs(Collections.singletonList(log1)); TestUtils.compareSelfNullClass(container1); TestUtils.checkNotEquals(container1, container2); container2.setLogs(Collections.singletonList(log1)); TestUtils.compareSelfNullClass(container1); TestUtils.checkEquals(container1, container2); log2.setSid(UUID.randomUUID()); container2.setLogs(Collections.singletonList(log2)); TestUtils.compareSelfNullClass(container1); TestUtils.checkNotEquals(container1, container2);
List<Log> logs = new ArrayList<>(); logs.add(log); container.setLogs(logs); LogSerializer serializer = mock(LogSerializer.class); JSONException exception = new JSONException("mock");
List<Log> logs = new ArrayList<>(); logs.add(log); container.setLogs(logs); LogSerializer serializer = mock(LogSerializer.class); when(serializer.serializeContainer(any(LogContainer.class))).thenReturn("mockPayload");
@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); } }
@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); } }
logs.add(startSessionLog); expectedContainer.setLogs(logs);