Search in sources :

Example 6 with ChatMessage

use of com.azure.android.communication.chat.models.ChatMessage 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)

Example 7 with ChatMessage

use of com.azure.android.communication.chat.models.ChatMessage in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method canSendThenGetHtmlMessage.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canSendThenGetHtmlMessage(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    SendChatMessageOptions messageRequest = new SendChatMessageOptions().setType(ChatMessageType.HTML).setSenderDisplayName("John").setContent("<div>test</div>").setMetadata(new HashMap<String, String>() {

        {
            put("tags", "");
            put("deliveryMode", "deliveryMode value - updated");
            put("onedriveReferences", "onedriveReferences - updated");
            put("amsreferences", "[\\\"test url file 3\\\"]");
        }
    });
    final String messageId = this.chatThreadClient.sendMessage(messageRequest).get().getId();
    final ChatMessage message = this.chatThreadClient.getMessage(messageId).get();
    assertEquals(message.getContent().getMessage(), messageRequest.getContent());
    assertEquals(message.getType(), messageRequest.getType());
    assertEquals(message.getSenderDisplayName(), messageRequest.getSenderDisplayName());
    assertEquals(message.getMetadata(), messageRequest.getMetadata());
}
Also used : ChatMessage(com.azure.android.communication.chat.models.ChatMessage) SendChatMessageOptions(com.azure.android.communication.chat.models.SendChatMessageOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

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