Search in sources :

Example 11 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method testIfConversationAreSame.

@Test
public void testIfConversationAreSame() {
    populateMessagesFromServer();
    assert threadMessagesList.size() > 0;
    Collections.shuffle(threadMessagesList);
    MessageVO message = threadMessagesList.get(0);
    assert message.getConversation() != null;
    Thread thread = message.getConversation();
    chat.setListener(new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
        }
    });
    RequestMessage repRequest = new RequestMessage.Builder("Message at " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(repRequest, null);
    pauseProcess();
    // Load Server messages
    ArrayList<MessageVO> msgFromServer = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (!history.isCache()) {
                System.out.println("Received Message List Server: " + content);
                msgFromServer.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
    // Load cache
    ArrayList<MessageVO> msgFromCache = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                msgFromCache.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistoryCache, null);
    pauseProcess();
    assert msgFromServer.size() > 0;
    assert msgFromCache.size() > 0;
    assert msgFromCache.size() == msgFromServer.size();
    for (MessageVO msg : msgFromServer) {
        if (msg.getMessage() == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " Conversation: " + msg.getConversation());
        MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getConversation());
        Assert.assertEquals(msg.getConversation() != null, msgInCache.getConversation() != null);
        if (msg.getConversation() != null) {
            Assert.assertEquals(msg.getConversation().getId(), msgInCache.getConversation().getId());
        }
    }
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ArrayList(java.util.ArrayList) ResultHistory(com.fanap.podchat.model.ResultHistory) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Test(org.junit.Test)

Example 12 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method testIfReplyInfoVOsAreTheSame.

@Test
public void testIfReplyInfoVOsAreTheSame() {
    populateMessagesFromServer();
    assert threadMessagesList.size() > 0;
    Collections.shuffle(threadMessagesList);
    MessageVO message = threadMessagesList.get(0);
    assert message.getConversation() != null;
    Thread thread = message.getConversation();
    chat.setListener(new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
        }
    });
    RequestReplyMessage repRequest = new RequestReplyMessage.Builder("Reply to " + message.getMessage(), thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
    chat.replyMessage(repRequest, null);
    pauseProcess();
    // Load Server messages
    ArrayList<MessageVO> msgFromServer = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (!history.isCache()) {
                System.out.println("Received Message List Server: " + content);
                msgFromServer.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
    // Load cache
    ArrayList<MessageVO> msgFromCache = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                msgFromCache.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistoryCache, null);
    pauseProcess();
    assert msgFromServer.size() > 0;
    assert msgFromCache.size() > 0;
    assert msgFromCache.size() == msgFromServer.size();
    for (MessageVO msg : msgFromServer) {
        if (msg.getMessage() == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " RepInfo: " + msg.getReplyInfoVO());
        MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getReplyInfoVO());
        Assert.assertEquals(msg.getReplyInfoVO() != null, msgInCache.getReplyInfoVO() != null);
        if (msg.getReplyInfoVO() != null) {
            Assert.assertEquals(msg.getReplyInfoVO().getMessage(), msgInCache.getReplyInfoVO().getMessage());
            Assert.assertEquals(msg.getReplyInfoVO().getMetadata(), msgInCache.getReplyInfoVO().getMetadata());
            Assert.assertEquals(msg.getReplyInfoVO().getRepliedToMessageTime(), msgInCache.getReplyInfoVO().getRepliedToMessageTime());
            Assert.assertEquals(msg.getReplyInfoVO().getRepliedToMessageNanos(), msgInCache.getReplyInfoVO().getRepliedToMessageNanos());
            Assert.assertEquals(msg.getReplyInfoVO().getSystemMetadata(), msgInCache.getReplyInfoVO().getSystemMetadata());
            if (msg.getReplyInfoVO().getParticipant() != null) {
                Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getName(), msgInCache.getReplyInfoVO().getParticipant().getName());
                Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getContactFirstName(), msgInCache.getReplyInfoVO().getParticipant().getContactFirstName());
                Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getCellphoneNumber(), msgInCache.getReplyInfoVO().getParticipant().getCellphoneNumber());
                Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getAdmin(), msgInCache.getReplyInfoVO().getParticipant().getAdmin());
            }
        }
    }
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) ArrayList(java.util.ArrayList) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Test(org.junit.Test)

Example 13 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class SearchMetadataTest method sendMessageWithMetadataTest.

@Test
@LargeTest
public void sendMessageWithMetadataTest() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    dummyMetadataVO.count = new Random().nextInt();
    dummyMetadataVO.desc = dummyMetadataVO.desc + "" + dummyMetadataVO.count;
    String meta = App.getGson().toJson(dummyMetadataVO);
    RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta).build();
    chat.sendTextMessage(request, null);
    sleep(2000);
    for (int i = 0; i < 16; i++) {
        dummyMetadataVO.count++;
        dummyMetadataVO.desc = String.format("%s%d", dummyMetadataVO.desc, dummyMetadataVO.count);
        String meta2 = App.getGson().toJson(dummyMetadataVO);
        request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta2).build();
        chat.sendTextMessage(request, null);
        sleep(6000);
    }
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> resp.getResult().getMessageVO().getSystemMetadata().equals(meta)));
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> !resp.getResult().getMessageVO().getSystemMetadata().equals("I'm something else!")));
}
Also used : Random(java.util.Random) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 14 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class TextMessagesQueueTest method resendMessageFromWaitingQ.

@Test
public void resendMessageFromWaitingQ() {
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    List<WaitQueueCache> waitList = chat.getWaitingQ();
    WaitQueueCache wToSend = waitList.remove(0);
    chat.resendMessage(wToSend.getUniqueId());
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> result) -> result.getResult().getMessageVO().getUniqueId().equals(wToSend.getUniqueId())));
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatListener(com.fanap.podchat.chat.ChatListener) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) Test(org.junit.Test)

Example 15 with ResultNewMessage

use of com.fanap.podchat.model.ResultNewMessage in project pod-chat-android-sdk by FanapSoft.

the class ThreadCacheTest method sendMessageAndDelete.

public void sendMessageAndDelete() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    Assert.assertNotNull(thread);
    ArrayList<Long> msgIds = new ArrayList<>();
    // send new message
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            msgIds.add(response.getResult().getMessageVO().getId());
            System.out.println("new message sent -> msg : " + content);
            chat.removeListener(chatListeners);
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            resumeProcess();
            System.out.println("Error: " + content);
            Assert.assertEquals(0, 1);
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestMessage request = new RequestMessage.Builder("Message for test delete :" + thread.getId(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    pauseProcess();
    // delete last message
    chatListeners = new ChatListener() {

        @Override
        public void onDeleteMessage(String content, ChatResponse<ResultDeleteMessage> response) {
            resumeProcess();
            System.out.println("Deleted: " + content);
            chat.removeListener(chatListeners);
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            resumeProcess();
            System.out.println("Error: " + content);
            Assert.assertEquals(0, 1);
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestDeleteMessage requestDeleteMessage = new RequestDeleteMessage.Builder().messageIds(msgIds).deleteForAll(true).build();
    presenter.deleteMessage(requestDeleteMessage, null);
    pauseProcess();
}
Also used : RequestDeleteMessage(com.fanap.podchat.requestobject.RequestDeleteMessage) ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage)

Aggregations

ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)17 ChatListener (com.fanap.podchat.chat.ChatListener)10 MessageVO (com.fanap.podchat.mainmodel.MessageVO)8 Thread (com.fanap.podchat.mainmodel.Thread)8 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)8 RequestThread (com.fanap.podchat.requestobject.RequestThread)8 Test (org.junit.Test)6 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)5 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)5 ChatResponse (com.fanap.podchat.model.ChatResponse)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)3 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)3 ResultHistory (com.fanap.podchat.model.ResultHistory)3 ResultThread (com.fanap.podchat.model.ResultThread)3 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)3 LargeTest (android.support.test.filters.LargeTest)2 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)2 PodChatException (com.fanap.podchat.util.PodChatException)2