Search in sources :

Example 6 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_not_throw_exception_if_reporting_fails.

@Test
public void test_should_not_throw_exception_if_reporting_fails() {
    // Given
    GeoTransition transition = GeoHelper.createTransition("areaId1");
    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)));
    Mockito.when(geoReporter.reportSync(Mockito.any(GeoReport[].class))).thenThrow(new RuntimeException("Hola!"));
    // When
    geoAreasHandler.handleTransition(transition);
}
Also used : Context(android.content.Context) GeoTransition(org.infobip.mobile.messaging.geo.transition.GeoTransition) Test(org.junit.Test)

Example 7 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_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 8 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_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

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