Search in sources :

Example 46 with Response

use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.

the class ChatAsyncClientTest method canDeleteChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canDeleteChatThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadParticipant.getId(), secondThreadParticipant.getId());
    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());
    CompletableFuture<Response<Void>> completableFuture2 = this.client.deleteChatThreadWithResponse(result1.getChatThreadProperties().getId(), null);
    assertNotNull(completableFuture2);
    Response<Void> response2 = completableFuture2.get();
    assertNotNull(response2);
    Void result2 = response2.getValue();
    assertNull(result2);
}
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 47 with Response

use of com.azure.android.core.rest.Response 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 48 with Response

use of com.azure.android.core.rest.Response 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 49 with Response

use of com.azure.android.core.rest.Response 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 50 with Response

use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.

the class ChatThreadAsyncClientTest method getNotFoundOnNonExistingChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void getNotFoundOnNonExistingChatThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        CompletableFuture<Response<ChatThreadProperties>> completableFuture = client.getChatThreadClient("19:00000000000000000000000000000000@thread.v2").getPropertiesWithResponse(null);
        completableFuture.get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof ChatErrorResponseException);
    ChatErrorResponseException exception = (ChatErrorResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(404, exception.getResponse().getStatusCode());
}
Also used : Response(com.azure.android.core.rest.Response) ChatErrorResponseException(com.azure.android.communication.chat.models.ChatErrorResponseException) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Response (com.azure.android.core.rest.Response)105 StreamResponse (com.azure.android.core.rest.StreamResponse)88 CountDownLatch (java.util.concurrent.CountDownLatch)88 Test (org.junit.jupiter.api.Test)88 HttpBinJSON (com.azure.android.core.test.implementation.entities.HttpBinJSON)67 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 MethodSource (org.junit.jupiter.params.provider.MethodSource)17 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)10 CreateChatThreadOptions (com.azure.android.communication.chat.implementation.models.CreateChatThreadOptions)5 CreateChatThreadResult (com.azure.android.communication.chat.implementation.models.CreateChatThreadResult)5 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)5 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)5 HttpHeaders (com.azure.android.core.http.HttpHeaders)5 HttpResponseException (com.azure.android.core.http.exception.HttpResponseException)5 SendChatMessageOptions (com.azure.android.communication.chat.models.SendChatMessageOptions)4 MyRestException (com.azure.android.core.test.MyRestException)3 LinkedHashMap (java.util.LinkedHashMap)3 UUID (java.util.UUID)3 ChatMessage (com.azure.android.communication.chat.models.ChatMessage)2 SendChatMessageResult (com.azure.android.communication.chat.models.SendChatMessageResult)2