protected ParseRESTCommand commandFromJSON(JSONObject json) throws JSONException { ParseRESTCommand command = null; if (ParseRESTCommand.isValidCommandJSONObject(json)) { command = ParseRESTCommand.fromJSONObject(json); } else if (ParseRESTCommand.isValidOldFormatCommandJSONObject(json)) { // do nothing } else { throw new JSONException("Failed to load command from JSON."); } return command; }
public ParseRESTCommand getCommand() throws JSONException { JSONObject json = getJSONObject("command"); ParseRESTCommand command = null; if (ParseRESTCommand.isValidCommandJSONObject(json)) { command = ParseRESTCommand.fromJSONObject(json); } else if (ParseRESTCommand.isValidOldFormatCommandJSONObject(json)) { // do nothing } else { throw new JSONException("Failed to load command from JSON."); } return command; } }
@Test public void testFromJSONObject() throws Exception { // Make test command String httpPath = "www.parse.com"; JSONObject jsonParameters = new JSONObject() .put("count", 1) .put("limit", 1); String sessionToken = "sessionToken"; String localId = "localId"; String httpMethod = "POST"; JSONObject commandJSON = new JSONObject() .put("httpPath", httpPath) .put("parameters", jsonParameters) .put("httpMethod", httpMethod) .put("sessionToken", sessionToken) .put("localId", localId); ParseRESTCommand command = ParseRESTCommand.fromJSONObject(commandJSON); assertEquals(httpPath, command.httpPath); assertEquals(httpMethod, command.method.toString()); assertEquals(sessionToken, command.getSessionToken()); assertEquals(localId, command.getLocalId()); assertEquals(jsonParameters, command.jsonParameters, JSONCompareMode.NON_EXTENSIBLE); }