Search in sources :

Example 16 with ResultHistory

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

the class MentionCacheTest method populateMessageFromServer.

public void populateMessageFromServer() {
    chatListeners = new ChatListener() {

        @Override
        public void onGetMentionList(ChatResponse<ResultHistory> response) {
            ChatListener.super.onGetMentionList(response);
        }

        @Override
        public void onGetThread(String content, ChatResponse<ResultThreads> response) {
            if (!response.isCache()) {
                System.out.println("Received List: " + content);
                for (Thread thread : response.getResult().getThreads()) {
                    if (thread.isGroup()) {
                        threads.add(thread);
                    }
                }
                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) ChatListener(com.fanap.podchat.chat.ChatListener) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultHistory(com.fanap.podchat.model.ResultHistory) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread)

Example 17 with ResultHistory

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

the class HashTagCacheTest method populateHashTagListFromServer.

public void populateHashTagListFromServer(long threadId) {
    threadHashTagMessagesListInServer.clear();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHashTagList(ChatResponse<ResultHistory> response) {
            if (!response.isCache()) {
                System.out.println("Received HashTag Message List Server: " + response.getJson());
                threadHashTagMessagesListInServer.addAll(response.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.setListener(chatListeners);
    RequestGetHashTagList request = new RequestGetHashTagList.Builder(threadId).offset(0).count(25).setHashtag("test").build();
    presenter.getHashTagList(request, null);
    pauseProcess();
    System.out.println("Received HashTag Message List Server: " + threadHashTagMessagesListInServer.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) 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) 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) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) 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) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory)

Example 18 with ResultHistory

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

the class HashTagCacheTest method populateHashTagListFromCache.

public void populateHashTagListFromCache(long threadId) {
    threadHashTagMessagesListInCache.clear();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHashTagList(ChatResponse<ResultHistory> response) {
            if (response.isCache()) {
                System.out.println("Received HashTag Message List Server: " + response.getJson());
                threadHashTagMessagesListInCache.addAll(response.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
                chat.removeListener(chatListeners);
                resumeProcess();
            } else {
                Assert.assertEquals(5, 10);
                resumeProcess();
            }
        }
    };
    chat.setListener(chatListeners);
    RequestGetHashTagList request = new RequestGetHashTagList.Builder(threadId).offset(0).count(25).setHashtag("test").build();
    presenter.getHashTagList(request, null);
    pauseProcess();
    System.out.println("Received HashTag Message List Server: " + threadHashTagMessagesListInCache.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) 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) 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) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) 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) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) ChatListener(com.fanap.podchat.chat.ChatListener) ResultHistory(com.fanap.podchat.model.ResultHistory)

Example 19 with ResultHistory

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

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

Example 20 with ResultHistory

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

the class SearchMetadataTest method searchHistoryWithMetadata_NOT_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_NOT_Test() {
    populateThreadsListFromServerOnly();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    RequestMessage.Builder sendMessageWithMetadataRequest;
    sendMessageWithMetadataRequest = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT);
    // Meta1
    int random1 = Math.abs(new Random().nextInt());
    dummyMetadataVO.count = random1;
    String meta1 = App.getGson().toJson(dummyMetadataVO);
    sendMessageWithMetadataRequest.jsonMetaData(meta1);
    chat.sendTextMessage(sendMessageWithMetadataRequest.build(), null);
    sleep(6000);
    // Meta2
    int random2 = Math.abs(new Random().nextInt());
    dummyMetadataVO.count = random2;
    String meta2 = App.getGson().toJson(dummyMetadataVO);
    sendMessageWithMetadataRequest.jsonMetaData(meta2);
    chat.sendTextMessage(sendMessageWithMetadataRequest.build(), null);
    sleep(6000);
    NosqlSearchMetadataCriteria metadataCriteriaUB = new NosqlSearchMetadataCriteria.Builder("count").is(String.valueOf(random2)).build();
    List<NosqlSearchMetadataCriteria> criteriaList = new ArrayList<>();
    criteriaList.add(metadataCriteriaUB);
    NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("count").gte(String.valueOf(random1)).not(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().noneMatch(messageVO -> messageVO.getSystemMetadata().contains(meta2))));
}
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