Search in sources :

Example 21 with RequestMessage

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

the class ChatTestIntegration method setHashTagTest.

@Test
@LargeTest
public void setHashTagTest() {
    ChatListener historyListeners = new ChatListener() {

        @Override
        public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
            System.out.println("onGetHistory: ");
            Logger.json(history.getJson());
            Assert.assertTrue(true);
            resumeProcess();
        }

        @Override
        public void onSent(String content, ChatResponse<ResultMessage> response) {
            System.out.println("onSent: ");
            Logger.json(response.getJson());
            Assert.assertTrue(true);
            resumeProcess();
        }
    };
    chat.addListener(historyListeners);
    RequestMessage requestMessage = new RequestMessage.Builder("#android fragment", 8085).build();
    presenter.sendTextMessage(requestMessage, null);
    pauseProcess();
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) LargeTest(android.support.test.filters.LargeTest)

Example 22 with RequestMessage

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

the class TextMessagesQueueTest 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 23 with RequestMessage

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

the class TextMessagesQueueTest method checkSendingQueue.

@Test
public void checkSendingQueue() {
    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);
    List<SendingQueueCache> sendQ = chat.getSendingQ();
    Assert.assertTrue(sendQ.stream().anyMatch(sendingQueueCache -> sendingQueueCache.getUniqueId().equals(uniqueId)));
}
Also used : SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) 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) SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) 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) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) 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) List(java.util.List) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultMessage(com.fanap.podchat.model.ResultMessage) Rule(org.junit.Rule) TextMessageType(com.fanap.podchat.util.TextMessageType) Assert(org.junit.Assert) Activity(android.app.Activity) Chat(com.fanap.podchat.chat.Chat) 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 24 with RequestMessage

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

the class TextMessagesQueueTest method banUserScenario.

@Test
public void banUserScenario() {
    populateThreadsListFromServerOnly();
    assert threads.size() > 0;
    Thread thread = threads.get(0);
    final boolean[] isBanned = { false };
    ChatListener mTestListener = new ChatListener() {

        @Override
        public void onError(String content, ErrorOutPut error) {
            if (error.getErrorCode() == 208) {
                isBanned[0] = true;
            }
        }
    };
    chat.setListener(mTestListener);
    int counter = 0;
    while (!isBanned[0]) {
        counter++;
        RequestMessage request = new RequestMessage.Builder("Ban me i'm the " + counter + "th message", thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
        chat.sendTextMessage(request, null);
    }
    RequestMessage request = new RequestMessage.Builder("Ok! i'm ban now. but i'll be send after 60 000 milli second is passed", thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    Assert.assertTrue(chat.getWaitingQ().size() > 0);
}
Also used : RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) Test(org.junit.Test)

Example 25 with RequestMessage

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

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