use of com.fanap.podchat.chat.ChatListener 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());
}
use of com.fanap.podchat.chat.ChatListener 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());
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateMessagesFromServer.
public void populateMessagesFromServer() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (!history.isCache()) {
print("Received Message List Server: " + content);
threadMessagesList.addAll(history.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
}
use of com.fanap.podchat.chat.ChatListener 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));
}
}
use of com.fanap.podchat.chat.ChatListener in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateMessagesFromCache.
public void populateMessagesFromCache() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (history.isCache()) {
print("Received Message List Cache: " + content);
threadMessagesList.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
}
Aggregations