use of org.infobip.mobile.messaging.api.messages.SyncMessagesBody in project mobile-messaging-sdk-android by infobip.
the class MobileApiMessagesTest method testThatNullBodyIsBeingSentInCaseOfEmptyMessageIDArrays.
@Test
public void testThatNullBodyIsBeingSentInCaseOfEmptyMessageIDArrays() {
String serverResponse = "{\n" + " \"payloads\": [\n" + " {\n" + " \"gcm.notification.messageId\": \"test-message-id\",\n" + " \"gcm.notification.title\": \"this is title\",\n" + " \"gcm.notification.body\": \"body\",\n" + " \"gcm.notification.sound\": \"true\",\n" + " \"gcm.notification.vibrate\": \"true\",\n" + " \"gcm.notification.silent\": \"true\",\n" + " \"gcm.notification.category\": \"UNKNOWN\"\n" + " }\n" + " ]\n" + "}";
debugServer.respondWith(NanoHTTPD.Response.Status.OK, serverResponse);
String[] mIDs = new String[0];
String[] drIDs = new String[0];
SyncMessagesBody syncMessagesBody = SyncMessagesBody.make(mIDs, drIDs);
SyncMessagesResponse syncMessagesResponse = mobileApiMessages.sync(syncMessagesBody);
// inspect http context
assertThat(debugServer.getUri()).isEqualTo("/mobile/5/messages/");
assertThat(debugServer.getRequestCount()).isEqualTo(1);
assertThat(debugServer.getRequestMethod()).isEqualTo(NanoHTTPD.Method.POST);
assertThat(debugServer.getQueryParametersCount()).isEqualTo(1);
assertThat(debugServer.getBody()).isEqualTo(null);
// inspect response
assertEquals(1, syncMessagesResponse.getPayloads().size());
MessageResponse messageResponse = syncMessagesResponse.getPayloads().get(0);
assertEquals("test-message-id", messageResponse.getMessageId());
assertEquals("this is title", messageResponse.getTitle());
assertEquals("body", messageResponse.getBody());
assertEquals("true", messageResponse.getSound());
assertEquals("true", messageResponse.getVibrate());
assertEquals("true", messageResponse.getSilent());
assertEquals("UNKNOWN", messageResponse.getCategory());
}
use of org.infobip.mobile.messaging.api.messages.SyncMessagesBody in project mobile-messaging-sdk-android by infobip.
the class MessagesSynchronizer method sync.
public void sync() {
if (!mobileMessagingCore.isPushRegistrationEnabled()) {
return;
}
final String[] unreportedMessageIds = mobileMessagingCore.getAndRemoveUnreportedMessageIds();
new MRetryableTask<Void, List<Message>>() {
@Override
public List<Message> run(Void[] objects) {
if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
MobileMessagingLogger.w("Can't sync messages without valid registration");
throw InternalSdkError.NO_VALID_REGISTRATION.getException();
}
String[] messageIds = mobileMessagingCore.getSyncMessagesIds();
SyncMessagesBody syncMessagesBody = SyncMessagesBody.make(messageIds, unreportedMessageIds);
MobileMessagingLogger.v("SYNC MESSAGES >>>", syncMessagesBody);
SyncMessagesResponse syncMessagesResponse = mobileApiMessages.sync(syncMessagesBody);
MobileMessagingLogger.v("SYNC MESSAGES <<<", syncMessagesResponse);
return MessagesMapper.mapResponseToMessages(syncMessagesResponse.getPayloads());
}
@Override
public void after(List<Message> messages) {
broadcaster.deliveryReported(unreportedMessageIds);
if (messages == null || messages.isEmpty()) {
return;
}
for (Message message : messages) {
mobileMessageHandler.handleMessage(message);
}
}
@Override
public void error(Throwable error) {
mobileMessagingCore.addUnreportedMessageIds(unreportedMessageIds);
mobileMessagingCore.setLastHttpException(error);
MobileMessagingLogger.e("MobileMessaging API returned error (synchronizing messages)! ", error);
stats.reportError(MobileMessagingStatsError.SYNC_MESSAGES_ERROR);
if (!(error instanceof InternalSdkError.InternalSdkException)) {
broadcaster.error(MobileMessagingError.createFrom(error));
}
}
}.retryWith(retryPolicy).execute(executor);
}
use of org.infobip.mobile.messaging.api.messages.SyncMessagesBody in project mobile-messaging-sdk-android by infobip.
the class MobileApiMessagesTest method sync_messages_success.
@Test
public void sync_messages_success() {
String serverResponse = "{\n" + " \"payloads\": [\n" + " {\n" + " \"gcm.notification.messageId\": \"test-message-id\",\n" + " \"gcm.notification.title\": \"this is title\",\n" + " \"gcm.notification.body\": \"body\",\n" + " \"gcm.notification.sound\": \"true\",\n" + " \"gcm.notification.vibrate\": \"true\",\n" + " \"gcm.notification.silent\": \"true\",\n" + " \"gcm.notification.category\": \"UNKNOWN\"\n" + " }\n" + " ]\n" + "}";
debugServer.respondWith(NanoHTTPD.Response.Status.OK, serverResponse);
String[] mIDs = new String[1];
mIDs[0] = "test-message-id";
String[] drIDs = new String[1];
drIDs[0] = "test-message-id";
SyncMessagesBody syncMessagesBody = SyncMessagesBody.make(mIDs, drIDs);
SyncMessagesResponse syncMessagesResponse = mobileApiMessages.sync(syncMessagesBody);
// inspect http context
assertThat(debugServer.getUri()).isEqualTo("/mobile/5/messages/");
assertThat(debugServer.getRequestCount()).isEqualTo(1);
assertThat(debugServer.getRequestMethod()).isEqualTo(NanoHTTPD.Method.POST);
assertThat(debugServer.getQueryParametersCount()).isEqualTo(1);
assertThat(debugServer.getBody()).isNotEqualTo(null);
// inspect response
assertEquals(1, syncMessagesResponse.getPayloads().size());
MessageResponse messageResponse = syncMessagesResponse.getPayloads().get(0);
assertEquals("test-message-id", messageResponse.getMessageId());
assertEquals("this is title", messageResponse.getTitle());
assertEquals("body", messageResponse.getBody());
assertEquals("true", messageResponse.getSound());
assertEquals("true", messageResponse.getVibrate());
assertEquals("true", messageResponse.getSilent());
assertEquals("UNKNOWN", messageResponse.getCategory());
}
Aggregations