Search in sources :

Example 31 with ChatListener

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

the class TextMessagesQueueTest method populateThreadsListFromServerOrCache.

// requests for list of threads
public void populateThreadsListFromServerOrCache() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            System.out.println("Received List: " + content);
            threads.addAll(thread.getResult().getThreads());
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).build();
    presenter.getThreads(requestThread, null);
    long t1 = System.currentTimeMillis();
    Mockito.verify(view, Mockito.after(10000).atLeastOnce()).onGetThreadList(Mockito.any(), Mockito.any());
    long t2 = System.currentTimeMillis();
    System.out.println("Received List: " + threads.size() + " after: " + (t2 - t1) + " ms");
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 32 with ChatListener

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

the class TextMessagesQueueTest method sendMessageFromSendingQueue.

@Test
public void sendMessageFromSendingQueue() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    chat.closeChat();
    sleep(2000);
    Assert.assertNotEquals(chat.getChatState(), CHAT_READY);
    RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    String uniqueId = chat.sendTextMessage(request, null);
    chat.resumeChat();
    Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
}
Also used : 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)

Example 33 with ChatListener

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

the class TextMessagesQueueTest method populateThreadsListFromCacheOnly.

// requests for list of threads from cache
public void populateThreadsListFromCacheOnly() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            if (thread.isCache()) {
                System.out.println("Received List: " + content);
                threads.addAll(thread.getResult().getThreads());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).build();
    presenter.getThreads(requestThread, null);
    pauseProcess();
    System.out.println("Received List: " + threads.size());
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 34 with ChatListener

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

the class ThreadCacheTest method populateThreadsFromCache.

public void populateThreadsFromCache() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            if (thread.isCache()) {
                threadsInCache.addAll(thread.getResult().getThreads());
                chat.removeListener(chatListeners);
            } else
                Assert.assertEquals(0, 1);
            resumeProcess();
        }
    };
    chat.addListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).build();
    presenter.getThreads(requestThread, null);
    long t1 = System.currentTimeMillis();
    pauseProcess();
    long t2 = System.currentTimeMillis();
    System.out.println("Received List: " + threadsInCache.size() + " after: " + (t2 - t1) + " ms");
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 35 with ChatListener

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

the class ThreadCacheTest method sendMessage.

public void sendMessage() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    System.out.println("Thread : " + thread.getTitle());
    Assert.assertNotNull(thread);
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            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("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread)

Aggregations

ChatListener (com.fanap.podchat.chat.ChatListener)134 Test (org.junit.Test)87 RequestThread (com.fanap.podchat.requestobject.RequestThread)80 LargeTest (android.support.test.filters.LargeTest)63 Thread (com.fanap.podchat.mainmodel.Thread)61 ResultHistory (com.fanap.podchat.model.ResultHistory)44 ChatResponse (com.fanap.podchat.model.ChatResponse)40 ResultThreads (com.fanap.podchat.model.ResultThreads)39 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)38 ArrayList (java.util.ArrayList)38 Date (java.util.Date)32 RequestConnect (com.fanap.podchat.requestobject.RequestConnect)31 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)31 Before (org.junit.Before)31 ChatPresenter (com.example.chat.application.chatexample.ChatPresenter)29 MessageVO (com.fanap.podchat.mainmodel.MessageVO)23 FlakyTest (android.support.test.filters.FlakyTest)21 MediumTest (android.support.test.filters.MediumTest)21 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)21 Activity (android.app.Activity)18