Search in sources :

Example 1 with MoMessagesResponse

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

the class MoMessageSenderTest method shouldOnlySaveNonRetriableMessagesToStore.

@Test
public void shouldOnlySaveNonRetriableMessagesToStore() {
    // Given
    MobileMessagingCore.setMessageStoreClass(context, SQLiteMessageStore.class);
    Message givenMessage1 = givenMessage("someMessageId1");
    Message givenMessage2 = givenMessage("someMessageId2");
    final MoMessageDelivery givenDelivery1 = givenDelivery(givenMessage1.getMessageId());
    final MoMessageDelivery givenDelivery2 = givenDelivery(givenMessage2.getMessageId());
    given(apiMock.sendMO(any(MoMessagesBody.class))).willReturn(new MoMessagesResponse(new MoMessageDelivery[] { givenDelivery1 })).willReturn(new MoMessagesResponse(new MoMessageDelivery[] { givenDelivery2 }));
    // When
    moMessageSender.send(null, givenMessage1);
    moMessageSender.sendWithRetry(givenMessage2);
    // Then
    verify(apiMock, after(200).atLeast(1)).sendMO(any(MoMessagesBody.class));
    verify(messageStoreWrapperMock, times(1)).upsert(messageCaptor.capture());
    List<Message> storedMessages = getAllMessages(messageCaptor.getAllValues());
    assertEquals(1, storedMessages.size());
    assertEquals(givenMessage1.getMessageId(), storedMessages.get(0).getMessageId());
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) MoMessageDelivery(org.infobip.mobile.messaging.api.messages.MoMessageDelivery) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessagesResponse(org.infobip.mobile.messaging.api.messages.MoMessagesResponse) Test(org.junit.Test)

Example 2 with MoMessagesResponse

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

the class MoMessageSenderTest method shouldSendMultipleMessages.

@Test
public void shouldSendMultipleMessages() throws Exception {
    // Given
    final MoMessageDelivery givenMessage1 = new MoMessageDelivery() {

        {
            setStatus("Message not sent");
            setStatusCode(1);
            setMessageId("myMessageId");
            setDestination("myDestination");
            setText("myText");
            setCustomPayload(new HashMap<String, Object>() {

                {
                    put("myStringKey", "string");
                    put("myBooleanKey", true);
                    put("myNumberKey", 1);
                }
            });
        }
    };
    final MoMessageDelivery givenMessage2 = new MoMessageDelivery() {

        {
            setStatus("Message sent");
            setStatusCode(0);
            setMessageId("myMessageId2");
            setDestination("myDestination2");
            setText("myText2");
            setCustomPayload(new HashMap<String, Object>() {

                {
                    put("myStringKey", "string2");
                    put("myBooleanKey", false);
                    put("myNumberKey", 2);
                }
            });
        }
    };
    MoMessagesResponse givenResponse = new MoMessagesResponse() {

        {
            setMessages(new MoMessageDelivery[] { givenMessage1, givenMessage2 });
        }
    };
    given(apiMock.sendMO(any(MoMessagesBody.class))).willReturn(givenResponse);
    // When
    moMessageSender.send(null, givenMessage(givenMessage1.getMessageId()), givenMessage(givenMessage2.getMessageId()));
    // Then
    verify(broadcaster, after(1000).atLeastOnce()).messagesSent(captor.capture());
    List<Message> messages = captor.getValue();
    assertEquals("myMessageId", messages.get(0).getMessageId());
    assertEquals(Message.Status.ERROR, messages.get(0).getStatus());
    assertEquals("Message not sent", messages.get(0).getStatusMessage());
    assertEquals("myDestination", messages.get(0).getDestination());
    assertEquals("myText", messages.get(0).getBody());
    assertEquals("string", messages.get(0).getCustomPayload().opt("myStringKey"));
    assertEquals(1.0, messages.get(0).getCustomPayload().optDouble("myNumberKey"), 0.01);
    assertEquals(true, messages.get(0).getCustomPayload().opt("myBooleanKey"));
    assertEquals("myMessageId2", messages.get(1).getMessageId());
    assertEquals(Message.Status.SUCCESS, messages.get(1).getStatus());
    assertEquals("Message sent", messages.get(1).getStatusMessage());
    assertEquals("myDestination2", messages.get(1).getDestination());
    assertEquals("myText2", messages.get(1).getBody());
    assertEquals("string2", messages.get(1).getCustomPayload().opt("myStringKey"));
    assertEquals(2.0, messages.get(1).getCustomPayload().optDouble("myNumberKey"), 0.01);
    assertEquals(false, messages.get(1).getCustomPayload().opt("myBooleanKey"));
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) MoMessageDelivery(org.infobip.mobile.messaging.api.messages.MoMessageDelivery) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessagesResponse(org.infobip.mobile.messaging.api.messages.MoMessagesResponse) Test(org.junit.Test)

Example 3 with MoMessagesResponse

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

the class MobileApiMessagesTest method create_sendMO_success.

@Test
public void create_sendMO_success() throws Exception {
    String serverResponse = "{" + "\"messages\":" + "[" + "{" + "\"status\" :       \"myStatusId\"," + "\"statusCode\" :   0," + "\"messageId\" :    \"myMessageId\"," + "\"destination\" :  \"myDestination\"," + "\"text\" :         \"myText\"," + "\"customPayload\":" + "{" + "\"myStringKey\" :   \"string\"," + "\"myBooleanKey\":   true," + "\"myNumberKey\" :   1" + "}" + "}," + "{" + "\"status\" :       \"myStatusId2\"," + "\"statusCode\" :   1," + "\"messageId\" :    \"myMessageId2\"," + "\"destination\" :  \"myDestination2\"," + "\"text\" :         \"myText2\"," + "\"customPayload\":" + "{" + "\"myStringKey\" :   \"string2\"," + "\"myBooleanKey\":   false," + "\"myNumberKey\" :   2" + "}" + "}" + "]" + "}";
    debugServer.respondWith(NanoHTTPD.Response.Status.OK, serverResponse);
    MoMessage[] moMessages = { new MoMessage("myMessageId", "myDestination", "myText", "myInitialMessageId", "myBulkId", new HashMap<String, Object>() {

        {
            put("myStringKey", "string1");
            put("myNubmberKey", 1);
            put("myBooleanKey", true);
        }
    }), new MoMessage("myMessageId2", "myDestination2", "myText2", null, "myBulkId2", new HashMap<String, Object>() {

        {
            put("myStringKey", "string2");
            put("myNubmberKey", 2);
            put("myBooleanKey", false);
        }
    }) };
    MoMessagesBody requestBody = new MoMessagesBody();
    requestBody.setFrom("fromTest");
    requestBody.setMessages(moMessages);
    MoMessagesResponse moMessagesResponse = mobileApiMessages.sendMO(requestBody);
    // inspect http context
    assertThat(debugServer.getUri()).isEqualTo("/mobile/1/messages/mo");
    assertThat(debugServer.getRequestCount()).isEqualTo(1);
    assertThat(debugServer.getRequestMethod()).isEqualTo(NanoHTTPD.Method.POST);
    assertThat(debugServer.getQueryParametersCount()).isEqualTo(1);
    // inspect parameters
    assertEquals("GCM", debugServer.getQueryParameter("platformType"));
    // inspect response
    assertEquals(2, moMessagesResponse.getMessages().length);
    assertEquals("myMessageId", moMessagesResponse.getMessages()[0].getMessageId());
    assertEquals("myStatusId", moMessagesResponse.getMessages()[0].getStatus());
    assertEquals(0, moMessagesResponse.getMessages()[0].getStatusCode());
    assertEquals("myDestination", moMessagesResponse.getMessages()[0].getDestination());
    assertEquals("myText", moMessagesResponse.getMessages()[0].getText());
    assertEquals("string", moMessagesResponse.getMessages()[0].getCustomPayload().get("myStringKey"));
    assertEquals(1.0, moMessagesResponse.getMessages()[0].getCustomPayload().get("myNumberKey"));
    assertEquals(true, moMessagesResponse.getMessages()[0].getCustomPayload().get("myBooleanKey"));
    assertEquals("myMessageId2", moMessagesResponse.getMessages()[1].getMessageId());
    assertEquals("myStatusId2", moMessagesResponse.getMessages()[1].getStatus());
    assertEquals(1, moMessagesResponse.getMessages()[1].getStatusCode());
    assertEquals("myDestination2", moMessagesResponse.getMessages()[1].getDestination());
    assertEquals("myText2", moMessagesResponse.getMessages()[1].getText());
    assertEquals("string2", moMessagesResponse.getMessages()[1].getCustomPayload().get("myStringKey"));
    assertEquals(2.0, moMessagesResponse.getMessages()[1].getCustomPayload().get("myNumberKey"));
    assertEquals(false, moMessagesResponse.getMessages()[1].getCustomPayload().get("myBooleanKey"));
}
Also used : HashMap(java.util.HashMap) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessagesResponse(org.infobip.mobile.messaging.api.messages.MoMessagesResponse) MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Test(org.junit.Test)

Aggregations

MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)3 MoMessagesBody (org.infobip.mobile.messaging.api.messages.MoMessagesBody)3 MoMessagesResponse (org.infobip.mobile.messaging.api.messages.MoMessagesResponse)3 Test (org.junit.Test)3 Message (org.infobip.mobile.messaging.Message)2 MoMessageDelivery (org.infobip.mobile.messaging.api.messages.MoMessageDelivery)2 HashMap (java.util.HashMap)1