Search in sources :

Example 1 with MessageResponse

use of org.infobip.mobile.messaging.api.messages.MessageResponse 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());
}
Also used : SyncMessagesResponse(org.infobip.mobile.messaging.api.messages.SyncMessagesResponse) MessageResponse(org.infobip.mobile.messaging.api.messages.MessageResponse) SyncMessagesBody(org.infobip.mobile.messaging.api.messages.SyncMessagesBody) Test(org.junit.Test)

Example 2 with MessageResponse

use of org.infobip.mobile.messaging.api.messages.MessageResponse 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));
}
Also used : SyncMessagesResponse(org.infobip.mobile.messaging.api.messages.SyncMessagesResponse) MessageResponse(org.infobip.mobile.messaging.api.messages.MessageResponse) SyncMessagesBody(org.infobip.mobile.messaging.api.messages.SyncMessagesBody) ArrayList(java.util.ArrayList)

Example 3 with MessageResponse

use of org.infobip.mobile.messaging.api.messages.MessageResponse in project mobile-messaging-sdk-android by infobip.

the class MessagesMapper method mapResponseToMessages.

static List<Message> mapResponseToMessages(List<MessageResponse> payloads) {
    if (payloads == null)
        return Collections.emptyList();
    List<Message> messages = new ArrayList<>(payloads.size());
    for (MessageResponse payload : payloads) {
        if (payload == null) {
            continue;
        }
        Message message = responseToMessage(payload);
        messages.add(message);
    }
    return messages;
}
Also used : Message(org.infobip.mobile.messaging.Message) MessageResponse(org.infobip.mobile.messaging.api.messages.MessageResponse) ArrayList(java.util.ArrayList)

Example 4 with MessageResponse

use of org.infobip.mobile.messaging.api.messages.MessageResponse 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());
}
Also used : SyncMessagesResponse(org.infobip.mobile.messaging.api.messages.SyncMessagesResponse) Message(org.infobip.mobile.messaging.Message) MessageResponse(org.infobip.mobile.messaging.api.messages.MessageResponse) SyncMessagesBody(org.infobip.mobile.messaging.api.messages.SyncMessagesBody) Test(org.junit.Test)

Example 5 with MessageResponse

use of org.infobip.mobile.messaging.api.messages.MessageResponse 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());
}
Also used : SyncMessagesResponse(org.infobip.mobile.messaging.api.messages.SyncMessagesResponse) MessageResponse(org.infobip.mobile.messaging.api.messages.MessageResponse) SyncMessagesBody(org.infobip.mobile.messaging.api.messages.SyncMessagesBody) Test(org.junit.Test)

Aggregations

MessageResponse (org.infobip.mobile.messaging.api.messages.MessageResponse)5 SyncMessagesBody (org.infobip.mobile.messaging.api.messages.SyncMessagesBody)4 SyncMessagesResponse (org.infobip.mobile.messaging.api.messages.SyncMessagesResponse)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Message (org.infobip.mobile.messaging.Message)2