Search in sources :

Example 1 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_with_generated_ids_if_report_unsuccessful.

@Test
public void test_should_notify_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
    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();
    assertNotSame("SomeSignalingMessageId", message.getMessageId());
    assertTrue(StringUtils.isNotBlank(message.getMessageId()));
    Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
    assertNotNull(geo);
    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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 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_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 3 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_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 4 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_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 5 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_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

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