Search in sources :

Example 56 with ChatListener

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

the class ChatTest method populateThreadsListFromCacheOnly.

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

Example 57 with ChatListener

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

the class ChatTest method getThreadFullHistory.

private void getThreadFullHistory(Thread thread) {
    long startTime = System.currentTimeMillis();
    AtomicBoolean hasNext = new AtomicBoolean(true);
    int count = 25;
    AtomicLong offset = new AtomicLong(0);
    AtomicLong threadMessagesCount = new AtomicLong(-1);
    AtomicLong threadReceivedHistory = new AtomicLong(0);
    ChatListener historyListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            threadMessagesCount.set(history.getResult().getContentCount());
            long received = threadReceivedHistory.get();
            threadReceivedHistory.set(received + history.getResult().getHistory().size());
            hasNext.set(history.getResult().isHasNext());
            if (hasNext.get()) {
                offset.set(offset.get() + history.getResult().getHistory().size());
            }
            resumeProcess();
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            Assert.fail(content);
        }
    };
    chat.addListener(historyListeners);
    while (hasNext.get()) {
        RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).offset(offset.get()).withNoCache().count(count).order("desc").build();
        String uniqueId = presenter.getHistory(requestGetHistory, null);
        pauseProcess();
    }
    long endTime = System.currentTimeMillis();
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println("RUNNING TEST ON THREAD:");
    System.out.println(thread.getTitle());
    System.out.println(thread.getId());
    System.out.println("RECEIVED TOTAL " + threadReceivedHistory + " MESSAGES OF HISTORY IN");
    System.out.println(endTime - startTime + " MILLISECONDS");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    System.out.println(">>> >>> >>>");
    Assert.assertEquals(threadMessagesCount.get(), threadReceivedHistory.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut)

Example 58 with ChatListener

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

the class ChatTest method getThreadHistoryBeforeAndAfterLastSeenMessage.

@Test
@LargeTest
public // and greater in second case
void getThreadHistoryBeforeAndAfterLastSeenMessage() {
    populateThreadsListFromServerOrCache();
    System.out.println("** Get history of " + threads.get(0).getTitle());
    Thread thread = threads.get(0);
    final long lastSeen = thread.getLastSeenMessageTime() + thread.getLastSeenMessageNanos();
    AtomicInteger numOfCacheResp = new AtomicInteger(0);
    ChatListener historyListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            int invokeTimes = 0;
            if (history.isCache()) {
                invokeTimes = numOfCacheResp.getAndIncrement();
            }
            checkTimesIsValid(history, invokeTimes, lastSeen);
            if (invokeTimes >= 2) {
                resumeProcess();
            }
        }
    };
    chat.addListener(historyListeners);
    RequestGetHistory requestGetHistoryBeforeLastSeenTime = new RequestGetHistory.Builder(thread.getId()).toTimeNanos(lastSeen).offset(0).count(25).order("desc").build();
    presenter.getHistory(requestGetHistoryBeforeLastSeenTime, null);
    RequestGetHistory requestGetHistoryAfterLastSeenTime = new RequestGetHistory.Builder(thread.getId()).fromTimeNanos(lastSeen).offset(0).count(25).order("asc").build();
    presenter.getHistory(requestGetHistoryAfterLastSeenTime, null);
    pauseProcess();
    sleep(2000);
    Mockito.verify(view, Mockito.atLeast(2)).onGetThreadHistory(Mockito.any());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatResponse(com.fanap.podchat.model.ChatResponse) ChatListener(com.fanap.podchat.chat.ChatListener) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 59 with ChatListener

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

the class ChatTest 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) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 60 with ChatListener

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

the class ChatTest 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) 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