use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelperTest method test_should_create_messages_with_server_ids_for_successful_report.
@Test
public void test_should_create_messages_with_server_ids_for_successful_report() {
// Given
Area area = createArea("areaId");
GeoReport report = createReport(context, "signalingMessageId", "campaignId", "sdkMessageId", false, area);
EventReportResponse reportResponse = new EventReportResponse();
reportResponse.setMessageIds(new HashMap<String, String>() {
{
put("sdkMessageId", "serverMessageId");
}
});
GeoReportingResult geoReportingResult = new GeoReportingResult(reportResponse);
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("serverMessageId", generated.getMessageId());
assertEquals(GeoEventType.entry, messages.values().iterator().next());
}
use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class AndroidGeoBroadcasterTest method test_should_send_geo_reports.
@Test
public void test_should_send_geo_reports() throws Exception {
// Given
GeoReport report = createReport(context, "SomeSignalingMessageId", "SomeCampaignId", "SomeSDKMessageId", false);
// When
broadcastSender.geoReported(Collections.singletonList(report));
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(GeoEvent.GEOFENCE_EVENTS_REPORTED.getKey(), intent.getAction());
List<GeoReport> reportsAfter = GeoReport.createFrom(intent.getExtras());
assertEquals(1, reportsAfter.size());
assertJEquals(report, reportsAfter.get(0));
}
use of org.infobip.mobile.messaging.geo.report.GeoReport 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.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method test_success.
@Test
public void test_success() throws Exception {
// Given
Area area1 = createArea("areaId1");
Area area2 = createArea("areaId2");
Area area3 = createArea("areaId3");
createMessage(context, "signalingMessageId1", "campaignId1", true, area1, area2);
createMessage(context, "signalingMessageId2", "campaignId3", true, area3);
createReport(context, "signalingMessageId1", "campaignId1", "messageId1", true, area1);
createReport(context, "signalingMessageId1", "campaignId1", "messageId2", true, area2);
createReport(context, "signalingMessageId2", "campaignId3", "messageId3", true, area3);
// When
geoReporter.synchronize();
// Then
// Examine what is reported back via broadcast intent
Mockito.verify(geoBroadcaster, Mockito.after(5000).atLeastOnce()).geoReported(geoReportCaptor.capture());
List<GeoReport> broadcastedReports = geoReportCaptor.getValue();
assertEquals(3, broadcastedReports.size());
for (GeoReport r : broadcastedReports) {
switch(r.getMessageId()) {
case "messageId1":
assertEquals(GeoEventType.entry, r.getEvent());
assertEquals("campaignId1", r.getCampaignId());
assertEquals("signalingMessageId1", r.getSignalingMessageId());
assertEquals(r.getMessageId(), "messageId1");
assertEquals(r.getArea().getId(), "areaId1");
break;
case "messageId2":
assertEquals(GeoEventType.entry, r.getEvent());
assertEquals("campaignId1", r.getCampaignId());
assertEquals("signalingMessageId1", r.getSignalingMessageId());
assertEquals("messageId2", r.getMessageId());
assertEquals("areaId2", r.getArea().getId());
break;
case "messageId3":
assertEquals(GeoEventType.entry, r.getEvent());
assertEquals("campaignId3", r.getCampaignId());
assertEquals("signalingMessageId2", r.getSignalingMessageId());
assertEquals("messageId3", r.getMessageId());
assertEquals("areaId3", r.getArea().getId());
break;
default:
assertTrue("Unexpected message id " + r.getMessageId(), false);
break;
}
}
// Examine HTTP request body
final EventReportBody body = reportBodyCaptor.getValue();
assertEquals(2, body.getMessages().size());
Set<String> messageIds = new HashSet<String>() {
{
List<MessagePayload> ps = new ArrayList<>(body.getMessages());
add(ps.get(0).getMessageId());
add(ps.get(1).getMessageId());
}
};
assertTrue(messageIds.contains("signalingMessageId1"));
assertTrue(messageIds.contains("signalingMessageId2"));
assertEquals(3, body.getReports().size());
EventReport[] reports = body.getReports().toArray(new EventReport[body.getReports().size()]);
assertNotSame(reports[0].getTimestampDelta(), reports[1].getTimestampDelta());
assertNotSame(reports[0].getTimestampDelta(), reports[2].getTimestampDelta());
assertNotSame(reports[1].getTimestampDelta(), reports[2].getTimestampDelta());
assertEquals(3, reports.length);
for (EventReport report : reports) {
switch(report.getSdkMessageId()) {
case "messageId1":
assertEquals(EventType.entry, report.getEvent());
assertEquals("areaId1", report.getGeoAreaId());
assertEquals("signalingMessageId1", report.getMessageId());
assertEquals("campaignId1", report.getCampaignId());
assertNotNull(report.getTimestampDelta());
break;
case "messageId2":
assertEquals(EventType.entry, report.getEvent());
assertEquals("areaId2", report.getGeoAreaId());
assertEquals("signalingMessageId1", report.getMessageId());
assertEquals("campaignId1", report.getCampaignId());
assertNotNull(report.getTimestampDelta());
break;
case "messageId3":
assertEquals(EventType.entry, report.getEvent());
assertEquals("areaId3", report.getGeoAreaId());
assertEquals("signalingMessageId2", report.getMessageId());
assertEquals("campaignId3", report.getCampaignId());
assertNotNull(report.getTimestampDelta());
break;
default:
assertTrue("Unexpected message id " + report.getMessageId(), false);
break;
}
}
}
use of org.infobip.mobile.messaging.geo.report.GeoReport 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());
}
Aggregations