use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class AndroidBroadcasterTest method test_should_send_mo_messages.
@Test
public void test_should_send_mo_messages() {
// Given
Message message = createMessage(context, "SomeMessageId", false);
// When
broadcastSender.messagesSent(Collections.singletonList(message));
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(Event.MESSAGES_SENT.getKey(), intent.getAction());
List<Message> messagesAfter = Message.createFrom(intent.<Bundle>getParcelableArrayListExtra(BroadcastParameter.EXTRA_MESSAGES));
assertEquals(1, messagesAfter.size());
assertEquals("SomeMessageId", messagesAfter.get(0).getMessageId());
}
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;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelper method createMessagesToNotify.
/**
* Creates new geo notification messages based on reporting result
*
* @param reportedEvents events that were reported to server
* @param reportingResult response from the server
* @return map of messages and corresponding geo event types for each message
*/
public static Map<Message, GeoEventType> createMessagesToNotify(Context context, List<GeoReport> reportedEvents, @NonNull GeoReportingResult reportingResult) {
GeofencingHelper geofencingHelper = new GeofencingHelper(context);
List<Message> allMessages = geofencingHelper.getMessageStoreForGeo().findAll(context);
Map<Message, GeoEventType> messages = new ArrayMap<>();
for (GeoReport report : reportedEvents) {
Message signalingMessage = GeoReportHelper.getSignalingMessageForReport(allMessages, report);
if (signalingMessage == null) {
MobileMessagingLogger.e("Cannot find signaling message for id: " + report.getSignalingMessageId());
continue;
}
messages.put(createNewMessageForReport(report, reportingResult, signalingMessage), report.getEvent());
}
return messages;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelper method createNewMessageForReport.
/**
* Creates new message based on geofencing report
*
* @param report geofencing report for any supported event
* @param reportingResult result of reporting geo events to server
* @param originalMessage original signaling message
* @return new message based on triggering event, area and original signaling message
*/
private static Message createNewMessageForReport(@NonNull final GeoReport report, @NonNull GeoReportingResult reportingResult, @NonNull Message originalMessage) {
GeoLatLng triggeringLocation = report.getTriggeringLocation();
if (triggeringLocation == null) {
triggeringLocation = new GeoLatLng(null, null);
}
List<Area> areas = new ArrayList<>();
if (report.getArea() != null) {
areas.add(report.getArea());
}
Geo geo;
Geo originalMessageGeo = GeoDataMapper.geoFromInternalData(originalMessage.getInternalData());
if (originalMessageGeo != null) {
geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), originalMessageGeo.getDeliveryTime(), originalMessageGeo.getExpiryTime(), originalMessageGeo.getStartTime(), originalMessageGeo.getCampaignId(), areas, originalMessageGeo.getEvents(), originalMessage.getSentTimestamp(), originalMessage.getContentUrl());
} else {
geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), null, null, null, null, areas, null, Time.now(), originalMessage.getContentUrl());
}
String internalData = GeoDataMapper.geoToInternalData(geo);
return new Message(getMessageIdFromReport(report, reportingResult), originalMessage.getTitle(), originalMessage.getBody(), originalMessage.getSound(), originalMessage.isVibrate(), originalMessage.getIcon(), // enforcing non-silent
false, originalMessage.getCategory(), originalMessage.getFrom(), Time.now(), 0, Time.now(), originalMessage.getCustomPayload(), internalData, originalMessage.getDestination(), originalMessage.getStatus(), originalMessage.getStatusMessage(), originalMessage.getContentUrl());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_trigger_sdk_actions_when_clicked_on_action_button.
@Test
public void test_should_trigger_sdk_actions_when_clicked_on_action_button() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, 1234, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
Message actualMessage = messageArgumentCaptor.getValue();
NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
}
Aggregations