Search in sources :

Example 6 with RequestMessage

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

the class IntegrationTest method searchHistoryWithMetadata_Is_NumberTest.

@Test
@LargeTest
public void searchHistoryWithMetadata_Is_NumberTest() {
    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 = "876";
    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)

Example 7 with RequestMessage

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

the class IntegrationTest method sendMessageWithMetadataTest.

@Test
@LargeTest
public void sendMessageWithMetadataTest() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.setListener(mTestListener);
    DummyMetadataVO dummyMetadataVO = new DummyMetadataVO();
    dummyMetadataVO.count = new Random().nextInt();
    dummyMetadataVO.desc = dummyMetadataVO.desc + "" + dummyMetadataVO.count;
    String meta = App.getGson().toJson(dummyMetadataVO);
    RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta).build();
    chat.sendTextMessage(request, null);
    sleep(2000);
    for (int i = 0; i < 16; i++) {
        dummyMetadataVO.count++;
        dummyMetadataVO.desc = String.format("%s%d", dummyMetadataVO.desc, dummyMetadataVO.count);
        String meta2 = App.getGson().toJson(dummyMetadataVO);
        request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).jsonMetaData(meta2).build();
        chat.sendTextMessage(request, null);
        sleep(6000);
    }
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> resp.getResult().getMessageVO().getSystemMetadata().equals(meta)));
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.argThat((ChatResponse<ResultNewMessage> resp) -> !resp.getResult().getMessageVO().getSystemMetadata().equals("I'm something else!")));
}
Also used : Random(java.util.Random) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) 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) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 8 with RequestMessage

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

the class SearchMetadataTest method searchHistoryWithMetadata_Has_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_Has_Test() {
    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 = "Find me before  " + System.currentTimeMillis() + (1_000_000 * 6);
    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").has(" me ").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(dummyMetadataVO.desc))));
}
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 9 with RequestMessage

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

the class TextMessagesQueueTest method sendMessageFromSendingQueue.

@Test
public void sendMessageFromSendingQueue() {
    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);
    chat.resumeChat();
    Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).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 10 with RequestMessage

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

the class ThreadCacheTest method sendMessage.

public void sendMessage() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    System.out.println("Thread : " + thread.getTitle());
    Assert.assertNotNull(thread);
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            chat.removeListener(chatListeners);
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            resumeProcess();
            System.out.println("Error: " + content);
            Assert.assertEquals(0, 1);
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Date(java.util.Date) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread)

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