/** * A helper method to concisely send a push to a query. This method is equivalent to ParsePush * push = new ParsePush(); push.setData(data); push.setQuery(query); * push.sendInBackground(callback); * * @param data The entire data of the push message. See the push guide for more details on the data * format. * @param query A ParseInstallation query which specifies the recipients of a push. * @param callback callback.done(e) is called when the send completes. */ public static void sendDataInBackground(JSONObject data, ParseQuery<ParseInstallation> query, SendCallback callback) { ParseTaskUtils.callbackOnMainThreadAsync(sendDataInBackground(data, query), callback); }
@Test public void testSendDataInBackground() throws Exception { // Mock controller ParsePushController controller = mock(ParsePushController.class); when(controller.sendInBackground(any(ParsePush.State.class), anyString())) .thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerPushController(controller); // Make sample ParsePush data and call method JSONObject data = new JSONObject(); data.put("key", "value"); data.put("keyAgain", "valueAgain"); ParseQuery<ParseInstallation> query = ParseInstallation.getQuery(); query.getBuilder() .whereEqualTo("foo", "bar"); ParsePush.sendDataInBackground(data, query); // Make sure controller is executed and state parameter is correct ArgumentCaptor<ParsePush.State> stateCaptor = ArgumentCaptor.forClass(ParsePush.State.class); verify(controller, times(1)).sendInBackground(stateCaptor.capture(), anyString()); ParsePush.State state = stateCaptor.getValue(); // Verify query state ParseQuery.State<ParseInstallation> queryState = state.queryState(); JSONObject queryStateJson = queryState.toJSON(PointerEncoder.get()); assertEquals("bar", queryStateJson.getJSONObject("where").getString("foo")); // Verify data assertEquals(data, state.data(), JSONCompareMode.NON_EXTENSIBLE); }
final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); ParsePush.sendDataInBackground(data, query, new SendCallback() { @Override public void done(ParseException e) {
@NonNull public static Completable send(@NonNull final JSONObject data, @NonNull final ParseQuery<ParseInstallation> query) { return RxTask.completable(() -> ParsePush.sendDataInBackground(data, query)); }