Search in sources :

Example 6 with CreateChatThreadResult

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

the class ChatAsyncClientTest method canCreateThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canCreateThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture = this.client.createChatThreadWithResponse(threadRequest, null);
    assertNotNull(completableFuture);
    Response<CreateChatThreadResult> response = completableFuture.get();
    assertNotNull(response);
    CreateChatThreadResult result = response.getValue();
    assertNotNull(result);
    assertNotNull(result.getChatThreadProperties());
    assertNotNull(result.getChatThreadProperties().getId());
}
Also used : Response(com.azure.android.core.rest.Response) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with CreateChatThreadResult

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

the class ChatAsyncClientTest method canRepeatCreateThread.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canRepeatCreateThread(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    UUID uuid = UUID.randomUUID();
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId()).setIdempotencyToken(uuid.toString());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture1 = this.client.createChatThreadWithResponse(threadRequest, null);
    assertNotNull(completableFuture1);
    Response<CreateChatThreadResult> response1 = completableFuture1.get();
    assertNotNull(response1);
    CreateChatThreadResult result1 = response1.getValue();
    assertNotNull(result1);
    assertNotNull(result1.getChatThreadProperties());
    assertNotNull(result1.getChatThreadProperties().getId());
    String expectedThreadId = response1.getValue().getChatThreadProperties().getId();
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture2 = this.client.createChatThreadWithResponse(threadRequest, null);
    assertNotNull(completableFuture2);
    Response<CreateChatThreadResult> response2 = completableFuture2.get();
    assertNotNull(response2);
    CreateChatThreadResult result2 = response2.getValue();
    assertNotNull(result2);
    assertNotNull(result2.getChatThreadProperties());
    assertNotNull(result2.getChatThreadProperties().getId());
    assertEquals(expectedThreadId, result2.getChatThreadProperties().getId());
    threadRequest.setIdempotencyToken(UUID.randomUUID().toString());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture3 = this.client.createChatThreadWithResponse(threadRequest, null);
    assertNotNull(completableFuture3);
    Response<CreateChatThreadResult> response3 = completableFuture3.get();
    assertNotNull(response3);
    CreateChatThreadResult result3 = response3.getValue();
    assertNotNull(result3);
    assertNotNull(result3.getChatThreadProperties());
    assertNotNull(result3.getChatThreadProperties().getId());
    assertNotEquals(expectedThreadId, result3.getChatThreadProperties().getId());
}
Also used : Response(com.azure.android.core.rest.Response) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) UUID(java.util.UUID) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with CreateChatThreadResult

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

the class ChatAsyncClientTest method canListChatThreads.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canListChatThreads(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<CreateChatThreadResult> completableFuture1 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture1);
    CreateChatThreadResult result1 = completableFuture1.get();
    assertNotNull(result1);
    assertNotNull(result1.getChatThreadProperties());
    assertNotNull(result1.getChatThreadProperties().getId());
    CompletableFuture<CreateChatThreadResult> completableFuture2 = this.client.createChatThread(threadRequest);
    assertNotNull(completableFuture2);
    CreateChatThreadResult result2 = completableFuture1.get();
    assertNotNull(result2);
    assertNotNull(result2.getChatThreadProperties());
    assertNotNull(result2.getChatThreadProperties().getId());
    PagedAsyncStream<ChatThreadItem> chatAsyncStream = this.client.listChatThreads(new ListChatThreadsOptions(), null);
    CountDownLatch latch = new CountDownLatch(1);
    AtomicBoolean gotNullResponse = new AtomicBoolean();
    AtomicBoolean gotNullList = new AtomicBoolean();
    List<ChatThreadItem> returnedThreads = new ArrayList<ChatThreadItem>();
    chatAsyncStream.byPage().forEach(new AsyncStreamHandler<PagedResponse<ChatThreadItem>>() {

        @Override
        public void onNext(PagedResponse<ChatThreadItem> response) {
            if (!gotNullResponse.get()) {
                gotNullResponse.set(response == null);
            }
            if (response != null) {
                List<ChatThreadItem> threadsInPage = response.getValue();
                if (!gotNullList.get()) {
                    gotNullResponse.set(threadsInPage == null);
                }
                if (threadsInPage != null) {
                    for (ChatThreadItem thread : threadsInPage) {
                        returnedThreads.add(thread);
                    }
                }
            }
        }

        @Override
        public void onError(Throwable throwable) {
            latch.countDown();
        }

        @Override
        public void onComplete() {
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "canListChatThreads");
    Assertions.assertFalse(gotNullResponse.get());
    Assertions.assertFalse(gotNullList.get());
// REVISIT: Unreliable assert
// assertTrue(returnedThreads.size() > 0);
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ArrayList(java.util.ArrayList) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) CountDownLatch(java.util.concurrent.CountDownLatch) ListChatThreadsOptions(com.azure.android.communication.chat.models.ListChatThreadsOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ChatThreadItem(com.azure.android.communication.chat.models.ChatThreadItem) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) ArrayList(java.util.ArrayList) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with CreateChatThreadResult

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

the class ChatAsyncClientTest method canCreateNewThreadWithoutSettingRepeatabilityID.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canCreateNewThreadWithoutSettingRepeatabilityID(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest1 = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture1 = this.client.createChatThreadWithResponse(threadRequest1, null);
    assertNotNull(completableFuture1);
    Response<CreateChatThreadResult> response1 = completableFuture1.get();
    assertNotNull(response1);
    CreateChatThreadResult result1 = response1.getValue();
    assertNotNull(result1);
    assertNotNull(result1.getChatThreadProperties());
    assertNotNull(result1.getChatThreadProperties().getId());
    String threadId1 = response1.getValue().getChatThreadProperties().getId();
    // Create new CreateChatThreadOptions to get new RepeatabilityID.
    final CreateChatThreadOptions threadRequest2 = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture2 = this.client.createChatThreadWithResponse(threadRequest2, null);
    assertNotNull(completableFuture2);
    Response<CreateChatThreadResult> response2 = completableFuture2.get();
    assertNotNull(response2);
    CreateChatThreadResult result2 = response2.getValue();
    assertNotNull(result2);
    assertNotNull(result2.getChatThreadProperties());
    assertNotNull(result2.getChatThreadProperties().getId());
    assertNotEquals(threadId1, result2.getChatThreadProperties().getId());
}
Also used : Response(com.azure.android.core.rest.Response) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with CreateChatThreadResult

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

the class ChatThreadAsyncClientTest method setupTest.

private void setupTest(HttpClient httpClient) throws ExecutionException, InterruptedException {
    this.client = super.getChatClientBuilder(httpClient).buildAsyncClient();
    this.firstThreadParticipant = new CommunicationUserIdentifier(THREAD_PARTICIPANT_1);
    this.secondThreadParticipant = new CommunicationUserIdentifier(THREAD_PARTICIPANT_2);
    CreateChatThreadOptions threadRequest = createThreadOptions(this.firstThreadParticipant.getId(), this.secondThreadParticipant.getId());
    CreateChatThreadResult createChatThreadResult = client.createChatThread(threadRequest).get();
    this.chatThreadClient = client.getChatThreadClient(createChatThreadResult.getChatThreadProperties().getId());
    this.threadId = chatThreadClient.getChatThreadId();
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) CreateChatThreadOptions(com.azure.android.communication.chat.models.CreateChatThreadOptions) CommunicationUserIdentifier(com.azure.android.communication.common.CommunicationUserIdentifier)

Aggregations

CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)13 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)6 Response (com.azure.android.core.rest.Response)5 ArrayList (java.util.ArrayList)4 ChatThreadProperties (com.azure.android.communication.chat.models.ChatThreadProperties)3 ChatThreadItem (com.azure.android.communication.chat.models.ChatThreadItem)2 ListChatThreadsOptions (com.azure.android.communication.chat.models.ListChatThreadsOptions)2 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CommunicationError (com.azure.android.communication.chat.implementation.models.CommunicationError)1 ChatError (com.azure.android.communication.chat.models.ChatError)1 ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1