Search in sources :

Example 11 with Message

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

the class AndroidBroadcasterTest method test_should_set_package_for_intent.

@Test
public void test_should_set_package_for_intent() throws Exception {
    // Given
    Message message = createMessage(context, "SomeMessageId", false);
    Mockito.when(contextMock.getPackageName()).thenReturn("test.package.name");
    // When
    broadcastSender.messageReceived(message);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    assertEquals("test.package.name", intentArgumentCaptor.getValue().getPackage());
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 12 with Message

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

the class SharedPreferencesMigrationTest method test_shouldMigrateAllMessagesToSqlite.

@Test
public void test_shouldMigrateAllMessagesToSqlite() throws Exception {
    UUID uuid = UUID.randomUUID();
    int numberOfMessages = 100;
    JsonObject attachment = new JsonObject();
    attachment.addProperty("url", "http://www.some-content.com.ru.hr");
    JsonArray attachments = new JsonArray();
    attachments.add(attachment);
    JsonObject internalData = new JsonObject();
    internalData.add("atts", attachments);
    internalData.add("silent", new JsonObject());
    for (int i = 0; i < numberOfMessages; i++) {
        sharedPreferencesMessageStore.save(context, new Message(i + uuid.toString(), "SomeTitle" + i, "SomeBody" + i, "SomeSound" + i, true, "SomeIcon" + i, false, "SomeCategory" + i, "SomeFrom" + i, 0, 0, 0, null, internalData.toString(), "SomeDestination" + i, Message.Status.SUCCESS, "SomeStatusMessage" + i, "http://www.some-content.com.ru.hr"));
    }
    MessageStore store = new SQLiteMessageStore();
    List<Message> messages = store.findAll(context);
    HashMap<String, Message> map = new HashMap<>();
    for (Message m : messages) map.put(m.getMessageId(), m);
    // we are not removing messages from shared prefs
    // in case user still uses SharedPreferencesMessageStore
    Assert.assertEquals(numberOfMessages, sharedPreferencesMessageStore.findAll(context).size());
    Assert.assertEquals(numberOfMessages, map.size());
    for (int i = 0; i < numberOfMessages; i++) {
        String id = i + uuid.toString();
        Assert.assertEquals(id, map.get(id).getMessageId());
        Assert.assertEquals("SomeTitle" + i, map.get(id).getTitle());
        Assert.assertEquals("SomeBody" + i, map.get(id).getBody());
        Assert.assertEquals("SomeSound" + i, map.get(id).getSound());
        Assert.assertEquals(true, map.get(id).isVibrate());
        Assert.assertEquals("SomeIcon" + i, map.get(id).getIcon());
        Assert.assertEquals(false, map.get(id).isSilent());
        Assert.assertEquals("SomeCategory" + i, map.get(id).getCategory());
        Assert.assertEquals("SomeFrom" + i, map.get(id).getFrom());
        Assert.assertEquals(0, map.get(id).getReceivedTimestamp());
        Assert.assertEquals(0, map.get(id).getSeenTimestamp());
        Assert.assertEquals(null, map.get(id).getCustomPayload());
        JSONAssert.assertEquals(internalData.toString(), map.get(id).getInternalData(), false);
        Assert.assertEquals("SomeDestination" + i, map.get(id).getDestination());
        Assert.assertEquals(Message.Status.SUCCESS, map.get(id).getStatus());
        Assert.assertEquals("SomeStatusMessage" + i, map.get(id).getStatusMessage());
        Assert.assertEquals("http://www.some-content.com.ru.hr", map.get(id).getContentUrl());
    }
}
Also used : JsonArray(org.infobip.mobile.messaging.api.shaded.google.gson.JsonArray) SharedPreferencesMessageStore(org.infobip.mobile.messaging.storage.SharedPreferencesMessageStore) MessageStore(org.infobip.mobile.messaging.storage.MessageStore) SQLiteMessageStore(org.infobip.mobile.messaging.storage.SQLiteMessageStore) Message(org.infobip.mobile.messaging.Message) SQLiteMessageStore(org.infobip.mobile.messaging.storage.SQLiteMessageStore) HashMap(java.util.HashMap) JsonObject(org.infobip.mobile.messaging.api.shaded.google.gson.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with Message

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

the class MobileMessageHandlerTest method test_shouldSend_messageReceived_forNonGeoMessage.

@Test
public void test_shouldSend_messageReceived_forNonGeoMessage() throws Exception {
    // Given
    Message m = createMessage(context, "SomeMessageId", false);
    // When
    handler.handleMessage(m);
    // Then
    Mockito.verify(broadcaster, Mockito.after(1000).atLeastOnce()).messageReceived(Mockito.any(Message.class));
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 14 with Message

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

the class MobileMessageHandlerTest method test_shouldSaveNonGeoMessageToUserStore.

@Test
public void test_shouldSaveNonGeoMessageToUserStore() throws Exception {
    // Given
    Message m = createMessage(context, "SomeMessageId", false);
    // When
    handler.handleMessage(m);
    // Then
    List<Message> messages = commonStore.findAll(context);
    assertEquals(1, messages.size());
    assertEquals("SomeMessageId", messages.get(0).getMessageId());
}
Also used : Message(org.infobip.mobile.messaging.Message) Test(org.junit.Test)

Example 15 with Message

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

the class NotificationTapReceiverTest method test_should_send_seen_report_message_ids.

@Test
public void test_should_send_seen_report_message_ids() {
    // Given
    Message givenMessage = createMessage(context, "SomeMessageId", false);
    Intent givenIntent = givenIntent(givenMessage, notificationSettings.getIntentFlags());
    // When
    notificationTapReceiver.onReceive(contextMock, givenIntent);
    // Then
    Mockito.verify(mobileMessagingCore, Mockito.times(1)).setMessagesSeen(givenMessage.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