Search in sources :

Example 6 with GeoReportingResult

use of org.infobip.mobile.messaging.geo.report.GeoReportingResult 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 7 with GeoReportingResult

use of org.infobip.mobile.messaging.geo.report.GeoReportingResult 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));
    }
}
Also used : GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) List(java.util.List) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult)

Example 8 with GeoReportingResult

use of org.infobip.mobile.messaging.geo.report.GeoReportingResult 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)

Example 9 with GeoReportingResult

use of org.infobip.mobile.messaging.geo.report.GeoReportingResult 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());
}
Also used : Context(android.content.Context) GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

Example 10 with GeoReportingResult

use of org.infobip.mobile.messaging.geo.report.GeoReportingResult in project mobile-messaging-sdk-android by infobip.

the class GeoAreasHandlerTests method test_should_save_messages_with_generated_ids_if_report_unsuccessful.

@Test
public void test_should_save_messages_with_generated_ids_if_report_unsuccessful() {
    // 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
    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());
}
Also used : Context(android.content.Context) Message(org.infobip.mobile.messaging.Message) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) Test(org.junit.Test)

Aggregations

GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)12 Test (org.junit.Test)11 Message (org.infobip.mobile.messaging.Message)10 Context (android.content.Context)7 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 HashMap (java.util.HashMap)4 Map (java.util.Map)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 List (java.util.List)1