Search in sources :

Example 41 with ChatListener

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

the class AssistantCacheTest method populateThreadsListFromServerOrCache.

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

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> thread) {
            print("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 42 with ChatListener

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

the class AssistantCacheTest method getAssistantList.

@Test
public void getAssistantList() {
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.addListener(mTestListener);
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetAssistants(Mockito.any());
}
Also used : ChatListener(com.fanap.podchat.chat.ChatListener) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 43 with ChatListener

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

the class AssistantCacheTest method getAndValidateAssistantHistoriesCache.

@Test
public void getAndValidateAssistantHistoriesCache() {
    ArrayList<AssistantVo> assistantVoArrayList = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            assistantVoArrayList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    Collections.shuffle(assistantVoArrayList);
    ArrayList<AssistantHistoryVo> assistantHistoryVos = new ArrayList<>();
    ArrayList<AssistantHistoryVo> assistantHistoryVosCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistantHistory(ChatResponse<List<AssistantHistoryVo>> response) {
            print("Received Assistant Histories cache: " + response.isCache());
            prettyLog(App.getGson().toJson(response.getResult()));
            if (response.isCache()) {
                assistantHistoryVosCache.addAll(response.getResult());
            } else {
                assistantHistoryVos.addAll(response.getResult());
            }
            if (assistantHistoryVos.size() == assistantHistoryVosCache.size()) {
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantHistoryRequest getAssistantHistoryRequest = new GetAssistantHistoryRequest.Builder().setCount(50).build();
    chat.getAssistantHistory(getAssistantHistoryRequest);
    pauseProcess();
    Assert.assertTrue(true);
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 44 with ChatListener

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

the class ChatTestIntegration method createChat.

@Before
public void createChat() {
    Looper.prepare();
    MockitoAnnotations.initMocks(this);
    RequestConnect rc = new RequestConnect.Builder(socketAddress, APP_ID, serverName, TOKEN, ssoHost, platformHost, fileServer, "podSpaceServer").build();
    chatListeners = new ChatListener() {

        @Override
        public void onChatState(String state) {
            if (state.equals(CHAT_READY)) {
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    chat.connect(rc);
    pauseProcess();
}
Also used : RequestConnect(com.fanap.podchat.requestobject.RequestConnect) ChatListener(com.fanap.podchat.chat.ChatListener) Before(org.junit.Before)

Example 45 with ChatListener

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

the class ChatTestIntegration method chatListeners.

// @After
// public void closeChat() {
// if (chat != null) {
// chat.closeChat();
// } else if (presenter != null) {
// presenter.closeChat();
// }
// }
@Test
public void chatListeners() {
    ChatListener listener1 = new ChatListener() {

        @Override
        public void onSent(String content, ChatResponse<ResultMessage> response) {
        }
    };
    chat.addListener(listener1);
    ChatListener listener2 = new ChatListener() {

        @Override
        public void onSent(String content, ChatResponse<ResultMessage> response) {
        }
    };
    chat.addListener(listener2);
    ChatListener listener3 = new ChatListener() {

        @Override
        public void onSent(String content, ChatResponse<ResultMessage> response) {
        }
    };
    chat.addListener(listener3);
    chat.removeListener(listener2);
    Assert.assertFalse(chat.getListeners().contains(listener2));
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

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