Search in sources :

Example 1 with RequestMessage

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

the class MessagesCacheTest method testIfParticipantsAreSame.

@Test
public void testIfParticipantsAreSame() {
    populateMessagesFromServer();
    assert threadMessagesList.size() > 0;
    Collections.shuffle(threadMessagesList);
    MessageVO message = threadMessagesList.get(0);
    assert message.getConversation() != null;
    Thread thread = message.getConversation();
    chat.setListener(new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
        }
    });
    RequestMessage repRequest = new RequestMessage.Builder("Message at " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(repRequest, null);
    pauseProcess();
    // Load Server messages
    ArrayList<MessageVO> msgFromServer = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (!history.isCache()) {
                System.out.println("Received Message List Server: " + content);
                msgFromServer.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
    chat.getHistory(requestGetHistory, null);
    pauseProcess();
    // Load cache
    ArrayList<MessageVO> msgFromCache = new ArrayList<>();
    chatListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            if (history.isCache()) {
                System.out.println("Received Message List Cache: " + content);
                msgFromCache.addAll(history.getResult().getHistory());
                chat.removeListener(chatListeners);
                resumeProcess();
            }
        }
    };
    chat.addListener(chatListeners);
    RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
    chat.getHistory(requestGetHistoryCache, null);
    pauseProcess();
    assert msgFromServer.size() > 0;
    assert msgFromCache.size() > 0;
    assert msgFromCache.size() == msgFromServer.size();
    for (MessageVO msg : msgFromServer) {
        if (msg.getMessage() == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " Conversation: " + msg.getConversation());
        MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getConversation());
        Assert.assertEquals(msg.getParticipant() != null, msgInCache.getParticipant() != null);
        if (msg.getParticipant() != null) {
            Assert.assertEquals(msg.getParticipant().getId(), msgInCache.getParticipant().getId());
            Assert.assertEquals(msg.getParticipant().getName(), msgInCache.getParticipant().getName());
            Assert.assertEquals(msg.getParticipant().getChatProfileVO() != null, msgInCache.getParticipant().getChatProfileVO() != null);
        }
    }
}
Also used : RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) 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) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Test(org.junit.Test)

Example 2 with RequestMessage

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

the class MessagesCacheTest method sendMessageToThread.

@Test
public void sendMessageToThread() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
    sleep(2000);
}
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 3 with RequestMessage

use of com.fanap.podchat.requestobject.RequestMessage 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 4 with RequestMessage

use of com.fanap.podchat.requestobject.RequestMessage 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)

Example 5 with RequestMessage

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

the class SearchMetadataTest method searchHistoryWithMetadata_Is_StringTest.

@Test
@LargeTest
public void searchHistoryWithMetadata_Is_StringTest() {
    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 = "This is me!";
    // dummyMetadataVO.desc = UUID.randomUUID().toString();
    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)

Aggregations

RequestMessage (com.fanap.podchat.requestobject.RequestMessage)32 ChatListener (com.fanap.podchat.chat.ChatListener)27 Thread (com.fanap.podchat.mainmodel.Thread)25 RequestThread (com.fanap.podchat.requestobject.RequestThread)25 Test (org.junit.Test)24 Date (java.util.Date)22 LargeTest (android.support.test.filters.LargeTest)15 ResultHistory (com.fanap.podchat.model.ResultHistory)14 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)10 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)10 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)10 ArrayList (java.util.ArrayList)8 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)5 MessageVO (com.fanap.podchat.mainmodel.MessageVO)4 ChatResponse (com.fanap.podchat.model.ChatResponse)4 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)4 GsonBuilder (com.google.gson.GsonBuilder)4 Random (java.util.Random)4 FlakyTest (android.support.test.filters.FlakyTest)3 MediumTest (android.support.test.filters.MediumTest)3