Search in sources :

Example 11 with EventReportResponse

use of org.infobip.mobile.messaging.api.geo.EventReportResponse 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"));
}
Also used : EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

Example 12 with EventReportResponse

use of org.infobip.mobile.messaging.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.

the class GeoReporter method reportSync.

/**
 * Reports geo events synchronously
 *
 * @param geoReports set that contains original messages and corresponding events
 * @return result that will contain lists of campaign ids and mappings between library generated message ids and IPCore ids
 */
@NonNull
public GeoReportingResult reportSync(@NonNull GeoReport[] geoReports) {
    EventReportBody eventReportBody = prepareEventReportBody(context, geofenceHelper.getMessageStoreForGeo(), geoReports);
    MobileMessagingLogger.v("GEO REPORT >>>", eventReportBody);
    EventReportResponse eventResponse = mobileApiGeo.report(eventReportBody);
    MobileMessagingLogger.v("GEO REPORT <<<", eventResponse);
    GeoReportingResult result = new GeoReportingResult(eventResponse);
    handleSuccess(context, geoReports, result);
    return result;
}
Also used : EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) EventReportBody(org.infobip.mobile.messaging.api.geo.EventReportBody) NonNull(android.support.annotation.NonNull)

Example 13 with EventReportResponse

use of org.infobip.mobile.messaging.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.

the class GeoReporterTest method test_shouldReportSeenAfterGeoSuccessfullyReported.

@Test
public void test_shouldReportSeenAfterGeoSuccessfullyReported() throws InterruptedException {
    // Given
    createMessage(context, "signalingMessageId1", "campaignId1", true);
    createMessage(context, "generatedMessageId1", "campaignId1", true);
    createReport(context, "signalingMessageId1", "campaignId1", "generatedMessageId1", true);
    PreferenceHelper.saveLong(context, MobileMessagingProperty.BATCH_REPORTING_DELAY, 10L);
    given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse());
    // When
    mobileMessaging.setMessagesSeen("generatedMessageId1");
    geoReporter.synchronize();
    // Then
    Mockito.verify(coreBroadcaster, Mockito.after(1000).atLeastOnce()).seenStatusReported(any(String[].class));
}
Also used : EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) EventReportBody(org.infobip.mobile.messaging.api.geo.EventReportBody) Test(org.junit.Test)

Example 14 with EventReportResponse

use of org.infobip.mobile.messaging.api.geo.EventReportResponse in project mobile-messaging-sdk-android by infobip.

the class GeoReporterTest method test_shouldUpdateMessageIdsOnSuccessfulReport.

@Test
public void test_shouldUpdateMessageIdsOnSuccessfulReport() 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", "campaignId2", true, area3);
    createReport(context, "signalingMessageId1", "campaignId1", "messageId1", true, area1);
    createReport(context, "signalingMessageId1", "campaignId1", "messageId2", true, area2);
    createReport(context, "signalingMessageId2", "campaignId2", "messageId3", true, area3);
    messageStore.save(context, createMessage(context, "messageId1", "campaignId1", false, area1), createMessage(context, "messageId2", "campaignId1", false, area2), createMessage(context, "messageId3", "campaignId2", false, area3));
    given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse() {

        {
            setMessageIds(new HashMap<String, String>() {

                {
                    put("messageId1", "ipCoreMessageId1");
                    put("messageId2", "ipCoreMessageId2");
                    put("messageId3", "ipCoreMessageId3");
                }
            });
        }
    });
    // When
    geoReporter.synchronize();
    // Then
    // Wait for reporting to complete
    Mockito.verify(geoBroadcaster, Mockito.after(1000).atLeastOnce()).geoReported(geoReportCaptor.capture());
    // Examine message store
    List<Message> messageList = messageStore.findAll(context);
    assertEquals(3, messageList.size());
    Map<String, Message> messageMap = new HashMap<>();
    for (Message m : messageList) messageMap.put(m.getMessageId(), m);
    assertTrue(messageMap.containsKey("ipCoreMessageId1"));
    Message m1 = messageMap.get("ipCoreMessageId1");
    Geo geo1 = GeoDataMapper.geoFromInternalData(m1.getInternalData());
    assertNotNull(geo1);
    assertEquals("campaignId1", geo1.getCampaignId());
    assertEquals("areaId1", geo1.getAreasList().get(0).getId());
    Message m2 = messageMap.get("ipCoreMessageId2");
    Geo geo2 = GeoDataMapper.geoFromInternalData(m2.getInternalData());
    assertTrue(messageMap.containsKey("ipCoreMessageId2"));
    assertNotNull(geo2);
    assertEquals("campaignId1", geo2.getCampaignId());
    assertEquals("areaId2", geo2.getAreasList().get(0).getId());
    Message m3 = messageMap.get("ipCoreMessageId3");
    Geo geo3 = GeoDataMapper.geoFromInternalData(m3.getInternalData());
    assertNotNull(geo3);
    assertTrue(messageMap.containsKey("ipCoreMessageId3"));
    assertEquals("campaignId2", geo3.getCampaignId());
    assertEquals("areaId3", geo3.getAreasList().get(0).getId());
}
Also used : MobileApiGeo(org.infobip.mobile.messaging.api.geo.MobileApiGeo) EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap) EventReportBody(org.infobip.mobile.messaging.api.geo.EventReportBody) Test(org.junit.Test)

Example 15 with EventReportResponse

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_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());
}
Also used : Context(android.content.Context) EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)16 Test (org.junit.Test)13 EventReportBody (org.infobip.mobile.messaging.api.geo.EventReportBody)9 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)7 Message (org.infobip.mobile.messaging.Message)6 Context (android.content.Context)4 HashMap (java.util.HashMap)4 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)4 Map (java.util.Map)2 MobileApiGeo (org.infobip.mobile.messaging.api.geo.MobileApiGeo)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NonNull (android.support.annotation.NonNull)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 EventReport (org.infobip.mobile.messaging.api.geo.EventReport)1 MessagePayload (org.infobip.mobile.messaging.api.geo.MessagePayload)1 GeoReporter (org.infobip.mobile.messaging.geo.report.GeoReporter)1