use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method test_withNonActiveCampaigns.
@Test
public void test_withNonActiveCampaigns() throws InterruptedException {
// 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);
given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse() {
{
setFinishedCampaignIds(newSet("campaignId1"));
setSuspendedCampaignIds(newSet("campaignId2"));
}
});
// When
geoReporter.synchronize();
// Then
// Examine what is reported back via broadcast intent
Mockito.verify(geoBroadcaster, Mockito.after(1000).atLeastOnce()).geoReported(geoReportCaptor.capture());
List<GeoReport> broadcastedReports = geoReportCaptor.getValue();
assertEquals(broadcastedReports.size(), 1);
GeoReport geoReport = broadcastedReports.get(0);
assertEquals(GeoEventType.entry, geoReport.getEvent());
assertEquals("campaignId3", geoReport.getCampaignId());
assertEquals("messageId3", geoReport.getMessageId());
assertEquals("areaId3", geoReport.getArea().getId());
final Set<String> finishedCampaignIds = PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.FINISHED_CAMPAIGN_IDS.getKey(), new ArraySet<String>(0));
final Set<String> suspendedCampaignIds = PreferenceHelper.findStringSet(context, MobileMessagingGeoProperty.SUSPENDED_CAMPAIGN_IDS.getKey(), new ArraySet<String>(0));
assertEquals(finishedCampaignIds.size(), 1);
assertEquals(finishedCampaignIds.iterator().next(), "campaignId1");
assertEquals(suspendedCampaignIds.size(), 1);
assertEquals(suspendedCampaignIds.iterator().next(), "campaignId2");
}
use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method test_shouldNotReportSeenForMessageIdsGeneratedForGeoReports.
@Test
public void test_shouldNotReportSeenForMessageIdsGeneratedForGeoReports() throws InterruptedException {
// Given
createMessage(context, "signalingMessageId1", "campaignId1", true);
createMessage(context, "generatedMessageId1", "campaignId1", true);
GeoReport report = createReport(context, "signalingMessageId1", "campaignId1", "generatedMessageId1", true);
mobileMessagingCore.addGeneratedMessageIds(report.getMessageId());
PreferenceHelper.saveLong(context, MobileMessagingProperty.BATCH_REPORTING_DELAY, 10L);
given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse());
// When
mobileMessaging.setMessagesSeen("generatedMessageId1");
// Then
Mockito.verify(coreBroadcaster, Mockito.after(1000).never()).seenStatusReported(any(String[].class));
}
use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class PushUnregisteredTest method verifyGeoReporting.
private void verifyGeoReporting(VerificationMode verificationMode) throws InterruptedException {
// Given
GeoReport report1 = createReport(context, "signalingMessageId1", "campaignId1", "messageId1", true, createArea("areaId1"));
GeoReport report2 = createReport(context, "signalingMessageId2", "campaignId2", "messageId2", true, createArea("areaId2"));
GeoReport report3 = createReport(context, "signalingMessageId3", "campaignId3", "messageId3", true, createArea("areaId3"));
createMessage(context, "signalingMessageId1", "campaignId1", true, report1.getArea(), report2.getArea());
createMessage(context, "signalingMessageId2", "campaignId2", true, report3.getArea());
given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse());
// When
geoReporter.synchronize();
// Then
// noinspection unchecked
verify(geoBroadcaster, verificationMode).geoReported(any(List.class));
}
use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_notify_messages_with_server_ids_if_report_successful.
@Test
public void test_should_notify_messages_with_server_ids_if_report_successful() {
// 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))).thenAnswer(new Answer<GeoReportingResult>() {
@Override
public GeoReportingResult answer(InvocationOnMock invocation) throws Throwable {
final GeoReport[] reports = (GeoReport[]) invocation.getArguments()[0];
EventReportResponse eventReportResponse = new EventReportResponse();
eventReportResponse.setMessageIds(new HashMap<String, String>() {
{
put(reports[0].getMessageId(), "SomeServerMessageId");
}
});
return new GeoReportingResult(eventReportResponse);
}
});
GeoTransition transition = GeoHelper.createTransition(123.0, 456.0, "SomeAreaId");
time.set(789);
// When
geoAreasHandler.handleTransition(transition);
// Then
Mockito.verify(geoNotificationHelper, Mockito.times(1)).notifyAboutGeoTransitions(geoNotificationCaptor.capture());
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);
assertEquals("SomeServerMessageId", message.getMessageId());
assertEquals("SomeCampaignId", geo.getCampaignId());
assertEquals(123.0, geo.getTriggeringLatitude());
assertEquals(456.0, geo.getTriggeringLongitude());
assertEquals("SomeAreaId", geo.getAreasList().get(0).getId());
}
use of org.infobip.mobile.messaging.geo.report.GeoReport in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_save_messages_with_server_ids_if_report_successful.
@Test
public void test_should_save_messages_with_server_ids_if_report_successful() {
// 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))).thenAnswer(new Answer<GeoReportingResult>() {
@Override
public GeoReportingResult answer(InvocationOnMock invocation) throws Throwable {
final GeoReport[] reports = (GeoReport[]) invocation.getArguments()[0];
EventReportResponse eventReportResponse = new EventReportResponse();
eventReportResponse.setMessageIds(new HashMap<String, String>() {
{
put(reports[0].getMessageId(), "SomeServerMessageId");
}
});
return new GeoReportingResult(eventReportResponse);
}
});
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