use of com.azure.android.communication.chat.models.ListChatMessagesOptions in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canListMessagesWithOptions.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListMessagesWithOptions(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
ListChatMessagesOptions options = new ListChatMessagesOptions();
options.setMaxPageSize(10);
options.setStartTime(OffsetDateTime.parse("2020-09-08T01:02:14.387Z"));
this.chatThreadClient.sendMessage(messageRequest).get();
this.chatThreadClient.sendMessage(messageRequest).get();
PagedAsyncStream<ChatMessage> messagePagedAsyncStream = this.chatThreadClient.listMessages(options, null);
CountDownLatch latch = new CountDownLatch(1);
List<ChatMessage> returnedMessages = new ArrayList<ChatMessage>();
messagePagedAsyncStream.forEach(new AsyncStreamHandler<ChatMessage>() {
@Override
public void onNext(ChatMessage message) {
if (message.getType().equals(ChatMessageType.TEXT)) {
returnedMessages.add(message);
}
}
@Override
public void onError(Throwable throwable) {
latch.countDown();
}
@Override
public void onComplete() {
latch.countDown();
}
});
awaitOnLatch(latch, "canListMessagesWithOptions");
assertTrue(returnedMessages.size() > 0);
}
use of com.azure.android.communication.chat.models.ListChatMessagesOptions in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canListMessages.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListMessages(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
this.chatThreadClient.sendMessage(messageRequest).get();
this.chatThreadClient.sendMessage(messageRequest).get();
PagedAsyncStream<ChatMessage> messagePagedAsyncStream = this.chatThreadClient.listMessages(new ListChatMessagesOptions(), null);
CountDownLatch latch = new CountDownLatch(1);
List<ChatMessage> returnedMessages = new ArrayList<ChatMessage>();
messagePagedAsyncStream.forEach(new AsyncStreamHandler<ChatMessage>() {
@Override
public void onNext(ChatMessage message) {
if (message.getType().equals(ChatMessageType.TEXT)) {
returnedMessages.add(message);
}
}
@Override
public void onError(Throwable throwable) {
latch.countDown();
}
@Override
public void onComplete() {
latch.countDown();
}
});
awaitOnLatch(latch, "canListMessages");
assertTrue(returnedMessages.size() > 0);
}
Aggregations