use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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.api.geo.EventReportResponse 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.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandlerTests method test_should_generate_messages_only_for_active_campaigns.
@Test
public void test_should_generate_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, "some url", area), createMessage(context, "signalingMessageId2", "campaignId2", true, "some url", area), createMessage(context, "signalingMessageId3", "campaignId3", true, "some url", 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
List<Message> messages = geoAreasHandler.getMobileMessagingCore().getMessageStore().findAll(context);
assertEquals(1, messages.size());
Message message = messages.get(0);
Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
assertNotNull(geo);
assertNotSame("signalingMessageId3", message.getMessageId());
assertEquals("some url", message.getContentUrl());
assertTrue(StringUtils.isNotBlank(message.getMessageId()));
assertEquals("campaignId3", geo.getCampaignId());
assertEquals("areaId1", geo.getAreasList().get(0).getId());
}
use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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());
}
use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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());
}
Aggregations