use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MobileMessageHandlerTest method test_shouldNotSaveGeoMessagesToMessageStore.
@Test
public void test_shouldNotSaveGeoMessagesToMessageStore() throws Exception {
// Given
Message message1 = createMessage(context, "SomeMessageId1", null, false);
Message message2 = createMessage(context, "SomeMessageId2", "SomeCampaignId2", false, createArea("SomeAreaId1"));
// When
mobileMessageHandler.handleMessage(message1);
mobileMessageHandler.handleMessage(message2);
// Then
List<Message> messages = commonStore.findAll(context);
assertEquals(1, messages.size());
Message message = messages.get(0);
assertEquals("SomeMessageId1", message.getMessageId());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MobileMessagingTestCase method createMessage.
/**
* Generates messages with provided ids and geo campaign object
*
* @param saveToStorage set to true to save messages to message store
* @param messageId message id for a message
* @param geo geo campaign object
* @return new message
*/
protected static Message createMessage(Context context, String messageId, boolean saveToStorage, Geo... geo) {
Message message = new Message();
message.setMessageId(messageId);
message.setSentTimestamp(0);
boolean isGeo = geo.length > 0 && geo[0] != null && geo[0].getAreasList() != null && !geo[0].getAreasList().isEmpty();
if (isGeo) {
JsonSerializer serializer = new JsonSerializer();
message.setInternalData(GeoDataMapper.geoToInternalData(geo[0]));
message.setContentUrl(InternalDataMapper.getInternalDataContentUrl(serializer.serialize(geo[0])));
}
if (saveToStorage) {
geoStore.save(context, message);
}
return message;
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class AndroidGeoBroadcasterTest method test_should_send_geo_event.
@Test
public void test_should_send_geo_event() {
// Given
Geo geo = new Geo(0.0, 0.0, null, null, null, "SomeCampaignId", Collections.singletonList(createArea("areaId1")), new ArrayList<GeoEventSettings>(), 0, null);
Message message = createMessage(context, "SomeMessageId", false, geo);
// When
broadcastSender.geoEvent(GeoEventType.entry, GeoMessage.createFrom(message, geo));
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(GeoEvent.GEOFENCE_AREA_ENTERED.getKey(), intent.getAction());
GeoMessage geoMessage = GeoMessage.createFrom(intent.getExtras());
assertNotSame(message, geoMessage);
assertEquals("SomeMessageId", geoMessage.getMessageId());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class GeoReporterTest method test_shouldUpdateMessageIdsOnSuccessfulReport.
@Test
public void test_shouldUpdateMessageIdsOnSuccessfulReport() throws Exception {
// Given
Area area1 = createArea("areaId1");
Area area2 = createArea("areaId2");
Area area3 = createArea("areaId3");
createMessage(context, "signalingMessageId1", "campaignId1", true, area1, area2);
createMessage(context, "signalingMessageId2", "campaignId2", true, area3);
createReport(context, "signalingMessageId1", "campaignId1", "messageId1", true, area1);
createReport(context, "signalingMessageId1", "campaignId1", "messageId2", true, area2);
createReport(context, "signalingMessageId2", "campaignId2", "messageId3", true, area3);
messageStore.save(context, createMessage(context, "messageId1", "campaignId1", false, area1), createMessage(context, "messageId2", "campaignId1", false, area2), createMessage(context, "messageId3", "campaignId2", false, area3));
given(mobileApiGeo.report(any(EventReportBody.class))).willReturn(new EventReportResponse() {
{
setMessageIds(new HashMap<String, String>() {
{
put("messageId1", "ipCoreMessageId1");
put("messageId2", "ipCoreMessageId2");
put("messageId3", "ipCoreMessageId3");
}
});
}
});
// When
geoReporter.synchronize();
// Then
// Wait for reporting to complete
Mockito.verify(geoBroadcaster, Mockito.after(1000).atLeastOnce()).geoReported(geoReportCaptor.capture());
// Examine message store
List<Message> messageList = messageStore.findAll(context);
assertEquals(3, messageList.size());
Map<String, Message> messageMap = new HashMap<>();
for (Message m : messageList) messageMap.put(m.getMessageId(), m);
assertTrue(messageMap.containsKey("ipCoreMessageId1"));
Message m1 = messageMap.get("ipCoreMessageId1");
Geo geo1 = GeoDataMapper.geoFromInternalData(m1.getInternalData());
assertNotNull(geo1);
assertEquals("campaignId1", geo1.getCampaignId());
assertEquals("areaId1", geo1.getAreasList().get(0).getId());
Message m2 = messageMap.get("ipCoreMessageId2");
Geo geo2 = GeoDataMapper.geoFromInternalData(m2.getInternalData());
assertTrue(messageMap.containsKey("ipCoreMessageId2"));
assertNotNull(geo2);
assertEquals("campaignId1", geo2.getCampaignId());
assertEquals("areaId2", geo2.getAreasList().get(0).getId());
Message m3 = messageMap.get("ipCoreMessageId3");
Geo geo3 = GeoDataMapper.geoFromInternalData(m3.getInternalData());
assertNotNull(geo3);
assertTrue(messageMap.containsKey("ipCoreMessageId3"));
assertEquals("campaignId2", geo3.getCampaignId());
assertEquals("areaId3", geo3.getAreasList().get(0).getId());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class WebContentReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Message message = Message.createFrom(intent.getExtras());
JSONObject customPayload = message.getCustomPayload();
String url = customPayload != null ? customPayload.optString("url") : "";
if (!url.isEmpty()) {
openWebView(context, url);
}
}
Aggregations