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);
}
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());
}
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());
}
Aggregations