Search in sources :

Example 41 with Response

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

the class RestProxyTests method headRequest.

@Test
public void headRequest() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<Void> cbResult = new CallbackResult<>();
    createService(Service10.class).head(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, "headRequest");
    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 42 with Response

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

the class RestProxyTests method getRequestWithAnythingWithEncodedPathParamWithPercent20.

@Test
public void getRequestWithAnythingWithEncodedPathParamWithPercent20() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service5.class).getAnythingWithEncodedPathParam("with%20path%20param", 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, "getRequestWithAnythingWithEncodedPathParamWithPercent20");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        Assertions.assertNotNull(response);
        HttpBinJSON json = response.getValue();
        assertNotNull(json);
        assertMatchWithHttpOrHttps("localhost/anything/with path param", json.url());
    }
}
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 43 with Response

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

the class RestProxyTests method postUrlFormEncoded.

@Test
public void postUrlFormEncoded() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinFormDataJSON> cbResult = new CallbackResult<>();
    Service26 service = createService(Service26.class);
    service.postEncodedForm("Foo", "123", "foo@bar.com", HttpBinFormDataJSON.PizzaSize.LARGE, Arrays.asList("Bacon", "Onion"), new Callback<Response<HttpBinFormDataJSON>>() {

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

        @Override
        public void onFailure(Throwable error) {
            cbResult.error = error;
            latch.countDown();
        }
    });
    awaitOnLatch(latch, "postUrlFormEncoded");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinFormDataJSON> response = cbResult.response;
        assertNotNull(response);
        assertEquals(200, response.getStatusCode());
        HttpBinFormDataJSON result = response.getValue();
        assertNotNull(result);
        assertNotNull(result.form());
        assertEquals("Foo", result.form().customerName());
        assertEquals("123", result.form().customerTelephone());
        assertEquals("foo@bar.com", result.form().customerEmail());
        assertEquals(HttpBinFormDataJSON.PizzaSize.LARGE, result.form().pizzaSize());
        assertEquals(2, result.form().toppings().size());
        assertEquals("Bacon", result.form().toppings().get(0));
        assertEquals("Onion", result.form().toppings().get(1));
    }
}
Also used : Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) HttpBinFormDataJSON(com.azure.android.core.test.implementation.entities.HttpBinFormDataJSON) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 44 with Response

use of com.azure.android.core.rest.Response 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"));
}
Also used : SendChatMessageResult(com.azure.android.communication.chat.models.SendChatMessageResult) UpdateChatMessageOptions(com.azure.android.communication.chat.models.UpdateChatMessageOptions) ChatMessage(com.azure.android.communication.chat.models.ChatMessage) SendChatMessageOptions(com.azure.android.communication.chat.models.SendChatMessageOptions) Response(com.azure.android.core.rest.Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 45 with Response

use of com.azure.android.core.rest.Response 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());
}
Also used : Response(com.azure.android.core.rest.Response) SendChatMessageResult(com.azure.android.communication.chat.models.SendChatMessageResult) 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

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