Search in sources :

Example 1 with MoMessage

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

the class MoMessageSenderTest method shouldNotResendMessagesWhichAreTooOld.

@Test
public void shouldNotResendMessagesWhichAreTooOld() {
    // Given
    Message givenRelevantMessage = new Message();
    Message givenTooOldMessage = new Message() {

        {
            setReceivedTimestamp(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(73));
        }
    };
    given(apiMock.sendMO(any(MoMessagesBody.class))).willThrow(new RuntimeException());
    // When
    moMessageSender.sendWithRetry(givenRelevantMessage, givenTooOldMessage);
    // Then
    verify(apiMock, after(200).atLeast(1)).sendMO(bodyCaptor.capture());
    MoMessage[] actualMessages = bodyCaptor.getValue().getMessages();
    assertEquals(1, actualMessages.length);
    assertEquals(givenRelevantMessage.getMessageId(), actualMessages[0].getMessageId());
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Test(org.junit.Test)

Example 2 with MoMessage

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

the class MoMessageMapper method body.

static MoMessagesBody body(String pushRegistrationId, Message[] messages) {
    List<MoMessage> moMessages = new ArrayList<>();
    for (Message message : messages) {
        String customPayloadString = message.getCustomPayload() != null ? message.getCustomPayload().toString() : null;
        Map customPayloadMap = serializer.deserialize(customPayloadString, Map.class);
        String internalData = message.getInternalData();
        moMessages.add(new MoMessage(message.getMessageId(), message.getDestination(), message.getBody(), InternalDataMapper.getInternalDataInitialMessageId(internalData), InternalDataMapper.getInternalDataBulkId(internalData), customPayloadMap));
    }
    MoMessagesBody moMessagesBody = new MoMessagesBody();
    moMessagesBody.setFrom(pushRegistrationId);
    moMessagesBody.setMessages(moMessages.toArray(new MoMessage[moMessages.size()]));
    return moMessagesBody;
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) Map(java.util.Map) MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage)

Example 3 with MoMessage

use of org.infobip.mobile.messaging.api.messages.MoMessage 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 Message (org.infobip.mobile.messaging.Message)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MoMessagesResponse (org.infobip.mobile.messaging.api.messages.MoMessagesResponse)1