Search in sources :

Example 71 with Thread

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

the class TextMessagesQueueTest method populateThreadsListFromServerOnly.

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

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> response) {
            if (!response.isCache()) {
                System.out.println("Received List: " + content);
                threads.addAll(response.getResult().getThreads().stream().filter(thread -> thread.getTitle() != null && thread.getId() > 0 && !thread.isClosed() && thread.getLastMessageVO() != null).collect(Collectors.toList()));
                chat.removeListener(chatListeners);
                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) Context(android.content.Context) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) BeforeClass(org.junit.BeforeClass) SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) 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) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) 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) List(java.util.List) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultMessage(com.fanap.podchat.model.ResultMessage) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) ResultThreads(com.fanap.podchat.model.ResultThreads) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 72 with Thread

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

the class TextMessagesQueueTest method sendMessageWhenChatIsNotReady.

@Test
public void sendMessageWhenChatIsNotReady() {
    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);
    Mockito.verify(mTestListener, Mockito.after(2000).never()).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 73 with Thread

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

the class ChatTestIntegration 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 74 with Thread

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

the class ChatTestIntegration method getThreadHistoryIns.

@Test
@LargeTest
public void getThreadHistoryIns() {
    populateThreadsListFromServerOrCache();
    System.out.println("** Get history of " + threads.get(0).getId());
    for (Thread thread : new ArrayList<>(threads)) {
        getThreadHistory(thread.getId());
    }
// getThreadHistory(threads.get(0).getId());
}
Also used : ArrayList(java.util.ArrayList) 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 75 with Thread

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

the class TextMessagesQueueTest method populateMessagesFromCache.

public void populateMessagesFromCache() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                threadMessagesList.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Aggregations

Thread (com.fanap.podchat.mainmodel.Thread)95 RequestThread (com.fanap.podchat.requestobject.RequestThread)79 Test (org.junit.Test)55 ChatListener (com.fanap.podchat.chat.ChatListener)53 ArrayList (java.util.ArrayList)42 ResultHistory (com.fanap.podchat.model.ResultHistory)36 LargeTest (android.support.test.filters.LargeTest)35 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)33 Date (java.util.Date)30 ChatResponse (com.fanap.podchat.model.ChatResponse)22 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)22 MessageVO (com.fanap.podchat.mainmodel.MessageVO)20 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)16 ResultThreads (com.fanap.podchat.model.ResultThreads)16 FlakyTest (android.support.test.filters.FlakyTest)14 MediumTest (android.support.test.filters.MediumTest)14 Activity (android.app.Activity)10 Context (android.content.Context)10