Search in sources :

Example 96 with Response

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

the class RestProxyTests method putRequestWithIntBody.

@Test
public void putRequestWithIntBody() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service9.class).put(42, new Callback<Response<HttpBinJSON>>() {

        @Override
        public void onSuccess(Response<HttpBinJSON> response) {
            cbResult.response = response;
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable error) {
            cbResult.error = error;
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "putRequestWithIntBody");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        Assertions.assertNotNull(response);
        HttpBinJSON json = response.getValue();
        Assertions.assertNotNull(json);
        assertEquals(String.class, json.data().getClass());
        assertEquals("42", json.data());
    }
}
Also used : Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) CountDownLatch(java.util.concurrent.CountDownLatch) HttpBinJSON(com.azure.android.core.test.implementation.entities.HttpBinJSON) Test(org.junit.jupiter.api.Test)

Example 97 with Response

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

the class RestProxyTests method syncVoidHeadRequest.

@Test
public void syncVoidHeadRequest() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<Void> cbResult = new CallbackResult<>();
    createService(Service10.class).voidHead(new Callback<Response<Void>>() {

        @Override
        public void onSuccess(Response<Void> response) {
            cbResult.response = response;
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable error) {
            cbResult.error = error;
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "syncVoidHeadRequest");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<Void> response = cbResult.response;
        Assertions.assertNotNull(response);
        Assertions.assertNull(response.getValue());
    }
}
Also used : Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 98 with Response

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

the class RestProxyTests method putRequestWithUnexpectedResponseAndFallthroughExceptionType.

@Test
public void putRequestWithUnexpectedResponseAndFallthroughExceptionType() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service9.class).putWithUnexpectedResponseAndFallthroughExceptionType("I'm the body!", new Callback<Response<HttpBinJSON>>() {

        @Override
        public void onSuccess(Response<HttpBinJSON> response) {
            cbResult.response = response;
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable error) {
            cbResult.error = error;
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "putRequestWithUnexpectedResponseAndFallthroughExceptionType");
    if (cbResult.response != null) {
        fail("Expected HttpResponseException would be thrown.");
    } else {
        Assertions.assertNotNull(cbResult.error);
        Assertions.assertTrue(cbResult.error instanceof MyRestException, "Expected MyRestException would be thrown. Instead got " + cbResult.error.getClass().getSimpleName());
        MyRestException e = (MyRestException) cbResult.error;
        assertNotNull(e.getValue());
        assertEquals("I'm the body!", e.getValue().data());
    }
}
Also used : Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) MyRestException(com.azure.android.core.test.MyRestException) CountDownLatch(java.util.concurrent.CountDownLatch) HttpBinJSON(com.azure.android.core.test.implementation.entities.HttpBinJSON) Test(org.junit.jupiter.api.Test)

Example 99 with Response

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

the class ChatAsyncImplClientTest method canGetExistingChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canGetExistingChatThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadMember.getId(), secondThreadMember.getId());
    CompletableFuture<Response<CreateChatThreadResult>> completableFuture1 = this.client.getChatClient().createChatThreadWithResponseAsync(threadRequest, null);
    assertNotNull(completableFuture1);
    Response<CreateChatThreadResult> response1 = completableFuture1.get();
    assertNotNull(response1);
    CreateChatThreadResult result1 = response1.getValue();
    assertNotNull(result1);
    assertNotNull(result1.getChatThread());
    assertNotNull(result1.getChatThread().getId());
    String expectedThreadId = result1.getChatThread().getId();
    CompletableFuture<Response<ChatThreadProperties>> completableFuture2 = this.client.getChatThreadClient().getChatThreadPropertiesWithResponseAsync(expectedThreadId);
    assertNotNull(completableFuture2);
    Response<ChatThreadProperties> response2 = completableFuture2.get();
    assertNotNull(response2);
    ChatThreadProperties result2 = response2.getValue();
    assertNotNull(result2);
    assertNotNull(result2.getId());
    assertEquals(expectedThreadId, result2.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.implementation.models.CreateChatThreadResult) ChatThreadProperties(com.azure.android.communication.chat.implementation.models.ChatThreadProperties) CreateChatThreadOptions(com.azure.android.communication.chat.implementation.models.CreateChatThreadOptions) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 100 with Response

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

the class ChatAsyncImplClientTest method getNotFoundOnNonExistingChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void getNotFoundOnNonExistingChatThreadWithResponse(HttpClient httpClient) {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        CompletableFuture<Response<ChatThreadProperties>> completableFuture = client.getChatThreadClient().getChatThreadPropertiesWithResponseAsync("19:00000000000000000000000000000000@thread.v2", null);
        completableFuture.get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof CommunicationErrorResponseException);
    HttpResponseException exception = (HttpResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(404, exception.getResponse().getStatusCode());
}
Also used : Response(com.azure.android.core.rest.Response) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpResponseException(com.azure.android.core.http.exception.HttpResponseException) ExecutionException(java.util.concurrent.ExecutionException) CommunicationErrorResponseException(com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException) 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