Search in sources :

Example 6 with SyncMessagesResponse

use of org.infobip.mobile.messaging.api.messages.SyncMessagesResponse 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

SyncMessagesBody (org.infobip.mobile.messaging.api.messages.SyncMessagesBody)6 SyncMessagesResponse (org.infobip.mobile.messaging.api.messages.SyncMessagesResponse)6 MessageResponse (org.infobip.mobile.messaging.api.messages.MessageResponse)4 Test (org.junit.Test)4 Message (org.infobip.mobile.messaging.Message)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MRetryableTask (org.infobip.mobile.messaging.mobile.common.MRetryableTask)1