use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class TextMessagesQueueTest method populateMessagesFromServerOrCache.
public void populateMessagesFromServerOrCache() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
System.out.println("Received Message List, Cache: " + history.isCache() + " Content: " + 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();
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class TextMessagesQueueTest method sendMessageFromSendingQueue.
@Test
public void sendMessageFromSendingQueue() {
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);
chat.resumeChat();
Mockito.verify(mTestListener, Mockito.after(5000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ThreadCacheTest method checkThreadsAreSameInCacheAndServer.
public void checkThreadsAreSameInCacheAndServer() {
for (Thread threadInServer : threadsInServer) {
if (threadInServer == null)
continue;
Thread threadInCache = threadsInCache.stream().filter(thread -> thread.getId() == threadInServer.getId()).findFirst().get();
System.out.println(">>>>>>>>>>> Thread in server " + threadInServer.getTitle());
System.out.println(">>>>>>>>>>> Thread in cache " + threadInCache.getTitle());
Assert.assertEquals(threadInServer.getId(), threadInCache.getId());
System.out.println(">>>>>>>>>>> Threads are same " + threadInCache.getTitle() + " threadId : " + threadInCache.getId());
Assert.assertNotNull(threadInServer.getLastMessageVO());
Assert.assertNotNull(threadInCache.getLastMessageVO());
System.out.println(">>>>>>>>>>> Last message in cache " + threadInCache.getLastMessageVO().getMessage());
System.out.println(">>>>>>>>>>> Last message in server " + threadInServer.getLastMessageVO().getMessage());
Assert.assertEquals(threadInCache.getLastMessage(), threadInCache.getLastMessageVO().getMessage());
}
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ThreadCacheTest method sendMessage.
public void sendMessage() {
populateThreadsFromServer();
Collections.shuffle(threadsInServer);
Thread thread = threadsInServer.get(0);
System.out.println("Thread : " + thread.getTitle());
Assert.assertNotNull(thread);
chatListeners = new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
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("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(request, null);
}
use of com.fanap.podchat.mainmodel.Thread 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();
}
Aggregations