Search in sources :

Example 86 with Response

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

the class RestProxyTests method getRequestWithAnythingWithEncodedPathParam.

@Test
public void getRequestWithAnythingWithEncodedPathParam() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service5.class).getAnythingWithEncodedPathParam("withpathparam", 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, "getRequestWithAnythingWithEncodedPathParam");
    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/withpathparam", 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 87 with Response

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

the class RestProxyTests method service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithNonEmptyBody.

@Test
public void service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithNonEmptyBody() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service19.class).putWithBodyParamApplicationOctetStreamContentTypeAndStringBody("penguins", 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, "service19PutWithBodyParamApplicationOctetStreamContentTypeAndStringBodyWithNonEmptyBody");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        HttpBinJSON json = response.getValue();
        Assertions.assertNotNull(json);
        assertEquals("penguins", 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 88 with Response

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

the class RestProxyTests method service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWithEmptyBody.

@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWithEmptyBody() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service19.class).putWithHeaderApplicationJsonContentTypeAndByteArrayBody(new byte[0], 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, "service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWithEmptyBody");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        HttpBinJSON json = response.getValue();
        Assertions.assertNotNull(json);
        assertEquals("\"\"", 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 89 with Response

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

the class RestProxyTests method service18GetStatus500WithExpectedResponse500.

@Test
public void service18GetStatus500WithExpectedResponse500() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<Void> cbResult = new CallbackResult<>();
    createService(Service18.class).getStatus500WithExpectedResponse500(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, "service18GetStatus500WithExpectedResponse500");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<Void> response = cbResult.response;
        Assertions.assertEquals(500, response.getStatusCode());
    }
}
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 90 with Response

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

the class RestProxyTests method service24Put.

@Test
public void service24Put() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    final Map<String, String> headerCollection = new HashMap<>();
    headerCollection.put("DEF", "GHIJ");
    headerCollection.put("123", "45");
    createService(Service24.class).put(headerCollection, 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, "service24Put");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        assertNotNull(response);
        assertEquals(200, response.getStatusCode());
        HttpBinJSON result = response.getValue();
        assertNotNull(result.headers());
        final HttpHeaders resultHeaders = new HttpHeaders(result.headers());
        assertEquals("GHIJ", resultHeaders.getValue("ABCDEF"));
        assertEquals("45", resultHeaders.getValue("ABC123"));
    }
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CountDownLatch(java.util.concurrent.CountDownLatch) Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) HttpBinJSON(com.azure.android.core.test.implementation.entities.HttpBinJSON) Test(org.junit.jupiter.api.Test)

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