use of org.infobip.mobile.messaging.api.messages.SyncMessagesResponse 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.SyncMessagesResponse in project mobile-messaging-sdk-android by infobip.
the class PushUnregisteredTest method verifyMessagesSynchronizer.
private void verifyMessagesSynchronizer(VerificationMode verificationMode) throws InterruptedException {
mobileMessagingCore.addSyncMessagesIds("test-message-id");
given(mobileApiMessages.sync(any(SyncMessagesBody.class))).willReturn(new SyncMessagesResponse(new ArrayList<MessageResponse>() {
{
add(new MessageResponse("test-message-id", "this is title", "body", "sound", "true", "false", "UNKNOWN", "{}", "{}"));
}
}));
messagesSynchronizer.sync();
verify(mobileApiMessages, verificationMode).sync(any(SyncMessagesBody.class));
}
use of org.infobip.mobile.messaging.api.messages.SyncMessagesResponse 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.SyncMessagesResponse in project mobile-messaging-sdk-android by infobip.
the class MessagesSynchronizerTest method should_not_report_dlr_with_duplicate_messageIds.
@Test
public void should_not_report_dlr_with_duplicate_messageIds() {
// Given
mobileMessagingCore.getAndRemoveUnreportedMessageIds();
given(mobileApiMessages.sync(syncBodyCaptor.capture())).willReturn(new SyncMessagesResponse());
// When
mobileMessagingCore.setMessagesDelivered("1");
mobileMessagingCore.setMessagesDelivered("2");
mobileMessagingCore.setMessagesDelivered("3");
mobileMessagingCore.setMessagesDelivered("4");
mobileMessagingCore.setMessagesDelivered("5");
// Then
verify(mobileApiMessages, after(500).atMost(5)).sync(any(SyncMessagesBody.class));
assertEquals(5, syncBodyCaptor.getAllValues().size());
List<String> reportedDlrs = getReportedDLRs(syncBodyCaptor.getAllValues());
assertEquals(5, reportedDlrs.size());
assertTrue(reportedDlrs.containsAll(asList("1", "2", "3", "4", "5")));
}
use of org.infobip.mobile.messaging.api.messages.SyncMessagesResponse in project mobile-messaging-sdk-android by infobip.
the class MessagesSynchronizerTest method should_deserialize_messages_with_appropriate_vibration_from_fetched_payload.
@Test
public void should_deserialize_messages_with_appropriate_vibration_from_fetched_payload() {
// Given
mobileMessagingCore.getAndRemoveUnreportedMessageIds();
given(mobileApiMessages.sync(any(SyncMessagesBody.class))).willReturn(new SyncMessagesResponse(asList(new MessageResponse() {
{
setMessageId("someMessageId1");
setBody("someBody1");
}
}, new MessageResponse() {
{
setMessageId("someMessageId2");
setBody("someBody2");
setVibrate("true");
}
}, new MessageResponse() {
{
setMessageId("someMessageId3");
setBody("someBody3");
setVibrate("false");
}
})));
// When
messagesSynchronizer.sync();
// Then
verify(mobileMessageHandler, after(1000).times(3)).handleMessage(messageArgumentCaptor.capture());
List<Message> actualMessages = messageArgumentCaptor.getAllValues();
assertEquals("someMessageId1", actualMessages.get(0).getMessageId());
assertEquals("someBody1", actualMessages.get(0).getBody());
assertEquals(true, actualMessages.get(0).isVibrate());
assertEquals("someMessageId2", actualMessages.get(1).getMessageId());
assertEquals("someBody2", actualMessages.get(1).getBody());
assertEquals(true, actualMessages.get(1).isVibrate());
assertEquals("someMessageId3", actualMessages.get(2).getMessageId());
assertEquals("someBody3", actualMessages.get(2).getBody());
assertEquals(false, actualMessages.get(2).isVibrate());
}
Aggregations