@Override public String buildRequestBody() throws JSONException { /* Serialize payload. */ return mLogSerializer.serializeContainer(mLogContainer); }
@Override public Log create() { return new MockLog(); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, WRAPPER_SDK_VERSION, getWrapperSdkVersion()); JSONUtils.write(writer, WRAPPER_SDK_NAME, getWrapperSdkName()); JSONUtils.write(writer, WRAPPER_RUNTIME_VERSION, getWrapperRuntimeVersion()); JSONUtils.write(writer, LIVE_UPDATE_RELEASE_LABEL, getLiveUpdateReleaseLabel()); JSONUtils.write(writer, LIVE_UPDATE_DEPLOYMENT_KEY, getLiveUpdateDeploymentKey()); JSONUtils.write(writer, LIVE_UPDATE_PACKAGE_HASH, getLiveUpdatePackageHash()); }
@Test(expected = JSONException.class) public void deserializeWithInvalidType() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory()); serializer.deserializeLog("{" + "\"type\": \"customProperties\"," + "\"timestamp\": \"2017-07-08T00:32:58.123Z\"," + "\"properties\":[{\"name\":\"test\",\"type\":\"unknown\",\"value\":42}]" + "}", null); }
@Test public void logWithUserId() throws JSONException { MockLog expectedLog = AndroidTestUtils.generateMockLog(); expectedLog.setTimestamp(new Date()); expectedLog.setUserId("charlie"); /* Verify serialize and deserialize. */ LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory()); String payload = serializer.serializeLog(expectedLog); Log actualLog = serializer.deserializeLog(payload, null); assertEquals(expectedLog, actualLog); assertEquals("charlie", actualLog.getUserId()); }
@Test(expected = JSONException.class) public void deserializeUnknownType() throws JSONException { MockLog log = AndroidTestUtils.generateMockLog(); LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(MOCK_LOG_TYPE, new MockLogFactory()); String payload = serializer.serializeLog(log); android.util.Log.v(TAG, payload); new DefaultLogSerializer().deserializeLog(payload, null); }
@Test public void toCommonSchemaLog() { LogFactory logFactory = mock(LogFactory.class); MockLog log = AndroidTestUtils.generateMockLog(); LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(MOCK_LOG_TYPE, logFactory); serializer.toCommonSchemaLog(log); verify(logFactory).toCommonSchemaLogs(log); } }
@Test(expected = JSONException.class) public void serializeWithoutProperties() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); CustomPropertiesLog invalidTypeLog = new CustomPropertiesLog(); invalidTypeLog.setTimestamp(new Date()); serializer.serializeLog(invalidTypeLog); }
private void checkSerialization(LogSerializer serializer, MockCommonSchemaLog log) throws JSONException { Log copy = serializer.deserializeLog(serializer.serializeLog(log), MockCommonSchemaLog.TYPE); assertEquals(log, copy); } }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, TYPE, getType()); JSONUtils.write(writer, MESSAGE, getMessage()); JSONUtils.write(writer, STACK_TRACE, getStackTrace()); JSONUtils.writeArray(writer, FRAMES, getFrames()); JSONUtils.writeArray(writer, INNER_EXCEPTIONS, getInnerExceptions()); JSONUtils.write(writer, WRAPPER_SDK_NAME, getWrapperSdkName()); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.writeStringArray(writer, TICKET_KEYS, getTicketKeys()); JSONUtils.write(writer, DEV_MAKE, getDevMake()); JSONUtils.write(writer, DEV_MODEL, getDevModel()); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test(expected = JSONException.class) public void formatNullDate() throws JSONException { JSONDateUtils.toString(null); }
@Test(expected = JSONException.class) public void deserializeWithInvalidNumber() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory()); serializer.deserializeLog("{" + "\"type\": \"customProperties\"," + "\"timestamp\": \"2017-07-08T00:32:58.123Z\"," + "\"properties\":[{\"name\":\"test\",\"type\":\"number\",\"value\":false}]" + "}", null); }
@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, ID, getId()); JSONUtils.write(writer, NAME, getName()); JSONUtils.writeArray(writer, FRAMES, getFrames()); }
@Test(expected = JSONException.class) public void deserializeWithoutProperties() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory()); serializer.deserializeLog("{" + "\"type\": \"customProperties\"," + "\"timestamp\": \"2017-07-08T00:32:58.123Z\"" + "}", null); }
@Test(expected = JSONException.class) public void deserializeWithInvalidDate() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory()); serializer.deserializeLog("{" + "\"type\": \"customProperties\"," + "\"timestamp\": \"2017-07-08T00:32:58.123Z\"," + "\"properties\":[{\"name\":\"test\",\"type\":\"dateTime\",\"value\":\"today\"}]" + "}", null); }