Search in sources :

Example 6 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class FCMMessageMapperTest method test_silentMessage_fromJson_withoutSilentData.

public void test_silentMessage_fromJson_withoutSilentData() throws Exception {
    Bundle bundle = new Bundle();
    bundle.putString("gcm.notification.e", "1");
    bundle.putString("gcm.notification.messageId", "L+auqUQFlo1yqk2TEakxua/4rc6DmGgm7cM6G0GRQjU=");
    bundle.putString("android.support.content.wakelockid", "11");
    bundle.putString("collapse_key", "org.infobip.mobile.messaging.showcase.dev");
    bundle.putString("gcm.notification.silent", "true");
    bundle.putString("gcm.notification.title", "notSilentTitle");
    bundle.putString("gcm.notification.body", "notSilentBody");
    bundle.putString("gcm.notification.sound", "notSilentSound");
    Message message = FCMMessageMapper.fromCloudBundle(bundle);
    assertNotEquals("notSilentTitle", message.getTitle());
    assertNotEquals("notSilentBody", message.getBody());
    assertNotEquals("notSilentSound", message.getSound());
}
Also used : Message(org.infobip.mobile.messaging.Message) Bundle(android.os.Bundle)

Example 7 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class SqliteMessageTest method test_message_shouldNotSaveMessageWithNullId.

@Test
public void test_message_shouldNotSaveMessageWithNullId() throws Exception {
    Message message = new Message();
    message.setMessageId(null);
    try {
        databaseHelper.save(new SqliteMessage(message));
        fail();
    } catch (SQLiteConstraintException ignored) {
    }
}
Also used : Message(org.infobip.mobile.messaging.Message) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Test(org.junit.Test)

Example 8 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class MoMessageSenderTest method shouldOnlySaveNonRetriableMessagesToStore.

@Test
public void shouldOnlySaveNonRetriableMessagesToStore() {
    // Given
    MobileMessagingCore.setMessageStoreClass(context, SQLiteMessageStore.class);
    Message givenMessage1 = givenMessage("someMessageId1");
    Message givenMessage2 = givenMessage("someMessageId2");
    final MoMessageDelivery givenDelivery1 = givenDelivery(givenMessage1.getMessageId());
    final MoMessageDelivery givenDelivery2 = givenDelivery(givenMessage2.getMessageId());
    given(apiMock.sendMO(any(MoMessagesBody.class))).willReturn(new MoMessagesResponse(new MoMessageDelivery[] { givenDelivery1 })).willReturn(new MoMessagesResponse(new MoMessageDelivery[] { givenDelivery2 }));
    // When
    moMessageSender.send(null, givenMessage1);
    moMessageSender.sendWithRetry(givenMessage2);
    // Then
    verify(apiMock, after(200).atLeast(1)).sendMO(any(MoMessagesBody.class));
    verify(messageStoreWrapperMock, times(1)).upsert(messageCaptor.capture());
    List<Message> storedMessages = getAllMessages(messageCaptor.getAllValues());
    assertEquals(1, storedMessages.size());
    assertEquals(givenMessage1.getMessageId(), storedMessages.get(0).getMessageId());
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) MoMessageDelivery(org.infobip.mobile.messaging.api.messages.MoMessageDelivery) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessagesResponse(org.infobip.mobile.messaging.api.messages.MoMessagesResponse) Test(org.junit.Test)

Example 9 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class MoMessageSenderTest method shouldSendMultipleMessages.

@Test
public void shouldSendMultipleMessages() throws Exception {
    // Given
    final MoMessageDelivery givenMessage1 = new MoMessageDelivery() {

        {
            setStatus("Message not sent");
            setStatusCode(1);
            setMessageId("myMessageId");
            setDestination("myDestination");
            setText("myText");
            setCustomPayload(new HashMap<String, Object>() {

                {
                    put("myStringKey", "string");
                    put("myBooleanKey", true);
                    put("myNumberKey", 1);
                }
            });
        }
    };
    final MoMessageDelivery givenMessage2 = new MoMessageDelivery() {

        {
            setStatus("Message sent");
            setStatusCode(0);
            setMessageId("myMessageId2");
            setDestination("myDestination2");
            setText("myText2");
            setCustomPayload(new HashMap<String, Object>() {

                {
                    put("myStringKey", "string2");
                    put("myBooleanKey", false);
                    put("myNumberKey", 2);
                }
            });
        }
    };
    MoMessagesResponse givenResponse = new MoMessagesResponse() {

        {
            setMessages(new MoMessageDelivery[] { givenMessage1, givenMessage2 });
        }
    };
    given(apiMock.sendMO(any(MoMessagesBody.class))).willReturn(givenResponse);
    // When
    moMessageSender.send(null, givenMessage(givenMessage1.getMessageId()), givenMessage(givenMessage2.getMessageId()));
    // Then
    verify(broadcaster, after(1000).atLeastOnce()).messagesSent(captor.capture());
    List<Message> messages = captor.getValue();
    assertEquals("myMessageId", messages.get(0).getMessageId());
    assertEquals(Message.Status.ERROR, messages.get(0).getStatus());
    assertEquals("Message not sent", messages.get(0).getStatusMessage());
    assertEquals("myDestination", messages.get(0).getDestination());
    assertEquals("myText", messages.get(0).getBody());
    assertEquals("string", messages.get(0).getCustomPayload().opt("myStringKey"));
    assertEquals(1.0, messages.get(0).getCustomPayload().optDouble("myNumberKey"), 0.01);
    assertEquals(true, messages.get(0).getCustomPayload().opt("myBooleanKey"));
    assertEquals("myMessageId2", messages.get(1).getMessageId());
    assertEquals(Message.Status.SUCCESS, messages.get(1).getStatus());
    assertEquals("Message sent", messages.get(1).getStatusMessage());
    assertEquals("myDestination2", messages.get(1).getDestination());
    assertEquals("myText2", messages.get(1).getBody());
    assertEquals("string2", messages.get(1).getCustomPayload().opt("myStringKey"));
    assertEquals(2.0, messages.get(1).getCustomPayload().optDouble("myNumberKey"), 0.01);
    assertEquals(false, messages.get(1).getCustomPayload().opt("myBooleanKey"));
}
Also used : MoMessage(org.infobip.mobile.messaging.api.messages.MoMessage) Message(org.infobip.mobile.messaging.Message) MoMessageDelivery(org.infobip.mobile.messaging.api.messages.MoMessageDelivery) MoMessagesBody(org.infobip.mobile.messaging.api.messages.MoMessagesBody) MoMessagesResponse(org.infobip.mobile.messaging.api.messages.MoMessagesResponse) Test(org.junit.Test)

Example 10 with Message

use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.

the class AndroidBroadcasterTest method test_should_send_notification_tapped_event.

@Test
public void test_should_send_notification_tapped_event() throws Exception {
    // Given
    Message message = createMessage(context, "SomeMessageId", false);
    // When
    broadcastSender.notificationTapped(message);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(Event.NOTIFICATION_TAPPED.getKey(), intent.getAction());
    Message messageAfter = Message.createFrom(intent.getExtras());
    assertNotSame(message, messageAfter);
    assertEquals("SomeMessageId", messageAfter.getMessageId());
}
Also used : Message(org.infobip.mobile.messaging.Message) Intent(android.content.Intent) Test(org.junit.Test)

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