use of org.infobip.mobile.messaging.Message 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());
}
use of org.infobip.mobile.messaging.Message 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());
}
use of org.infobip.mobile.messaging.Message 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());
}
use of org.infobip.mobile.messaging.Message 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());
}
use of org.infobip.mobile.messaging.Message 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());
}
Aggregations