use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelperTest method test_should_update_list_of_inactive_campaigns_based_on_report_result.
@Test
public void test_should_update_list_of_inactive_campaigns_based_on_report_result() {
// Given
EventReportResponse reportResponse = new EventReportResponse();
reportResponse.setSuspendedCampaignIds(Sets.newSet("campaignId1"));
reportResponse.setFinishedCampaignIds(Sets.newSet("campaignId2"));
// When
Set<String> ids = GeoReportHelper.getAndUpdateInactiveCampaigns(context, new GeoReportingResult(reportResponse));
// Then
assertTrue(GeofencingHelper.getSuspendedCampaignIds(context).contains("campaignId1"));
assertTrue(ids.contains("campaignId1"));
assertTrue(GeofencingHelper.getFinishedCampaignIds(context).contains("campaignId2"));
assertTrue(ids.contains("campaignId2"));
}
use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandler method handleTransition.
/**
* Handles geofencing intent and reports corresponding areas to server
*
* @param transition resolved transition information
*/
@SuppressWarnings("WeakerAccess")
public void handleTransition(GeoTransition transition) {
MobileMessagingLogger.v("GEO TRANSITION", transition);
Map<Message, List<Area>> messagesAndAreas = GeoReportHelper.findSignalingMessagesAndAreas(context, geoMessageStore, transition.getRequestIds(), transition.getEventType());
if (messagesAndAreas.isEmpty()) {
MobileMessagingLogger.d(TAG, "No messages for triggered areas");
return;
}
logGeofences(messagesAndAreas.values(), transition.getEventType());
geofencingHelper.addUnreportedGeoEvents(GeoReportHelper.createReportsForMultipleMessages(context, messagesAndAreas, transition.getEventType(), transition.getTriggeringLocation()));
GeoReport[] unreportedEvents = geofencingHelper.removeUnreportedGeoEvents();
if (unreportedEvents.length == 0) {
MobileMessagingLogger.d(TAG, "No geofencing events to report at current time");
return;
}
try {
GeoReportingResult result = geoReporter.reportSync(unreportedEvents);
handleReportingResultWithNewMessagesAndNotifications(unreportedEvents, result);
} catch (Exception e) {
MobileMessagingLogger.e(TAG, "Failed to report geo events " + e.toString());
handleGeoReportingResult(context, new GeoReportingResult(e));
}
}
use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_notify_messages_only_for_active_campaigns.
@Test
public void test_should_notify_messages_only_for_active_campaigns() throws InterruptedException {
// Given
Area area = createArea("areaId1");
Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Arrays.asList(createMessage(context, "signalingMessageId1", "campaignId1", true, area), createMessage(context, "signalingMessageId2", "campaignId2", true, area), createMessage(context, "signalingMessageId3", "campaignId3", true, area)));
EventReportResponse response = new EventReportResponse();
response.setSuspendedCampaignIds(Sets.newSet("campaignId1"));
response.setFinishedCampaignIds(Sets.newSet("campaignId2"));
Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(response));
GeoTransition transition = GeoHelper.createTransition("areaId1");
// When
geoAreasHandler.handleTransition(transition);
// Then
Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());
assertEquals(1, geoNotificationCaptor.getValue().size());
Map.Entry<Message, GeoEventType> notification = geoNotificationCaptor.getValue().entrySet().iterator().next();
assertEquals(GeoEventType.entry, notification.getValue());
Message message = notification.getKey();
Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
assertNotNull(geo);
assertNotSame("signalingMessageId3", message.getMessageId());
assertTrue(StringUtils.isNotBlank(message.getMessageId()));
assertEquals("campaignId3", geo.getCampaignId());
assertEquals("areaId1", geo.getAreasList().get(0).getId());
}
use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_report_transition.
@Test
public void test_should_report_transition() {
// Given
Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));
Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));
Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));
GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");
time.set(789);
// When
geoAreasHandler.handleTransition(transition);
// Then
Mockito.verify(geoReporter, Mockito.times(1)).reportSync(geoReportCaptor.capture());
GeoReport report = geoReportCaptor.getValue()[0];
assertEquals("SomeAreaId", report.getArea().getId());
assertEquals("SomeCampaignId", report.getCampaignId());
assertEquals("SomeSignalingMessageId", report.getSignalingMessageId());
assertNotSame("SomeSignalingMessageId", report.getMessageId());
assertTrue(StringUtils.isNotBlank(report.getMessageId()));
assertEquals(789, report.getTimestampOccurred().longValue());
assertEquals(123.0, report.getTriggeringLocation().getLat());
assertEquals(456.0, report.getTriggeringLocation().getLng());
}
use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_save_messages_with_generated_ids_if_report_unsuccessful.
@Test
public void test_should_save_messages_with_generated_ids_if_report_unsuccessful() {
// Given
Message m = createMessage(context, "SomeSignalingMessageId", "SomeCampaignId", true, createArea("SomeAreaId"));
Mockito.when(messageStore.findAll(Mockito.any(Context.class))).thenReturn(Collections.singletonList(m));
Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenReturn(new GeoReportingResult(new Exception()));
GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");
time.set(789);
// When
geoAreasHandler.handleTransition(transition);
// Then
Message message = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context).get(0);
Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
assertNotNull(geo);
assertNotSame("SomeSignalingMessageId", message.getMessageId());
assertTrue(StringUtils.isNotBlank(message.getMessageId()));
assertEquals("SomeCampaignId", geo.getCampaignId());
assertEquals(123.0, geo.getTriggeringLatitude());
assertEquals(456.0, geo.getTriggeringLongitude());
assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());
}
Aggregations