Search in sources :

Example 81 with Message

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

the class GeoReportHelperTest method test_should_find_signaling_messages_for_report.

@Test
public void test_should_find_signaling_messages_for_report() throws Exception {
    // Given
    Message m1 = createMessage(context, "signalingMessageId", "campaignId", true, createArea("areaId"));
    Message m2 = createMessage(context, "signalingMessageI2", "campaignId", true, createArea("areaId"));
    Message m3 = createMessage(context, "signalingMessageI3", "campaignId", true, createArea("areaId"));
    GeoReport report = createReport(context, "signalingMessageId", "campaignId", "sdkMessageId", false);
    // When
    Message foundMessage = GeoReportHelper.getSignalingMessageForReport(Arrays.asList(m1, m2, m3), report);
    // Then
    assertJEquals(m1, foundMessage);
}
Also used : GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 82 with Message

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

the class GeoReportHelperTest method test_should_create_messages_with_generated_ids_for_unsuccessful_report.

@Test
public void test_should_create_messages_with_generated_ids_for_unsuccessful_report() {
    // Given
    Area area = createArea("areaId");
    GeoReport report = createReport(context, "signalingMessageId", "campaignId", "sdkMessageId", false, area);
    GeoReportingResult geoReportingResult = new GeoReportingResult(new Exception());
    createMessage(context, "signalingMessageId", "campaignId", true, area);
    // When
    Map<Message, GeoEventType> messages = GeoReportHelper.createMessagesToNotify(context, Collections.singletonList(report), geoReportingResult);
    // Then
    Message generated = messages.keySet().iterator().next();
    assertEquals("sdkMessageId", generated.getMessageId());
    assertEquals(GeoEventType.entry, messages.values().iterator().next());
}
Also used : GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

Example 83 with Message

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

the class NotificationCategoriesTest method shouldPerformSendMoAndMarkMessagesSeen_whenTriggeringSdkActions.

@Test
public void shouldPerformSendMoAndMarkMessagesSeen_whenTriggeringSdkActions() throws Exception {
    // given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
    NotificationCategory givenCategory = givenNotificationCategory(givenTappedNotificationAction);
    // when
    mobileInteractive.triggerSdkActionsFor(givenCategory.getCategoryId(), givenTappedNotificationAction, givenMessage);
    // then
    Mockito.verify(mmcMock, Mockito.times(1)).setMessagesSeen(messageIdArgumentCaptor.capture());
    Mockito.verify(mmcMock, Mockito.times(1)).sendMessagesWithRetry(messageArgumentCaptor.capture());
    Message actualMessage = messageArgumentCaptor.getValue();
    assertEquals(givenCategory.getCategoryId() + " " + givenTappedNotificationAction.getId(), actualMessage.getBody());
    assertEquals(givenMessage.getMessageId(), InternalDataMapper.getInternalDataInitialMessageId(actualMessage.getInternalData()));
    assertEquals(givenMessage.getMessageId(), messageIdArgumentCaptor.getValue());
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 84 with Message

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

the class AndroidInteractiveBroadcasterTest method test_should_send_notification_action_tapped_event.

@Test
public void test_should_send_notification_action_tapped_event() throws Exception {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    NotificationAction notificationAction = givenNotificationAction("actionIdNotTapped").build();
    NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
    NotificationCategory givenNotificationCategory = new NotificationCategory("categoryId", notificationAction, givenTappedNotificationAction);
    // When
    broadcastSender.notificationActionTapped(givenMessage, givenNotificationCategory, givenTappedNotificationAction);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(InteractiveEvent.NOTIFICATION_ACTION_TAPPED.getKey(), intent.getAction());
    Message messageAfter = Message.createFrom(intent.getExtras());
    NotificationAction actionAfter = NotificationAction.createFrom(intent.getExtras());
    NotificationCategory categoryAfter = NotificationCategory.createFrom(intent.getExtras());
    assertNotSame(message, messageAfter);
    assertEquals("SomeMessageId", messageAfter.getMessageId());
    assertJEquals(givenMessage, messageAfter);
    assertJEquals(givenTappedNotificationAction, actionAfter);
    assertJEquals(givenNotificationCategory, categoryAfter);
}
Also used : Message(org.infobip.mobile.messaging.Message) NotificationAction(org.infobip.mobile.messaging.interactive.NotificationAction) Intent(android.content.Intent) NotificationCategory(org.infobip.mobile.messaging.interactive.NotificationCategory) Test(org.junit.Test)

Example 85 with Message

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

the class MobileMessagingTestCase method createMessage.

/**
 * Generates messages with provided ids and geo campaign object
 *
 * @param saveToStorage set to true to save messages to message store
 * @param messageId     message id for a message
 * @return new message
 */
protected static Message createMessage(Context context, String messageId, boolean saveToStorage) {
    Message message = new Message();
    message.setMessageId(messageId);
    if (saveToStorage) {
        MobileMessagingCore.getInstance(context).getMessageStore().save(context, message);
    }
    return message;
}
Also used : Message(org.infobip.mobile.messaging.Message)

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