Search in sources :

Example 1 with GeoReport

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

Example 2 with GeoReport

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

Example 3 with GeoReport

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));
}
Also used : EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) ArrayList(java.util.ArrayList) List(java.util.List) EventReportBody(org.infobip.mobile.messaging.api.geo.EventReportBody)

Example 4 with GeoReport

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

Example 5 with GeoReport

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

Aggregations

GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)13 Test (org.junit.Test)11 Message (org.infobip.mobile.messaging.Message)7 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)7 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)7 EventReportBody (org.infobip.mobile.messaging.api.geo.EventReportBody)4 Context (android.content.Context)3 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Intent (android.content.Intent)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 EventReport (org.infobip.mobile.messaging.api.geo.EventReport)1 MessagePayload (org.infobip.mobile.messaging.api.geo.MessagePayload)1