/** * Sends this push notification in a background thread. This is preferable to using * <code>send()</code>, unless your code is already running from a background thread. * * @param callback callback.done(e) is called when the send completes. */ public void sendInBackground(SendCallback callback) { ParseTaskUtils.callbackOnMainThreadAsync(sendInBackground(), callback); }
/** * Sends this push notification while blocking this thread until the push notification has * successfully reached the Parse servers. Typically, you should use {@link #sendInBackground()} * instead of this, unless you are managing your own threading. * * @throws ParseException Throws an exception if the server is inaccessible. */ public void send() throws ParseException { ParseTaskUtils.wait(sendInBackground()); }
/** * A helper method to concisely send a push message to a query. This method is equivalent to * ParsePush push = new ParsePush(); push.setMessage(message); push.setQuery(query); * push.sendInBackground(); * * @param message The message that will be shown in the notification. * @param query A ParseInstallation query which specifies the recipients of a push. * @return A task that is resolved when the message is sent. */ public static Task<Void> sendMessageInBackground(String message, ParseQuery<ParseInstallation> query) { ParsePush push = new ParsePush(); push.setQuery(query); push.setMessage(message); return push.sendInBackground(); }
/** * 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(); * * @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. * @return A task that is resolved when the data is sent. */ public static Task<Void> sendDataInBackground(JSONObject data, ParseQuery<ParseInstallation> query) { ParsePush push = new ParsePush(); push.setQuery(query); push.setData(data); return push.sendInBackground(); }
@Test public void testSendInBackgroundSuccess() 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 ParsePush push = new ParsePush(); JSONObject data = new JSONObject(); data.put("key", "value"); List<String> channels = new ArrayList<>(); channels.add("test"); channels.add("testAgain"); push.builder.expirationTime((long) 1000) .data(data) .channelSet(channels); ParseTaskUtils.wait(push.sendInBackground()); // 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(); assertEquals(data, state.data(), JSONCompareMode.NON_EXTENSIBLE); assertEquals(2, state.channelSet().size()); assertTrue(state.channelSet().contains("test")); assertTrue(state.channelSet().contains("testAgain")); }
final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); push.sendInBackground(new SendCallback() { @Override public void done(ParseException e) {
final Semaphore done = new Semaphore(0); final Capture<Exception> exceptionCapture = new Capture<>(); push.sendInBackground(new SendCallback() { @Override public void done(ParseException e) {
.data(data) .channelSet(channels); Task<Void> pushTask = push.sendInBackground(); pushTask.waitForCompletion();
@NonNull public static Completable send(@NonNull final ParsePush push) { return RxTask.completable(() -> push.sendInBackground()); }
@Test public void testParseObservableSend() { rx.parse2.ParseObservable.send(mocker(ParsePush.class) .when(it -> it.sendInBackground()) .thenReturn(it -> Task.<Void>forResult(null)) .mock()) .test() .assertNoErrors() .assertComplete(); }