use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class CoreNotificationHandlerTest method shouldProvideMultipleNotifications_whenMultipleNotificationsEnabled.
@Test
public void shouldProvideMultipleNotifications_whenMultipleNotificationsEnabled() {
// Given
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.DISPLAY_NOTIFICATION_ENABLED, true);
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.MULTIPLE_NOTIFICATIONS_ENABLED, true);
PreferenceHelper.saveClass(context, MobileMessagingProperty.CALLBACK_ACTIVITY, Activity.class);
// When
for (int i = 0; i < 10; i++) {
Message message = new Message();
message.setBody("SomeText");
coreNotificationHandler.displayNotification(message);
}
// Then
Mockito.verify(notificationManagerMock, Mockito.times(10)).notify(notificationCaptor.capture(), Mockito.any(Notification.class));
Set<Integer> notificationIDs = new HashSet<>(notificationCaptor.getAllValues());
assertEquals(10, notificationIDs.size());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class NotificationTapReceiverTest method test_should_set_flags_and_message_for_activity_intent.
@Test
public void test_should_set_flags_and_message_for_activity_intent() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
Intent givenIntent = givenIntent(givenMessage, notificationSettings.getIntentFlags());
// When
notificationTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(contextMock, Mockito.times(1)).startActivity(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(notificationSettings.getIntentFlags() | Intent.FLAG_ACTIVITY_NEW_TASK, intent.getFlags());
Message message = Message.createFrom(intent.getBundleExtra(BroadcastParameter.EXTRA_MESSAGE));
assertJEquals(givenMessage, message);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class FCMMessageMapperTest method test_message_should_be_possible_to_construct_message_from_bundle.
public void test_message_should_be_possible_to_construct_message_from_bundle() throws Exception {
// Given
Bundle bundle = new Bundle();
bundle.putString("gcm.notification.messageId", "SomeMessageId");
bundle.putString("gcm.notification.title", "SomeMessageTitle");
bundle.putString("gcm.notification.body", "SomeMessageBody");
bundle.putString("gcm.notification.sound", "SomeMessageSound");
bundle.putString("gcm.notification.sound2", "SomeMessageSound");
bundle.putString("gcm.notification.vibrate", "true");
bundle.putString("gcm.notification.icon", "SomeMessageIcon");
bundle.putString("gcm.notification.silent", "false");
bundle.putString("gcm.notification.category", "SomeMessageCategory");
bundle.putString("from", "SomeMessageFrom");
bundle.putLong("received_timestamp", 1234L);
bundle.putLong("seen_timestamp", 5678L);
bundle.putString("internalData", "{}");
bundle.putString("customPayload", "{}");
bundle.putString("destination", "SomeDestination");
bundle.putString("status", "SUCCESS");
bundle.putString("status_message", "SomeStatusMessage");
// When
Message message = FCMMessageMapper.fromCloudBundle(bundle);
// Then
assertEquals("SomeMessageId", message.getMessageId());
assertEquals("SomeMessageTitle", message.getTitle());
assertEquals("SomeMessageBody", message.getBody());
assertEquals("SomeMessageSound", message.getSound());
assertEquals(true, message.isVibrate());
assertEquals("SomeMessageIcon", message.getIcon());
assertEquals(false, message.isSilent());
assertEquals("SomeMessageCategory", message.getCategory());
assertEquals("SomeMessageFrom", message.getFrom());
assertEquals(1234L, message.getReceivedTimestamp());
assertEquals(5678L, message.getSeenTimestamp());
assertEquals(0, message.getCustomPayload().length());
assertEquals("SomeDestination", message.getDestination());
assertEquals(Message.Status.SUCCESS, message.getStatus());
assertEquals("SomeStatusMessage", message.getStatusMessage());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class FCMMessageMapperTest method test_silentMessage_fromJson_withSilentData.
public void test_silentMessage_fromJson_withSilentData() throws Exception {
String internalData = "{" + "\"silent\":" + "{" + "\"title\":\"silentTitle\"," + "\"body\":\"silentBody\"," + "\"sound\":\"silentSound\"," + "\"category\":\"silentCategory\"" + "}" + "}";
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("internalData", internalData);
bundle.putString("gcm.notification.silent", "true");
Message message = FCMMessageMapper.fromCloudBundle(bundle);
assertEquals("silentTitle", message.getTitle());
assertEquals("silentBody", message.getBody());
assertEquals("silentSound", message.getSound());
assertEquals("silentCategory", message.getCategory());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class FCMMessageMapperTest method test_customDataWithGcmKeys.
public void test_customDataWithGcmKeys() throws Exception {
String customPayload = "{" + "\"key1\":\"value1\"," + "\"key2\":\"value2\"," + "\"key3\":\"value3\"" + "}";
Bundle bundle = new Bundle();
bundle.putString("customPayload", customPayload);
bundle.putString("gcm.notification.e", "1");
bundle.putString("gcm.notification.messageId", "L+auqUQFlo1yqk2TEakxua/4rc6DmGgm7cM6G0GRQjU=");
bundle.putString("gcm.notification.sound", "default");
bundle.putString("gcm.notification.title", "notification title sender");
bundle.putString("gcm.notification.body", "push text");
bundle.putString("android.support.content.wakelockid", "11");
bundle.putString("collapse_key", "org.infobip.mobile.messaging.showcase.dev");
Message message = FCMMessageMapper.fromCloudBundle(bundle);
JSONAssert.assertEquals(customPayload, message.getCustomPayload(), true);
}
Aggregations