Search in sources :

Example 1 with GetAssistantRequest

use of com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest in project pod-chat-android-sdk by FanapSoft.

the class ChatActivity method getAssistants.

private void getAssistants() {
    GetAssistantRequest request = new GetAssistantRequest.Builder().typeCode("default").setOffset(0).setCount(2).build();
    presenter.getAssistants(request);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest)

Example 2 with GetAssistantRequest

use of com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method getAssistantHistories.

@Test
public void getAssistantHistories() {
    ArrayList<AssistantVo> assistantVoArrayList = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            assistantVoArrayList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    Collections.shuffle(assistantVoArrayList);
    ChatListener mMockedListener = Mockito.mock(ChatListener.class);
    chat.addListener(mMockedListener);
    GetAssistantHistoryRequest getAssistantHistoryRequest = new GetAssistantHistoryRequest.Builder().setCount(50).build();
    chat.getAssistantHistory(getAssistantHistoryRequest);
    Mockito.verify(mMockedListener, Mockito.after(3000).atLeastOnce()).onGetAssistantHistory(Mockito.any());
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 3 with GetAssistantRequest

use of com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method blockAssistantAndCheckCache.

@Test
public void blockAssistantAndCheckCache() {
    populateContactsFromServer();
    List<AssistantVo> assistantVos = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            if (!response.isCache()) {
                prettyLog(response.getJson());
                assistantVos.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).withNoCache().setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    // the block assistant method accepts only Invitee
    Collections.shuffle(assistantVos);
    List<AssistantVo> notBlockedAssistants = assistantVos.stream().filter(assistantVo -> !assistantVo.getBlock()).collect(Collectors.toList());
    Contact assistantContactToBlock = contacts.stream().filter(contact -> contact.getLinkedUser() != null && Objects.equals(contact.getLinkedUser().getUsername(), notBlockedAssistants.get(0).getParticipantVO().getUsername())).findFirst().get();
    print("Going to block " + assistantContactToBlock.getFirstName());
    prettyLog(App.getGson().toJson(assistantContactToBlock));
    Invitee invitee = new Invitee(assistantContactToBlock.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    AssistantVo assistantToBlock = new AssistantVo();
    assistantToBlock.setInvitees(invitee);
    List<AssistantVo> toBlockAssistantList = new ArrayList<>();
    toBlockAssistantList.add(assistantToBlock);
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantBlocked(ChatResponse<List<AssistantVo>> response) {
            prettyLog(response.getJson());
            toBlockAssistantList.clear();
            toBlockAssistantList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    BlockUnblockAssistantRequest requestBlock = new BlockUnblockAssistantRequest.Builder(toBlockAssistantList, true).build();
    chat.blockAssistant(requestBlock);
    pauseProcess();
    ArrayList<AssistantVo> inCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            if (response.isCache()) {
                prettyLog(response.getJson());
                inCache.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest requestGetAssistantFromCache = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(requestGetAssistantFromCache);
    pauseProcess();
    assert inCache.size() > 0;
    Assert.assertTrue(inCache.stream().filter(anAssistantInCache -> toBlockAssistantList.stream().anyMatch(blockListAssistant -> anAssistantInCache.getParticipantVO().getId() == blockListAssistant.getParticipantVO().getId())).findFirst().get().getBlock());
}
Also used : ResultContact(com.fanap.podchat.model.ResultContact) ResultThreads(com.fanap.podchat.model.ResultThreads) RoleType(com.fanap.podchat.chat.RoleType) ChatPresenter(com.example.chat.application.chatexample.ChatPresenter) ResultHistory(com.fanap.podchat.model.ResultHistory) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Looper(android.os.Looper) App(com.fanap.podchat.chat.App) Invitee(com.fanap.podchat.mainmodel.Invitee) InviteType(com.fanap.podchat.util.InviteType) Participant(com.fanap.podchat.mainmodel.Participant) Logger(com.orhanobut.logger.Logger) InstrumentationRegistry(android.support.test.InstrumentationRegistry) ChatListener(com.fanap.podchat.chat.ChatListener) MessageVO(com.fanap.podchat.mainmodel.MessageVO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) APP_ID(com.example.chat.application.chatexample.ChatActivity.APP_ID) List(java.util.List) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Chat(com.fanap.podchat.chat.Chat) Context(android.content.Context) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) Thread(com.fanap.podchat.mainmodel.Thread) RunWith(org.junit.runner.RunWith) ChatContract(com.example.chat.application.chatexample.ChatContract) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultParticipant(com.fanap.podchat.model.ResultParticipant) ArrayList(java.util.ArrayList) R(com.fanap.podchat.example.R) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) BaseApplication(com.example.chat.application.chatexample.BaseApplication) ChatActivity(com.example.chat.application.chatexample.ChatActivity) Contact(com.fanap.podchat.mainmodel.Contact) RequestThread(com.fanap.podchat.requestobject.RequestThread) 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) AndroidJUnit4(android.support.test.runner.AndroidJUnit4) LargeTest(android.support.test.filters.LargeTest) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Assert(org.junit.Assert) Activity(android.app.Activity) Collections(java.util.Collections) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Invitee(com.fanap.podchat.mainmodel.Invitee) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 4 with GetAssistantRequest

use of com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method checkCacheAndServerAssistantList.

@Test
public void checkCacheAndServerAssistantList() {
    ArrayList<AssistantVo> inCache = new ArrayList<>();
    ArrayList<AssistantVo> inServer = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            if (response.isCache()) {
                inCache.addAll(response.getResult());
            } else {
                inServer.addAll(response.getResult());
            }
            if (inCache.size() > 0 && inServer.size() > 0) {
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    pauseProcess();
    Assert.assertEquals(inCache.size(), inServer.size());
    for (AssistantVo assistantInServer : inServer) {
        Assert.assertTrue(validateAssistantsAreSame(assistantInServer, inCache));
    }
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) ChatListener(com.fanap.podchat.chat.ChatListener) List(java.util.List) ArrayList(java.util.ArrayList) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 5 with GetAssistantRequest

use of com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest in project pod-chat-android-sdk by FanapSoft.

the class AssistantCacheTest method getAssistantList.

@Test
public void getAssistantList() {
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.addListener(mTestListener);
    GetAssistantRequest request = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
    chat.getAssistants(request);
    Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetAssistants(Mockito.any());
}
Also used : ChatListener(com.fanap.podchat.chat.ChatListener) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Aggregations

GetAssistantRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest)10 LargeTest (android.support.test.filters.LargeTest)7 ChatListener (com.fanap.podchat.chat.ChatListener)7 Test (org.junit.Test)7 AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 GetAssistantHistoryRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest)4 AssistantHistoryVo (com.fanap.podchat.chat.assistant.model.AssistantHistoryVo)3 RegisterAssistantRequest (com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest)3 Contact (com.fanap.podchat.mainmodel.Contact)3 Invitee (com.fanap.podchat.mainmodel.Invitee)3 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultContact (com.fanap.podchat.model.ResultContact)3 RequestGetContact (com.fanap.podchat.requestobject.RequestGetContact)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Looper (android.os.Looper)2 InstrumentationRegistry (android.support.test.InstrumentationRegistry)2 ActivityTestRule (android.support.test.rule.ActivityTestRule)2