@Test public void testCallFunctionInBackgroundFailure() throws Exception { ParseRequest.setDefaultInitialRetryDelay(1L); ParseHttpClient restClient = mock(ParseHttpClient.class); when(restClient.execute(any(ParseHttpRequest.class))).thenThrow(new IOException()); ParseCloudCodeController controller = new ParseCloudCodeController(restClient); Task<String> cloudCodeTask = controller.callFunctionInBackground("test", new HashMap<String, Object>(), "sessionToken"); cloudCodeTask.waitForCompletion(); verify(restClient, times(5)).execute(any(ParseHttpRequest.class)); assertTrue(cloudCodeTask.isFaulted()); Exception error = cloudCodeTask.getError(); assertThat(error, instanceOf(ParseException.class)); assertEquals(ParseException.CONNECTION_FAILED, ((ParseException) error).getCode()); }
public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); }
ParseCloudCodeController { public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); } }
ParseCloudCodeController { public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); } ParseCloudCodeController(ParseHttpClient restClient); }
ParseCloudCodeController { public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); } ParseCloudCodeController(ParseHttpClient restClient); Task<T> callFunctionInBackground(final String name,
                                                final Map<String, ?> params, String sessionToken); }
ParseCloudCodeController { public <T> Task<T> callFunctionInBackground(final String name, final Map<String, ?> params, String sessionToken) { ParseRESTCommand command = ParseRESTCloudCommand.callFunctionCommand( name, params, sessionToken); return command.executeAsync(restClient).onSuccess(new Continuation<JSONObject, T>() { @Override public T then(Task<JSONObject> task) { @SuppressWarnings("unchecked") T result = (T) convertCloudResponse(task.getResult()); return result; } }); } ParseCloudCodeController(ParseHttpClient restClient); Task<T> callFunctionInBackground(final String name,
                                                final Map<String, ?> params, String sessionToken);  }