use of com.azure.android.communication.chat.models.ChatMessage 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.ChatMessage in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canUpdateExistingMessage.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canUpdateExistingMessage(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
UpdateChatMessageOptions updateMessageRequest = super.updateMessageOptions();
final String messageId = this.chatThreadClient.sendMessage(messageRequest).get().getId();
this.chatThreadClient.updateMessage(messageId, updateMessageRequest).get();
final ChatMessage message = chatThreadClient.getMessage(messageId).get();
assertEquals(message.getContent().getMessage(), updateMessageRequest.getContent());
assertEquals(message.getMetadata().containsKey("tags"), false);
assertEquals(message.getMetadata().get("deliveryMode"), updateMessageRequest.getMetadata().get("deliveryMode"));
assertEquals(message.getMetadata().get("onedriveReferences"), updateMessageRequest.getMetadata().get("onedriveReferences"));
assertEquals(message.getMetadata().get("amsreferences"), messageRequest.getMetadata().get("amsreferences"));
assertEquals(message.getMetadata().get("key"), messageRequest.getMetadata().get("key"));
}
use of com.azure.android.communication.chat.models.ChatMessage in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canUpdateExistingMessageWithResponse.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canUpdateExistingMessageWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
UpdateChatMessageOptions updateMessageRequest = super.updateMessageOptions();
CompletableFuture<Response<SendChatMessageResult>> completableFuture1 = this.chatThreadClient.sendMessageWithResponse(messageRequest, null);
Response<SendChatMessageResult> sendResponse = completableFuture1.get();
assertNotNull(sendResponse);
final String messageId = sendResponse.getValue().getId();
assertNotNull(messageId);
CompletableFuture<Response<Void>> completableFuture2 = this.chatThreadClient.updateMessageWithResponse(messageId, updateMessageRequest, null);
Response<Void> updateResponse = completableFuture2.get();
assertNotNull(updateResponse);
assertEquals(204, updateResponse.getStatusCode());
CompletableFuture<Response<ChatMessage>> completableFuture3 = chatThreadClient.getMessageWithResponse(messageId, null);
Response<ChatMessage> getResponse = completableFuture3.get();
assertNotNull(getResponse);
ChatMessage message = getResponse.getValue();
assertEquals(message.getContent().getMessage(), updateMessageRequest.getContent());
assertEquals(message.getMetadata().containsKey("tags"), false);
assertEquals(message.getMetadata().get("deliveryMode"), updateMessageRequest.getMetadata().get("deliveryMode"));
assertEquals(message.getMetadata().get("onedriveReferences"), updateMessageRequest.getMetadata().get("onedriveReferences"));
assertEquals(message.getMetadata().get("amsreferences"), messageRequest.getMetadata().get("amsreferences"));
assertEquals(message.getMetadata().get("key"), messageRequest.getMetadata().get("key"));
}
use of com.azure.android.communication.chat.models.ChatMessage in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canSendThenGetMessageWithResponse.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canSendThenGetMessageWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
CompletableFuture<Response<SendChatMessageResult>> completableFuture1 = this.chatThreadClient.sendMessageWithResponse(messageRequest, null);
Response<SendChatMessageResult> response1 = completableFuture1.get();
assertNotNull(response1);
final String messageId = response1.getValue().getId();
CompletableFuture<Response<ChatMessage>> completableFuture2 = this.chatThreadClient.getMessageWithResponse(messageId, null);
Response<ChatMessage> response2 = completableFuture2.get();
assertNotNull(response2);
final ChatMessage message = response2.getValue();
assertEquals(message.getContent().getMessage(), messageRequest.getContent());
assertEquals(message.getType(), messageRequest.getType());
assertEquals(message.getSenderDisplayName(), messageRequest.getSenderDisplayName());
assertEquals(message.getMetadata(), messageRequest.getMetadata());
}
use of com.azure.android.communication.chat.models.ChatMessage in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method canSendThenGetMessage.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canSendThenGetMessage(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
SendChatMessageOptions messageRequest = super.sendMessageOptions();
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());
}
Aggregations