use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class InternalDataMapperTest method should_not_produce_npe_when_silent_but_vibrate_is_not_set.
@Test
public void should_not_produce_npe_when_silent_but_vibrate_is_not_set() {
// Given
String givenInternalData = "{ \"silent\": { } }";
Message givenMessage = new Message();
// When
InternalDataMapper.updateMessageWithInternalData(givenMessage, givenInternalData);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MessageBundleMapperTest method test_shouldSerializeAndDeserializeCustomPayloadWithNestedObjects.
public void test_shouldSerializeAndDeserializeCustomPayloadWithNestedObjects() throws Exception {
// Given (some crazy json)
Message givenMessage = new Message();
givenMessage.setCustomPayload(new JSONObject().put("level1_1", new JSONObject().put("level2_1", new JSONObject().put("level3", "someData")).put("level2_2", new JSONObject().put("level3", "someData"))).put("level1_2", new JSONObject().put("level2", new JSONObject().put("level3", "someData"))).put("level1_3", new JSONArray().put(new JSONArray().put(new JSONObject().put("level3", "someData")))));
// When
Message actualMessage = MessageBundleMapper.messageFromBundle(MessageBundleMapper.messageToBundle(givenMessage));
// Then
JSONAssert.assertEquals(givenMessage.getCustomPayload(), actualMessage.getCustomPayload(), true);
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class SqliteMessageMigrationTest method test_shouldAddSendDateTimeToInternalData.
@Test
public void test_shouldAddSendDateTimeToInternalData() throws Exception {
// Create SQLiteOpenHelper directly to perform raw operations on database
context.deleteDatabase(DatabaseHelperImpl.DATABASE_NAME);
SQLiteOpenHelper sqLiteOpenHelper = new SQLiteOpenHelper(context, DatabaseHelperImpl.DATABASE_NAME, null, DatabaseHelperImpl.VER_2017_MAY_15) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_MAY_MESSAGES_TABLE);
db.execSQL(SQL_CREATE_GEO_MESSAGES_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
};
SQLiteDatabase db = sqLiteOpenHelper.getWritableDatabase();
// Save new data to database
ContentValues contentValues = new ContentValues();
contentValues.put("id", "SomeMessageId");
contentValues.put("title", "SomeMessageTitle");
contentValues.put("body", "SomeMessageBody");
contentValues.put("sound", "SomeMessageSound");
contentValues.put("vibrate", 1);
contentValues.put("icon", "SomeMessageIcon");
contentValues.put("silent", 1);
contentValues.put("category", "SomeMessageCategory");
contentValues.put("_from", "SomeMessageFrom");
contentValues.put("received_timestamp", 1234L);
contentValues.put("seen_timestamp", 5678L);
contentValues.put("internal_data", "{\"key1\":\"value1\"}");
contentValues.put("custom_payload", "{\"key2\":\"value2\"}");
contentValues.put("destination", "SomeMessageDestination");
contentValues.put("status", "ERROR");
contentValues.put("status_message", "SomeMessageStatusMessage");
contentValues.put("content_url", "SomeMessageContentUrl");
db.insertWithOnConflict(DatabaseContract.Tables.MESSAGES, null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
db.close();
sqLiteOpenHelper.close();
// Check that sent timestamp was added and other fields are the same
SQLiteMessageStore messageStore = new SQLiteMessageStore();
List<Message> messages = messageStore.findAll(context);
assertEquals(1, messages.size());
assertEquals("SomeMessageId", messages.get(0).getMessageId());
assertEquals("SomeMessageTitle", messages.get(0).getTitle());
assertEquals("SomeMessageBody", messages.get(0).getBody());
assertEquals("SomeMessageSound", messages.get(0).getSound());
assertEquals(true, messages.get(0).isVibrate());
assertEquals("SomeMessageIcon", messages.get(0).getIcon());
assertEquals(true, messages.get(0).isSilent());
assertEquals("SomeMessageCategory", messages.get(0).getCategory());
assertEquals("SomeMessageFrom", messages.get(0).getFrom());
assertEquals(1234L, messages.get(0).getReceivedTimestamp());
assertEquals(5678L, messages.get(0).getSeenTimestamp());
assertEquals(1234L, messages.get(0).getSentTimestamp());
JSONAssert.assertEquals("{\"key1\" : \"value1\", \"sendDateTime\":1234}", messages.get(0).getInternalData(), true);
JSONAssert.assertEquals("{\"key2\" : \"value2\"}", messages.get(0).getCustomPayload(), true);
assertEquals("SomeMessageDestination", messages.get(0).getDestination());
assertEquals(Message.Status.ERROR, messages.get(0).getStatus());
assertEquals("SomeMessageStatusMessage", messages.get(0).getStatusMessage());
assertEquals("SomeMessageContentUrl", messages.get(0).getContentUrl());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class MessagesSynchronizerTest method should_deserialize_messages_with_appropriate_vibration_from_fetched_payload.
@Test
public void should_deserialize_messages_with_appropriate_vibration_from_fetched_payload() {
// Given
mobileMessagingCore.getAndRemoveUnreportedMessageIds();
given(mobileApiMessages.sync(any(SyncMessagesBody.class))).willReturn(new SyncMessagesResponse(asList(new MessageResponse() {
{
setMessageId("someMessageId1");
setBody("someBody1");
}
}, new MessageResponse() {
{
setMessageId("someMessageId2");
setBody("someBody2");
setVibrate("true");
}
}, new MessageResponse() {
{
setMessageId("someMessageId3");
setBody("someBody3");
setVibrate("false");
}
})));
// When
messagesSynchronizer.sync();
// Then
verify(mobileMessageHandler, after(1000).times(3)).handleMessage(messageArgumentCaptor.capture());
List<Message> actualMessages = messageArgumentCaptor.getAllValues();
assertEquals("someMessageId1", actualMessages.get(0).getMessageId());
assertEquals("someBody1", actualMessages.get(0).getBody());
assertEquals(true, actualMessages.get(0).isVibrate());
assertEquals("someMessageId2", actualMessages.get(1).getMessageId());
assertEquals("someBody2", actualMessages.get(1).getBody());
assertEquals(true, actualMessages.get(1).isVibrate());
assertEquals("someMessageId3", actualMessages.get(2).getMessageId());
assertEquals("someBody3", actualMessages.get(2).getBody());
assertEquals(false, actualMessages.get(2).isVibrate());
}
use of org.infobip.mobile.messaging.Message in project mobile-messaging-sdk-android by infobip.
the class CoreNotificationHandlerTest method shouldNotProduceNPE_whenMessageArrivesAndNotificationsDisabled.
@Test
public void shouldNotProduceNPE_whenMessageArrivesAndNotificationsDisabled() {
// Given
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.DISPLAY_NOTIFICATION_ENABLED, false);
Message givenMessage = createMessage(context, "SomeMessageId", false);
// When
coreNotificationHandler.displayNotification(givenMessage);
// Then
Mockito.verify(notificationManagerMock, Mockito.never()).notify(Mockito.anyInt(), Mockito.any(Notification.class));
}
Aggregations