Search in sources :

Example 1 with ListChatMessagesOptions

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);
}
Also used : ChatMessage(com.azure.android.communication.chat.models.ChatMessage) SendChatMessageOptions(com.azure.android.communication.chat.models.SendChatMessageOptions) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ListChatMessagesOptions(com.azure.android.communication.chat.models.ListChatMessagesOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with ListChatMessagesOptions

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);
}
Also used : ChatMessage(com.azure.android.communication.chat.models.ChatMessage) SendChatMessageOptions(com.azure.android.communication.chat.models.SendChatMessageOptions) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ListChatMessagesOptions(com.azure.android.communication.chat.models.ListChatMessagesOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ChatMessage (com.azure.android.communication.chat.models.ChatMessage)2 ListChatMessagesOptions (com.azure.android.communication.chat.models.ListChatMessagesOptions)2 SendChatMessageOptions (com.azure.android.communication.chat.models.SendChatMessageOptions)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2