Search in sources :

Example 6 with EventReportResponse

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));
}
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 7 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_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 8 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_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());
}
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) Test(org.junit.Test)

Example 9 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_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)

Example 10 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_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());
}
Also used : EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) GeoReport(org.infobip.mobile.messaging.geo.report.GeoReport) Message(org.infobip.mobile.messaging.Message) GeoReportingResult(org.infobip.mobile.messaging.geo.report.GeoReportingResult) 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