use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class FCMMessageMapperTest method test_silentMessage_fromJson_withoutSilentData.
public void test_silentMessage_fromJson_withoutSilentData() throws Exception {
Bundle bundle = new Bundle();
bundle.putString("gcm.notification.e", "1");
bundle.putString("gcm.notification.messageId", "L+auqUQFlo1yqk2TEakxua/4rc6DmGgm7cM6G0GRQjU=");
bundle.putString("android.support.content.wakelockid", "11");
bundle.putString("collapse_key", "org.infobip.mobile.messaging.showcase.dev");
bundle.putString("gcm.notification.silent", "true");
bundle.putString("gcm.notification.title", "notSilentTitle");
bundle.putString("gcm.notification.body", "notSilentBody");
bundle.putString("gcm.notification.sound", "notSilentSound");
Message message = FCMMessageMapper.fromCloudBundle(bundle);
assertNotEquals("notSilentTitle", message.getTitle());
assertNotEquals("notSilentBody", message.getBody());
assertNotEquals("notSilentSound", message.getSound());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class SqliteMessageTest method test_message_shouldNotSaveMessageWithNullId.
@Test
public void test_message_shouldNotSaveMessageWithNullId() throws Exception {
Message message = new Message();
message.setMessageId(null);
try {
databaseHelper.save(new SqliteMessage(message));
fail();
} catch (SQLiteConstraintException ignored) {
}
}
use of org.infobip.mobile.messaging.Message 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());
}
use of org.infobip.mobile.messaging.Message 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"));
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class AndroidBroadcasterTest method test_should_send_notification_tapped_event.
@Test
public void test_should_send_notification_tapped_event() throws Exception {
// Given
Message message = createMessage(context, "SomeMessageId", false);
// When
broadcastSender.notificationTapped(message);
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(Event.NOTIFICATION_TAPPED.getKey(), intent.getAction());
Message messageAfter = Message.createFrom(intent.getExtras());
assertNotSame(message, messageAfter);
assertEquals("SomeMessageId", messageAfter.getMessageId());
}
Aggregations