/** Tests a valid JSON construction of this RPC message. */
  public void testJsonConstructor() {
    JSONObject commandJson =
        JsonFileReader.readId(this.mContext, getCommandType(), getMessageType());
    assertNotNull(Test.NOT_NULL, commandJson);

    try {
      Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson);
      SetMediaClockTimerResponse cmd = new SetMediaClockTimerResponse(hash);

      JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType());
      assertNotNull(Test.NOT_NULL, body);

      // Test everything in the json body.
      assertEquals(
          Test.MATCH,
          JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME),
          cmd.getFunctionName());
      assertEquals(
          Test.MATCH,
          JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID),
          cmd.getCorrelationID());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  /** Tests a valid JSON construction of this RPC message. */
  public void testJsonConstructor() {
    JSONObject commandJson =
        JsonFileReader.readId(this.mContext, getCommandType(), getMessageType());
    assertNotNull(Test.NOT_NULL, commandJson);

    try {
      Hashtable<String, Object> hash = JsonRPCMarshaller.deserializeJSONObject(commandJson);
      DiagnosticMessage cmd = new DiagnosticMessage(hash);

      JSONObject body = JsonUtils.readJsonObjectFromJsonObject(commandJson, getMessageType());
      assertNotNull(Test.NOT_NULL, body);

      // Test everything in the json body.
      assertEquals(
          Test.MATCH,
          JsonUtils.readStringFromJsonObject(body, RPCMessage.KEY_FUNCTION_NAME),
          cmd.getFunctionName());
      assertEquals(
          Test.MATCH,
          JsonUtils.readIntegerFromJsonObject(body, RPCMessage.KEY_CORRELATION_ID),
          cmd.getCorrelationID());

      JSONObject parameters =
          JsonUtils.readJsonObjectFromJsonObject(body, RPCMessage.KEY_PARAMETERS);
      assertEquals(
          Test.MATCH,
          JsonUtils.readIntegerFromJsonObject(parameters, DiagnosticMessage.KEY_TARGET_ID),
          cmd.getTargetID());
      assertEquals(
          Test.MATCH,
          JsonUtils.readIntegerFromJsonObject(parameters, DiagnosticMessage.KEY_MESSAGE_LENGTH),
          cmd.getMessageLength());

      List<Integer> messageDataList =
          JsonUtils.readIntegerListFromJsonObject(parameters, DiagnosticMessage.KEY_MESSAGE_DATA);
      List<Integer> testDataList = cmd.getMessageData();
      assertEquals(Test.MATCH, messageDataList.size(), testDataList.size());
      assertTrue(Test.TRUE, Validator.validateIntegerList(messageDataList, testDataList));
    } catch (JSONException e) {
      fail(Test.JSON_FAIL);
    }
  }