use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method testIfConversationAreSame.
@Test
public void testIfConversationAreSame() {
populateMessagesFromServer();
assert threadMessagesList.size() > 0;
Collections.shuffle(threadMessagesList);
MessageVO message = threadMessagesList.get(0);
assert message.getConversation() != null;
Thread thread = message.getConversation();
chat.setListener(new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
}
});
RequestMessage repRequest = new RequestMessage.Builder("Message at " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(repRequest, null);
pauseProcess();
// Load Server messages
ArrayList<MessageVO> msgFromServer = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (!history.isCache()) {
System.out.println("Received Message List Server: " + content);
msgFromServer.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
// Load cache
ArrayList<MessageVO> msgFromCache = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (history.isCache()) {
System.out.println("Received Message List Cache: " + content);
msgFromCache.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistoryCache, null);
pauseProcess();
assert msgFromServer.size() > 0;
assert msgFromCache.size() > 0;
assert msgFromCache.size() == msgFromServer.size();
for (MessageVO msg : msgFromServer) {
if (msg.getMessage() == null)
continue;
System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " Conversation: " + msg.getConversation());
MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getConversation());
Assert.assertEquals(msg.getConversation() != null, msgInCache.getConversation() != null);
if (msg.getConversation() != null) {
Assert.assertEquals(msg.getConversation().getId(), msgInCache.getConversation().getId());
}
}
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method sendMessageToThreadAndGetFromCache.
@Test
public void sendMessageToThreadAndGetFromCache() {
populateThreadsListFromServerOrCache();
assert threads.size() > 0;
Thread thread = threads.get(0);
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
String msgText = "Android Test " + new Date();
RequestMessage request = new RequestMessage.Builder(msgText, thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(request, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
sleep(2000);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistory, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getMessage().equals(msgText))));
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method testIfReplyInfoVOsAreTheSame.
@Test
public void testIfReplyInfoVOsAreTheSame() {
populateMessagesFromServer();
assert threadMessagesList.size() > 0;
Collections.shuffle(threadMessagesList);
MessageVO message = threadMessagesList.get(0);
assert message.getConversation() != null;
Thread thread = message.getConversation();
chat.setListener(new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
}
});
RequestReplyMessage repRequest = new RequestReplyMessage.Builder("Reply to " + message.getMessage(), thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
chat.replyMessage(repRequest, null);
pauseProcess();
// Load Server messages
ArrayList<MessageVO> msgFromServer = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (!history.isCache()) {
System.out.println("Received Message List Server: " + content);
msgFromServer.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
// Load cache
ArrayList<MessageVO> msgFromCache = new ArrayList<>();
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (history.isCache()) {
System.out.println("Received Message List Cache: " + content);
msgFromCache.addAll(history.getResult().getHistory());
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistoryCache = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistoryCache, null);
pauseProcess();
assert msgFromServer.size() > 0;
assert msgFromCache.size() > 0;
assert msgFromCache.size() == msgFromServer.size();
for (MessageVO msg : msgFromServer) {
if (msg.getMessage() == null)
continue;
System.out.println(">>>>>>>>>>> Server Message " + msg.getMessage() + " RepInfo: " + msg.getReplyInfoVO());
MessageVO msgInCache = msgFromCache.stream().filter(messageVO -> messageVO.getId() == msg.getId()).findFirst().get();
System.out.println(">>>>>>>>>>> Cache Message " + msgInCache.getMessage() + " RepInfo: " + msgInCache.getReplyInfoVO());
Assert.assertEquals(msg.getReplyInfoVO() != null, msgInCache.getReplyInfoVO() != null);
if (msg.getReplyInfoVO() != null) {
Assert.assertEquals(msg.getReplyInfoVO().getMessage(), msgInCache.getReplyInfoVO().getMessage());
Assert.assertEquals(msg.getReplyInfoVO().getMetadata(), msgInCache.getReplyInfoVO().getMetadata());
Assert.assertEquals(msg.getReplyInfoVO().getRepliedToMessageTime(), msgInCache.getReplyInfoVO().getRepliedToMessageTime());
Assert.assertEquals(msg.getReplyInfoVO().getRepliedToMessageNanos(), msgInCache.getReplyInfoVO().getRepliedToMessageNanos());
Assert.assertEquals(msg.getReplyInfoVO().getSystemMetadata(), msgInCache.getReplyInfoVO().getSystemMetadata());
if (msg.getReplyInfoVO().getParticipant() != null) {
Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getName(), msgInCache.getReplyInfoVO().getParticipant().getName());
Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getContactFirstName(), msgInCache.getReplyInfoVO().getParticipant().getContactFirstName());
Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getCellphoneNumber(), msgInCache.getReplyInfoVO().getParticipant().getCellphoneNumber());
Assert.assertEquals(msg.getReplyInfoVO().getParticipant().getAdmin(), msgInCache.getReplyInfoVO().getParticipant().getAdmin());
}
}
}
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class ChatTestIntegration method getThreadHistoryBeforeAndAfterLastSeenMessage.
@Test
@LargeTest
public // and greater in second case
void getThreadHistoryBeforeAndAfterLastSeenMessage() {
populateThreadsListFromServerOrCache();
System.out.println("** Get history of " + threads.get(0).getTitle());
Thread thread = threads.get(0);
final long lastSeen = thread.getLastSeenMessageTime() + thread.getLastSeenMessageNanos();
AtomicInteger numOfCacheResp = new AtomicInteger(0);
ChatListener historyListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
int invokeTimes = 0;
if (history.isCache()) {
invokeTimes = numOfCacheResp.getAndIncrement();
}
checkTimesIsValid(history, invokeTimes, lastSeen);
if (invokeTimes >= 2) {
resumeProcess();
}
}
};
chat.addListener(historyListeners);
RequestGetHistory requestGetHistoryBeforeLastSeenTime = new RequestGetHistory.Builder(thread.getId()).toTimeNanos(lastSeen).offset(0).count(25).order("desc").build();
presenter.getHistory(requestGetHistoryBeforeLastSeenTime, null);
RequestGetHistory requestGetHistoryAfterLastSeenTime = new RequestGetHistory.Builder(thread.getId()).fromTimeNanos(lastSeen).offset(0).count(25).order("asc").build();
presenter.getHistory(requestGetHistoryAfterLastSeenTime, null);
pauseProcess();
sleep(2000);
Mockito.verify(view, Mockito.atLeast(2)).onGetThreadHistory(Mockito.any());
}
use of com.fanap.podchat.requestobject.RequestGetHistory in project pod-chat-android-sdk by FanapSoft.
the class TextMessagesQueueTest 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()) {
System.out.println("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