Search in sources :

Example 1 with RequestReplyMessage

use of com.fanap.podchat.requestobject.RequestReplyMessage in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method sendReplyMessageAndCheckCache.

@Test
public void sendReplyMessageAndCheckCache() {
    populateThreadsListFromServerOnly();
    populateMessagesFromServer();
    assert threads.size() > 0;
    assert threadMessagesList.size() > 0;
    Thread thread = threads.get(0);
    MessageVO message = threadMessagesList.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    String replyTXT = "Reply to " + message.getMessage();
    RequestReplyMessage repRequest = new RequestReplyMessage.Builder(replyTXT, thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
    chat.replyMessage(repRequest, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistory, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getMessage().equals(replyTXT))));
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) Context(android.content.Context) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) BeforeClass(org.junit.BeforeClass) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) Mock(org.mockito.Mock) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ChatContract(com.example.chat.application.chatexample.ChatContract) ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) ResultHistory(com.fanap.podchat.model.ResultHistory) Looper(android.os.Looper) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) RequestThread(com.fanap.podchat.requestobject.RequestThread) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) Before(org.junit.Before) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) CHAT_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CHAT_READY) ActivityTestRule(android.support.test.rule.ActivityTestRule) Test(org.junit.Test) InstrumentationRegistry(android.support.test.InstrumentationRegistry) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) Collections(java.util.Collections) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test)

Example 2 with RequestReplyMessage

use of com.fanap.podchat.requestobject.RequestReplyMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatActivity method replyMessage.

public void replyMessage() {
    RequestReplyMessage message = new RequestReplyMessage.Builder("this is reply from john", TEST_THREAD_ID, 94305, TextMessageType.Constants.TEXT).build();
    presenter.replyMessage(message, null);
// presenter.replyMessage("this is reply from john", 381, 14103, new ChatHandler() {
// @Override
// public void onReplyMessage(String uniqueId) {
// super.onReplyMessage(uniqueId);
// }
// });
}
Also used : RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage)

Example 3 with RequestReplyMessage

use of com.fanap.podchat.requestobject.RequestReplyMessage in project pod-chat-android-sdk by FanapSoft.

the class MessagesCacheTest method sendReplyMessage.

@Test
public void sendReplyMessage() {
    populateMessagesFromServer();
    Collections.shuffle(threadMessagesList);
    MessageVO message = threadMessagesList.get(0);
    Assert.assertNotNull(message);
    Thread thread = message.getConversation();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    RequestReplyMessage repRequest = new RequestReplyMessage.Builder("Reply to " + message.getMessage(), thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
    chat.replyMessage(repRequest, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
    sleep(2000);
}
Also used : RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test)

Example 4 with RequestReplyMessage

use of com.fanap.podchat.requestobject.RequestReplyMessage 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)

Aggregations

RequestReplyMessage (com.fanap.podchat.requestobject.RequestReplyMessage)4 ChatListener (com.fanap.podchat.chat.ChatListener)3 MessageVO (com.fanap.podchat.mainmodel.MessageVO)3 Thread (com.fanap.podchat.mainmodel.Thread)3 RequestThread (com.fanap.podchat.requestobject.RequestThread)3 Test (org.junit.Test)3 ResultHistory (com.fanap.podchat.model.ResultHistory)2 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)2 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Looper (android.os.Looper)1 InstrumentationRegistry (android.support.test.InstrumentationRegistry)1 ActivityTestRule (android.support.test.rule.ActivityTestRule)1 AndroidJUnit4 (android.support.test.runner.AndroidJUnit4)1 BaseApplication (com.example.chat.application.chatexample.BaseApplication)1 ChatActivity (com.example.chat.application.chatexample.ChatActivity)1 APP_ID (com.example.chat.application.chatexample.ChatActivity.APP_ID)1 ChatContract (com.example.chat.application.chatexample.ChatContract)1