Search in sources :

Example 51 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class FCMMessageMapperTest method test_firstAttachment_shouldMapIntoContentUrl_whenMultipleAttachments.

public void test_firstAttachment_shouldMapIntoContentUrl_whenMultipleAttachments() throws Exception {
    String internalData = "{" + "\"atts\" : [" + "{" + "\"url\":\"someUrl1\"" + "}," + "{" + "\"url\":\"someUrl2\"," + "\"t\":\"someType2\"" + "}," + "{" + "\"url\":\"someUrl3\"," + "\"t\":\"someType3\"" + "}," + "]" + "}";
    Bundle bundle = new Bundle();
    bundle.putString("internalData", internalData);
    Message message = FCMMessageMapper.fromCloudBundle(bundle);
    assertEquals("someUrl1", message.getContentUrl());
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

Example 52 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class FCMMessageMapperTest method test_toBundle_success.

public void test_toBundle_success() throws Exception {
    Message message = new Message();
    message.setTitle("lala");
    message.setFrom("from");
    Bundle plainBundle = FCMMessageMapper.toCloudBundle(message);
    assertEquals(plainBundle.getString("gcm.notification.title"), "lala");
    assertEquals(plainBundle.getString("from"), "from");
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

Example 53 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class SqliteMessageTest method test_message_toFromSqlite.

@Test
public void test_message_toFromSqlite() throws Exception {
    Message message = new Message("SomeMessageId", "SomeTitle", "SomeBody", "SomeSound", true, "SomeIcon", false, "SomeCategory", "SomeFrom", 1234L, 5678L, 9012L, new JSONObject() {

        {
            put("stringValue", "StringValue2");
            put("numberValue", 2);
            put("booleanValue", true);
        }
    }, null, "SomeDestination", Message.Status.SUCCESS, "SomeStatusMessage", "http://www.some-content.com.ru.hr");
    databaseHelper.save(new SqliteMessage(message));
    List<SqliteMessage> messages = databaseHelper.findAll(SqliteMessage.class);
    assertEquals(1, messages.size());
    Message m = messages.get(0);
    assertNotSame(message, m);
    assertEquals("SomeMessageId", m.getMessageId());
    assertEquals("SomeTitle", m.getTitle());
    assertEquals("SomeBody", m.getBody());
    assertEquals("SomeSound", m.getSound());
    assertEquals(true, m.isVibrate());
    assertEquals("SomeIcon", m.getIcon());
    assertEquals(1234L, m.getReceivedTimestamp());
    assertEquals(5678L, m.getSeenTimestamp());
    assertEquals(9012L, m.getSentTimestamp());
    JSONAssert.assertEquals("{" + "'stringValue': 'StringValue2'," + "'numberValue': 2," + "'booleanValue':true" + "}", m.getCustomPayload(), true);
    assertEquals("SomeDestination", message.getDestination());
    assertEquals(Message.Status.SUCCESS, message.getStatus());
    assertEquals("SomeStatusMessage", message.getStatusMessage());
    assertEquals("http://www.some-content.com.ru.hr", message.getContentUrl());
}
Also used : Message(org.infobip.mobile.messaging.Message) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 54 with Message

use of org.infobip.mobile.messaging.Message 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 55 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class AndroidBroadcasterTest method test_should_send_message_broadcast.

@Test
public void test_should_send_message_broadcast() {
    // Given
    Message message = createMessage(context, "SomeMessageId", false);
    // When
    broadcastSender.messageReceived(message);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(Event.MESSAGE_RECEIVED.getKey(), intent.getAction());
    Message messageAfter = Message.createFrom(intent.getExtras());
    assertNotSame(message, messageAfter);
    assertEquals("SomeMessageId", messageAfter.getMessageId());
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

Message (org.infobip.mobile.messaging.Message)87 Test (org.junit.Test)44 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)10 Context (android.content.Context)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 JSONObject (org.json.JSONObject)7 List (java.util.List)6 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)6 Geo (org.infobip.mobile.messaging.geo.Geo)6 Map (java.util.Map)5 MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)5 Area (org.infobip.mobile.messaging.geo.Area)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Date (java.util.Date)4