use of org.infobip.mobile.messaging.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.
the class MobileApiGeoTest method create_eventReport_success.
@Test
public void create_eventReport_success() throws Exception {
String jsonResponse = "{" + " 'finishedCampaignIds':['id1', 'id2', 'id3']," + " 'suspendedCampaignIds':['id4', 'id5', 'id6']," + " 'messageIds':{'messageId1':'newMessageId1', 'messageId2':'newMessageId2', 'messageId3':'newMessageId3'}" + "}";
Set<EventReport> events = new HashSet<EventReport>() {
{
add(new EventReport(EventType.entry, "myAreaId1", "campaignId1", "messageId1", "sdkMessageId1", 1L));
add(new EventReport(EventType.exit, "myAreaId2", "campaignId1", "messageId1", "sdkMessageId2", 2L));
add(new EventReport(EventType.dwell, "myAreaId3", "campaignId2", "messageId2", "sdkMessageId3", 3L));
}
};
Set<MessagePayload> messages = new HashSet<MessagePayload>() {
{
add(new MessagePayload("messageId1", null, null, null, null, null, null, null, null));
add(new MessagePayload("messageId2", null, null, null, null, null, null, null, null));
}
};
debugServer.respondWith(NanoHTTPD.Response.Status.OK, jsonResponse);
EventReportResponse response = mobileApiGeo.report(new EventReportBody(messages, events, "SomeDeviceInstanceId"));
// inspect http context
assertThat(debugServer.getUri()).isEqualTo("/mobile/4/geo/event");
assertThat(debugServer.getRequestCount()).isEqualTo(1);
assertThat(debugServer.getRequestMethod()).isEqualTo(NanoHTTPD.Method.POST);
assertThat(debugServer.getQueryParametersCount()).isEqualTo(0);
assertThat(response.getFinishedCampaignIds().size()).isEqualTo(3);
assertThat(response.getFinishedCampaignIds()).contains("id1");
assertThat(response.getFinishedCampaignIds()).contains("id2");
assertThat(response.getFinishedCampaignIds()).contains("id3");
assertThat(response.getSuspendedCampaignIds().size()).isEqualTo(3);
assertThat(response.getSuspendedCampaignIds()).contains("id4");
assertThat(response.getSuspendedCampaignIds()).contains("id5");
assertThat(response.getSuspendedCampaignIds()).contains("id6");
assertThat(response.getMessageIds().get("messageId1")).isEqualTo("newMessageId1");
assertThat(response.getMessageIds().get("messageId2")).isEqualTo("newMessageId2");
assertThat(response.getMessageIds().get("messageId3")).isEqualTo("newMessageId3");
JSONAssert.assertEquals(debugServer.getBody(), "{" + "\"platformType\":\"GCM\"," + "\"deviceApplicationInstanceId\":\"SomeDeviceInstanceId\"," + "\"messages\": [" + "{\n" + " \"messageId\": \"messageId1\",\n" + " \"title\": null,\n" + " \"body\": null,\n" + " \"sound\": null,\n" + " \"vibrate\": null,\n" + " \"category\": null,\n" + " \"silent\": null,\n" + " \"customPayload\": null,\n" + " \"internalData\": null\n" + " },\n" + " {\n" + " \"messageId\": \"messageId2\",\n" + " \"title\": null,\n" + " \"body\": null,\n" + " \"sound\": null,\n" + " \"vibrate\": null,\n" + " \"category\": null,\n" + " \"silent\": null,\n" + " \"customPayload\": null,\n" + " \"internalData\": null\n" + " }" + "]," + "\"reports\": [" + "{" + "\"event\":\"entry\"," + "\"geoAreaId\":\"myAreaId1\"," + "\"campaignId\":\"campaignId1\"," + "\"messageId\":\"messageId1\"," + "\"sdkMessageId\":\"sdkMessageId1\"," + "\"timestampDelta\":1" + "}," + "{" + "\"event\":\"exit\"," + "\"geoAreaId\":\"myAreaId2\"," + "\"campaignId\":\"campaignId1\"," + "\"messageId\":\"messageId1\"," + "\"sdkMessageId\":\"sdkMessageId2\"," + "\"timestampDelta\":2" + "}," + "{" + "\"event\":\"dwell\"," + "\"geoAreaId\":\"myAreaId3\"," + "\"campaignId\":\"campaignId2\"," + "\"messageId\":\"messageId2\"," + "\"sdkMessageId\":\"sdkMessageId3\"," + "\"timestampDelta\":3" + "}" + "]" + "}", JSONCompareMode.LENIENT);
}
use of org.infobip.mobile.messaging.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method test_shouldReportSeenForMessageIdsIfNoCorrespondingGeoReport.
@Test
public void test_shouldReportSeenForMessageIdsIfNoCorrespondingGeoReport() throws InterruptedException {
// Given
createMessage(context, "generatedMessageId1", true);
createReport(context, "signalingMessageId1", "campaignId1", "generatedMessageId2", true);
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).atLeastOnce()).seenStatusReported(any(String[].class));
}
use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Enable message store for notification messages
enableMessageStoreForReceivedMessages();
messageStore = MobileMessaging.getInstance(context).getMessageStore();
mobileApiGeo = mock(MobileApiGeo.class);
geoReporter = new GeoReporter(context, mobileMessagingCore, geoBroadcaster, mobileMessagingCore.getStats(), mobileApiGeo);
geoReportCaptor = new ArgumentCaptor<>();
reportBodyCaptor = ArgumentCaptor.forClass(EventReportBody.class);
given(mobileApiGeo.report(reportBodyCaptor.capture())).willReturn(new EventReportResponse());
}
use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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));
}
Aggregations