@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); }
@Override public Task<JSONObject> then(Task<JSONObject> task) { String localId = command.getLocalId(); Exception error = task.getError(); if (error != null) { if (error instanceof ParseException && ((ParseException) error).getCode() == ParseException.CONNECTION_FAILED) { // do nothing } else { if (tcs != null) { tcs.setError(error); } } return task; } JSONObject json = task.getResult(); if (tcs != null) { tcs.setResult(json); } else if (localId != null) { // If this command created a new objectId, add it to the map. String objectId = json.optString("objectId", null); if (objectId != null) { ParseCorePlugins.getInstance() .getLocalIdManager().setObjectId(localId, objectId); } } return task; } });
assertEquals("objectIdAgain", jsonParameters.getString("objectId")); assertNull(command.getLocalId());