Search in sources :

Example 16 with AssistantVo

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

the class AssistantCacheTest method registerNewAssistant.

@Test
public void registerNewAssistant() {
    populateContactsFromServer();
    ChatListener mTestListener = Mockito.mock(ChatListener.class);
    chat.addListener(mTestListener);
    assert contacts.size() > 0;
    Contact contact = getValidContact();
    print("Selected contact for register as assistant " + App.getGson().toJson(contact));
    ArrayList<String> typeRoles = new ArrayList<>();
    typeRoles.add(RoleType.Constants.ADD_ROLE_TO_USER);
    typeRoles.add(RoleType.Constants.READ_THREAD);
    typeRoles.add(RoleType.Constants.EDIT_THREAD);
    List<AssistantVo> assistantVos = new ArrayList<>();
    AssistantVo assistantVo = new AssistantVo();
    Invitee invite = new Invitee(contact.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    assistantVo.setInvitees(invite);
    assistantVo.setContactType("default");
    assistantVo.setRoles(typeRoles);
    assistantVos.add(assistantVo);
    RegisterAssistantRequest request = new RegisterAssistantRequest.Builder(assistantVos).build();
    chat.registerAssistant(request);
    Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onRegisterAssistant(Mockito.argThat((ChatResponse<List<AssistantVo>> response) -> response.getResult().stream().anyMatch(assistantVo1 -> assistantVo1.getParticipantVO().getCoreUserId() == contact.getLinkedUser().getCoreUserId())));
}
Also used : Invitee(com.fanap.podchat.mainmodel.Invitee) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ChatListener(com.fanap.podchat.chat.ChatListener) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ResultContact(com.fanap.podchat.model.ResultContact) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Contact(com.fanap.podchat.mainmodel.Contact) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 17 with AssistantVo

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

the class AssistantCacheTest method unBlockAssistantAndCheckBlockListInCache.

@Test
public void unBlockAssistantAndCheckBlockListInCache() {
    populateContactsFromServer();
    ArrayList<AssistantVo> blockedListFromServer = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantBlocks(ChatResponse<List<AssistantVo>> response) {
            print("Blocked assistants list cache: " + response.isCache());
            prettyLog(response.getJson());
            blockedListFromServer.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    GetBlockedAssistantsRequest getBlockedAssistantsRequest = new GetBlockedAssistantsRequest.Builder().withNoCache().build();
    chat.getBlocksAssistant(getBlockedAssistantsRequest);
    pauseProcess();
    Contact assistantContactToUnBlock = contacts.stream().filter(contact -> contact.getLinkedUser() != null && Objects.equals(contact.getLinkedUser().getUsername(), blockedListFromServer.get(0).getParticipantVO().getUsername())).findFirst().get();
    print("Going to unblock " + assistantContactToUnBlock.getFirstName());
    prettyLog(App.getGson().toJson(assistantContactToUnBlock));
    Invitee invitee = new Invitee(assistantContactToUnBlock.getId(), InviteType.Constants.TO_BE_USER_CONTACT_ID);
    AssistantVo assistantToUnBlock = new AssistantVo();
    assistantToUnBlock.setInvitees(invitee);
    List<AssistantVo> toUnBlockAssistantList = new ArrayList<>();
    toUnBlockAssistantList.add(assistantToUnBlock);
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantUnBlocked(ChatResponse<List<AssistantVo>> response) {
            print("Assistant unblocked");
            prettyLog(response.getJson());
            toUnBlockAssistantList.clear();
            toUnBlockAssistantList.addAll(response.getResult());
            chat.removeListener(this);
            resumeProcess();
        }
    });
    ChatListener mMockedListener = Mockito.mock(ChatListener.class);
    chat.addListener(mMockedListener);
    BlockUnblockAssistantRequest requestBlock = new BlockUnblockAssistantRequest.Builder(toUnBlockAssistantList, false).build();
    chat.unBlockAssistant(requestBlock);
    pauseProcess();
    ArrayList<AssistantVo> blockedListInCache = new ArrayList<>();
    chat.addListener(new ChatListener() {

        @Override
        public void onAssistantBlocks(ChatResponse<List<AssistantVo>> response) {
            print("Blocked assistants list cache: " + response.isCache());
            prettyLog(response.getJson());
            if (response.isCache()) {
                blockedListInCache.addAll(response.getResult());
                chat.removeListener(this);
                resumeProcess();
            }
        }
    });
    GetBlockedAssistantsRequest getBlockedAssistantsRequest2 = new GetBlockedAssistantsRequest.Builder().build();
    chat.getBlocksAssistant(getBlockedAssistantsRequest2);
    pauseProcess();
    Assert.assertTrue(blockedListInCache.stream().noneMatch(assistantVo -> assistantVo.getParticipantVO().getId() == toUnBlockAssistantList.get(0).getParticipantVO().getId()));
}
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) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 18 with AssistantVo

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

the class ChatTestIntegration method getAssistantTest.

@Test
@LargeTest
public void getAssistantTest() {
    long startTime = System.currentTimeMillis();
    ChatListener historyListeners = new ChatListener() {

        @Override
        public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
            System.out.println("onGetAssistants: " + response);
            Assert.assertTrue(true);
            resumeProcess();
        }
    };
    chat.addListener(historyListeners);
    getAssistants();
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ChatResponse(com.fanap.podchat.model.ChatResponse) 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 19 with AssistantVo

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

the class ChatTestSandbox method deActiveAssistant.

private void deActiveAssistant() {
    // 52987   khodam
    // 103187  nemati
    // invite
    Invitee invite = new Invitee("52987", InviteType.Constants.TO_BE_USER_CONTACT_ID);
    List<AssistantVo> assistantVos = new ArrayList<>();
    AssistantVo assistantVo = new AssistantVo();
    assistantVo.setInvitees(invite);
    assistantVos.add(assistantVo);
    DeActiveAssistantRequest request = new DeActiveAssistantRequest.Builder(assistantVos).build();
    presenter.deActiveAssistant(request);
    pauseProcess();
}
Also used : Invitee(com.fanap.podchat.mainmodel.Invitee) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ArrayList(java.util.ArrayList) DeActiveAssistantRequest(com.fanap.podchat.chat.assistant.request_model.DeActiveAssistantRequest)

Example 20 with AssistantVo

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

the class ChatTestSandbox method registerAssistantsTest.

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

        @Override
        public void onRegisterAssistant(ChatResponse<List<AssistantVo>> response) {
            System.out.println("onRegisterAssistant: " + response.getJson());
            Assert.assertTrue(true);
        }
    };
    chat.addListener(historyListeners);
    registerAssistant();
}
Also used : AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ChatResponse(com.fanap.podchat.model.ChatResponse) 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)

Aggregations

AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)25 ArrayList (java.util.ArrayList)19 LargeTest (android.support.test.filters.LargeTest)15 ChatListener (com.fanap.podchat.chat.ChatListener)15 Test (org.junit.Test)15 Invitee (com.fanap.podchat.mainmodel.Invitee)13 ChatResponse (com.fanap.podchat.model.ChatResponse)10 List (java.util.List)9 RegisterAssistantRequest (com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest)8 GetAssistantRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest)7 FlakyTest (android.support.test.filters.FlakyTest)6 MediumTest (android.support.test.filters.MediumTest)6 BlockUnblockAssistantRequest (com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest)5 GetAssistantHistoryRequest (com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest)5 Contact (com.fanap.podchat.mainmodel.Contact)5 Participant (com.fanap.podchat.mainmodel.Participant)5 ResultContact (com.fanap.podchat.model.ResultContact)5 AssistantHistoryVo (com.fanap.podchat.chat.assistant.model.AssistantHistoryVo)4 GetBlockedAssistantsRequest (com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest)4 RequestGetContact (com.fanap.podchat.requestobject.RequestGetContact)4