Search in sources :

Example 81 with Thread

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

the class ThreadCacheTest method sendMessageAndDelete.

public void sendMessageAndDelete() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    Assert.assertNotNull(thread);
    ArrayList<Long> msgIds = new ArrayList<>();
    // send new message
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            msgIds.add(response.getResult().getMessageVO().getId());
            System.out.println("new message sent -> msg : " + content);
            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("Message for test delete :" + thread.getId(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    pauseProcess();
    // delete last message
    chatListeners = new ChatListener() {

        @Override
        public void onDeleteMessage(String content, ChatResponse<ResultDeleteMessage> response) {
            resumeProcess();
            System.out.println("Deleted: " + content);
            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);
    RequestDeleteMessage requestDeleteMessage = new RequestDeleteMessage.Builder().messageIds(msgIds).deleteForAll(true).build();
    presenter.deleteMessage(requestDeleteMessage, null);
    pauseProcess();
}
Also used : RequestDeleteMessage(com.fanap.podchat.requestobject.RequestDeleteMessage) ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage)

Example 82 with Thread

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

the class ThreadCacheTest method sendMessageAndEdit.

public void sendMessageAndEdit() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    Assert.assertNotNull(thread);
    final long[] messageId = { 0 };
    // send new message
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            messageId[0] = response.getResult().getMessageVO().getId();
            resumeProcess();
            System.out.println("new message sent -> msg : " + content);
            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("Message for test edit :" + thread.getId(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    pauseProcess();
    // delete last message
    chatListeners = new ChatListener() {

        @Override
        public void onEditedMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            System.out.println("Edited: " + content);
            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);
    RequestEditMessage requestEditMessage = new RequestEditMessage.Builder("last message edited " + messageId[0], messageId[0]).build();
    chat.editMessage(requestEditMessage, null);
    pauseProcess();
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) RequestEditMessage(com.fanap.podchat.requestobject.RequestEditMessage) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread)

Example 83 with Thread

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

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

Example 84 with Thread

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

the class IntegrationTest 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 85 with Thread

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

the class IntegrationTest method searchHistoryWithMetadata_AND_Test.

@Test
@LargeTest
public void searchHistoryWithMetadata_AND_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.count = 1001;
    // 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);
    // 
    // dummyMetadataVO.count = 1002;
    // meta = App.getGson().toJson(dummyMetadataVO);
    // 
    // sendMessageWithMetadataRequest.setJsonMetaData(meta);
    // chat.sendTextMessage(sendMessageWithMetadataRequest, null);
    // 
    // sleep(6000);
    // NosqlSearchMetadataCriteria
    // metadataCriteriaLB =
    // new NosqlSearchMetadataCriteria.Builder("count")
    // .gt("1000")
    // .build();
    NosqlSearchMetadataCriteria metadataCriteriaUB = new NosqlSearchMetadataCriteria.Builder("count").lte("1002").build();
    List<NosqlSearchMetadataCriteria> criteriaList = new ArrayList<>();
    // criteriaList.add(metadataCriteriaLB);
    criteriaList.add(metadataCriteriaUB);
    NosqlSearchMetadataCriteria metadataCriteria = new NosqlSearchMetadataCriteria.Builder("count").gt("1000").and(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) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) 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

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