use of com.fanap.podchat.mainmodel.Invitee in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method unBlockAssistantAndCheckAssistantListInCache.
@Test
public void unBlockAssistantAndCheckAssistantListInCache() {
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> assistantListInCache = new ArrayList<>();
chat.addListener(new ChatListener() {
@Override
public void onGetAssistants(ChatResponse<List<AssistantVo>> response) {
print("Receive assistants list cache: " + response.isCache());
prettyLog(response.getJson());
if (response.isCache()) {
assistantListInCache.addAll(response.getResult());
chat.removeListener(this);
resumeProcess();
}
}
});
GetAssistantRequest getAssistantRequest = new GetAssistantRequest.Builder().build();
chat.getAssistants(getAssistantRequest);
pauseProcess();
Assert.assertTrue(assistantListInCache.stream().anyMatch(assistantInCache -> assistantInCache.getParticipantVO().getId() == toUnBlockAssistantList.get(0).getParticipantVO().getId() && !assistantInCache.getBlock()));
}
use of com.fanap.podchat.mainmodel.Invitee in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method checkRegisteredAssistantInCache.
// Register new assistant and check if it is in cache
@LargeTest
@Test
public void checkRegisteredAssistantInCache() {
populateContactsFromServer();
assert contacts.size() > 0;
Collections.shuffle(contacts);
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);
final AssistantVo[] registeredAssistant = new AssistantVo[1];
ChatListener mListener = new ChatListener() {
@Override
public void onRegisterAssistant(ChatResponse<List<AssistantVo>> response) {
registeredAssistant[0] = response.getResult().get(0);
chat.removeListener(this);
resumeProcess();
}
};
chat.setListener(mListener);
RegisterAssistantRequest request = new RegisterAssistantRequest.Builder(assistantVos).build();
chat.registerAssistant(request);
pauseProcess();
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.addListener(mTestListener);
GetAssistantRequest requestGet = new GetAssistantRequest.Builder().setCount(25).setOffset(0).build();
chat.getAssistants(requestGet);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetAssistants(Mockito.argThat((ChatResponse<List<AssistantVo>> response) -> (response.isCache() && validateAssistantsAreSame(registeredAssistant[0], response.getResult()))));
}
use of com.fanap.podchat.mainmodel.Invitee 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())));
}
use of com.fanap.podchat.mainmodel.Invitee 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()));
}
use of com.fanap.podchat.mainmodel.Invitee 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();
}
Aggregations