Search in sources :

Example 1 with GeoTransition

use of org.infobip.mobile.messaging.geo.transition.GeoTransition 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 GeoTransition

use of org.infobip.mobile.messaging.geo.transition.GeoTransition 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 GeoTransition

use of org.infobip.mobile.messaging.geo.transition.GeoTransition 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 GeoTransition

use of org.infobip.mobile.messaging.geo.transition.GeoTransition 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 GeoTransition

use of org.infobip.mobile.messaging.geo.transition.GeoTransition 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

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