Search in sources :

Example 91 with ChatListener

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

the class SearchMetadataTest method populateThreadsListFromServerOrCache.

// requests for list of threads
@Test
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.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) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 92 with ChatListener

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

the class SearchMetadataTest method searchHistoryWithMetadata_Is_NumberTest.

@Test
@LargeTest
public void searchHistoryWithMetadata_Is_NumberTest() {
    populateThreadsListFromServerOnly();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    dummyMetadataVO.desc = "876";
    String meta = App.getGson().toJson(dummyMetadataVO);
    RequestMessage sendMessageWithMetadataRequest = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta).build();
    chat.sendTextMessage(sendMessageWithMetadataRequest, null);
    sleep(6000);
    NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("desc").is(dummyMetadataVO.desc).build();
    SearchSystemMetadataRequest request = new SearchSystemMetadataRequest.Builder(thread.getId()).metadataCriteria(metadataCriteria).count(50).build();
    chat.searchHistory(request, null);
    Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onGetHistory(Mockito.any(String.class), Mockito.argThat((ChatResponse<ResultHistory> resp) -> resp.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getSystemMetadata().equals(meta))));
}
Also used : ResultHistory(com.fanap.podchat.model.ResultHistory) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) NosqlSearchMetadataCriteria(com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria) SearchSystemMetadataRequest(com.fanap.podchat.chat.messge.SearchSystemMetadataRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 93 with ChatListener

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

the class SearchMetadataTest method chatListeners.

@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) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 94 with ChatListener

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

the class SearchMetadataTest method populateThreadsListFromServerOnly.

// requests for list of threads from server
@Test
public void populateThreadsListFromServerOnly() {
    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());
                resumeProcess();
            }
        }
    };
    chat.setListener(chatListeners);
    RequestThread requestThread = new RequestThread.Builder().count(25).withNoCache().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) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 95 with ChatListener

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

the class SearchMetadataTest method searchHistoryWithMetadata_LT_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_LT_Test() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("count").lte("4").build();
    SearchSystemMetadataRequest request = new SearchSystemMetadataRequest.Builder(thread.getId()).metadataCriteria(metadataCriteria).count(50).build();
    chat.searchHistory(request, null);
    Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onGetHistory(Mockito.any(String.class), Mockito.argThat((ChatResponse<ResultHistory> resp) -> resp.getResult().getHistory().size() > 0));
}
Also used : ChatListener(com.fanap.podchat.chat.ChatListener) NosqlSearchMetadataCriteria(com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria) SearchSystemMetadataRequest(com.fanap.podchat.chat.messge.SearchSystemMetadataRequest) ResultHistory(com.fanap.podchat.model.ResultHistory) 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)

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