Search in sources :

Example 6 with ResultHistory

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

the class MessagesCacheTest method sendReplyMessageAndCheckCache.

@Test
public void sendReplyMessageAndCheckCache() {
    populateThreadsListFromServerOnly();
    populateMessagesFromServer();
    assert threads.size() > 0;
    assert threadMessagesList.size() > 0;
    Thread thread = threads.get(0);
    MessageVO message = threadMessagesList.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    String replyTXT = "Reply to " + message.getMessage();
    RequestReplyMessage repRequest = new RequestReplyMessage.Builder(replyTXT, thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
    chat.replyMessage(repRequest, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistory, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getMessage().equals(replyTXT))));
}
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) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) 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) 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) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) Collections(java.util.Collections) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test)

Example 7 with ResultHistory

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

the class MessagesCacheTest method populateMessagesFromServerOrCache.

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

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            System.out.println("Received Message List, Cache: " + history.isCache() + " Content: " + 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)

Example 8 with ResultHistory

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

the class MessagesCacheTest method populateMessagesFromServer.

public void populateMessagesFromServer() {
    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 Server: " + content);
                threadMessagesList.addAll(history.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
}
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) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) 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) 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) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) Collections(java.util.Collections) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) 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)

Example 9 with ResultHistory

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

the class SearchMetadataTest method searchHistoryWithMetadata_GT_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_GT_Test() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    dummyMetadataVO.desc = "GT test";
    dummyMetadataVO.count = 12;
    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("count").gte("12").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 : 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 10 with ResultHistory

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

the class SearchMetadataTest method searchHistoryWithMetadata_OR_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_OR_Test() {
    populateThreadsListFromServerOnly();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    int random1 = Math.abs(new Random().nextInt());
    dummyMetadataVO.count = random1;
    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);
    int random2 = Math.abs(new Random().nextInt());
    dummyMetadataVO.count = random2;
    meta = App.getGson().toJson(dummyMetadataVO);
    sendMessageWithMetadataRequest.setJsonMetaData(meta);
    chat.sendTextMessage(sendMessageWithMetadataRequest, null);
    sleep(6000);
    // NosqlSearchMetadataCriteria
    // metadataCriteriaLB =
    // new NosqlSearchMetadataCriteria.Builder("count")
    // .is(String.valueOf(random1))
    // .build();
    NosqlSearchMetadataCriteria metadataCriteriaUB = new NosqlSearchMetadataCriteria.Builder("count").is(String.valueOf(random2)).build();
    List<NosqlSearchMetadataCriteria> criteriaList = new ArrayList<>();
    // criteriaList.add(metadataCriteriaLB);
    criteriaList.add(metadataCriteriaUB);
    NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("count").is(String.valueOf(random1)).or(criteriaList).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().contains(String.valueOf(dummyMetadataVO.count)))));
}
Also used : ArrayList(java.util.ArrayList) ResultHistory(com.fanap.podchat.model.ResultHistory) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Random(java.util.Random) 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)

Aggregations

ResultHistory (com.fanap.podchat.model.ResultHistory)47 ChatListener (com.fanap.podchat.chat.ChatListener)36 Thread (com.fanap.podchat.mainmodel.Thread)36 RequestThread (com.fanap.podchat.requestobject.RequestThread)36 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)22 ChatResponse (com.fanap.podchat.model.ChatResponse)21 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)21 Date (java.util.Date)21 MessageVO (com.fanap.podchat.mainmodel.MessageVO)18 LargeTest (android.support.test.filters.LargeTest)17 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)15 ResultThreads (com.fanap.podchat.model.ResultThreads)11 Activity (android.app.Activity)10 Context (android.content.Context)10 Looper (android.os.Looper)10 InstrumentationRegistry (android.support.test.InstrumentationRegistry)10 ActivityTestRule (android.support.test.rule.ActivityTestRule)10