Search in sources :

Example 46 with Message

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());
}
Also used : Message(org.infobip.mobile.messaging.Message) Notification(android.app.Notification) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 47 with Message

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);
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

Example 48 with 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());
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

Example 49 with Message

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());
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

Example 50 with Message

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);
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

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