Search in sources :

Example 71 with Message

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());
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 72 with Message

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;
}
Also used : Message(org.infobip.mobile.messaging.Message) JsonSerializer(org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer)

Example 73 with 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());
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) GeoMessage(org.infobip.mobile.messaging.geo.GeoMessage) GeoMessage(org.infobip.mobile.messaging.geo.GeoMessage) Message(org.infobip.mobile.messaging.Message) GeoEventSettings(org.infobip.mobile.messaging.geo.GeoEventSettings) Intent(android.content.Intent) Test(org.junit.Test)

Example 74 with Message

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());
}
Also used : MobileApiGeo(org.infobip.mobile.messaging.api.geo.MobileApiGeo) EventReportResponse(org.infobip.mobile.messaging.api.geo.EventReportResponse) Message(org.infobip.mobile.messaging.Message) HashMap(java.util.HashMap) EventReportBody(org.infobip.mobile.messaging.api.geo.EventReportBody) Test(org.junit.Test)

Example 75 with Message

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);
    }
}
Also used : Message(org.infobip.mobile.messaging.Message) JSONObject(org.json.JSONObject)

Aggregations

Message (org.infobip.mobile.messaging.Message)87 Test (org.junit.Test)44 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 GeoReportingResult (org.infobip.mobile.messaging.geo.report.GeoReportingResult)10 Context (android.content.Context)7 GeoReport (org.infobip.mobile.messaging.geo.report.GeoReport)7 GeoTransition (org.infobip.mobile.messaging.geo.transition.GeoTransition)7 JSONObject (org.json.JSONObject)7 List (java.util.List)6 EventReportResponse (org.infobip.mobile.messaging.api.geo.EventReportResponse)6 Geo (org.infobip.mobile.messaging.geo.Geo)6 Map (java.util.Map)5 MoMessage (org.infobip.mobile.messaging.api.messages.MoMessage)5 Area (org.infobip.mobile.messaging.geo.Area)5 NotificationAction (org.infobip.mobile.messaging.interactive.NotificationAction)5 NotificationCategory (org.infobip.mobile.messaging.interactive.NotificationCategory)5 Date (java.util.Date)4