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());
}
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");
}
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());
}
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());
}
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());
}
Aggregations