Search in sources :

Example 51 with HttpBinJSON

use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.

the class RestProxyTests method service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWithNonEmptyBody.

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

use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.

the class RestProxyTests method requestWithMultipleHostParams.

@Test
public void requestWithMultipleHostParams() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service17.class).get("local", "host", 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, "requestWithMultipleHostParams");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        Assertions.assertNotNull(response);
        Assertions.assertNotNull(response.getValue());
        HttpBinJSON json = response.getValue();
        assertNotNull(json);
        assertMatchWithHttpOrHttps("localhost/get", 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 53 with HttpBinJSON

use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.

the class RestProxyTests method service20GetResponseBody.

@Test
public void service20GetResponseBody() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service20.class).putBody("body string", 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, "service20GetResponseBody");
    if (cbResult.error != null) {
        Assertions.fail(cbResult.error);
    } else {
        final Response<HttpBinJSON> response = cbResult.response;
        assertNotNull(response);
        assertEquals(200, response.getStatusCode());
        final HttpBinJSON body = response.getValue();
        assertNotNull(body);
        assertMatchWithHttpOrHttps("localhost/put", body.url());
        assertEquals("body string", body.data());
        final HttpHeaders headers = response.getHeaders();
        assertNotNull(headers);
    }
}
Also used : Response(com.azure.android.core.rest.Response) StreamResponse(com.azure.android.core.rest.StreamResponse) HttpHeaders(com.azure.android.core.http.HttpHeaders) CountDownLatch(java.util.concurrent.CountDownLatch) HttpBinJSON(com.azure.android.core.test.implementation.entities.HttpBinJSON) Test(org.junit.jupiter.api.Test)

Example 54 with HttpBinJSON

use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.

the class RestProxyTests method service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWithNullBody.

@Test
public void service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWithNullBody() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service19.class).putWithBodyParamApplicationJsonContentTypeAndStringBody(null, 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, "service19PutWithBodyParamApplicationJsonContentTypeAndStringBodyWithNullBody");
    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 55 with HttpBinJSON

use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.

the class RestProxyTests method getRequestWithQueryParametersAndAnythingWithEncodedWithPercent20.

@Test
public void getRequestWithQueryParametersAndAnythingWithEncodedWithPercent20() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service6.class).getAnythingWithEncoded("x%20y", 15, 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, "getRequestWithQueryParametersAndAnythingWithEncodedWithPercent20");
    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?a=x y&b=15", 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)

Aggregations

HttpBinJSON (com.azure.android.core.test.implementation.entities.HttpBinJSON)69 CountDownLatch (java.util.concurrent.CountDownLatch)68 Test (org.junit.jupiter.api.Test)68 Response (com.azure.android.core.rest.Response)67 StreamResponse (com.azure.android.core.rest.StreamResponse)67 HttpHeaders (com.azure.android.core.http.HttpHeaders)6 MyRestException (com.azure.android.core.test.MyRestException)3 LinkedHashMap (java.util.LinkedHashMap)3 HttpResponseException (com.azure.android.core.http.exception.HttpResponseException)2 HashMap (java.util.HashMap)2 HttpClient (com.azure.android.core.http.HttpClient)1 HttpPipeline (com.azure.android.core.http.HttpPipeline)1 HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)1 HttpResponse (com.azure.android.core.http.HttpResponse)1 HttpLogOptions (com.azure.android.core.http.policy.HttpLogOptions)1 HttpLoggingPolicy (com.azure.android.core.http.policy.HttpLoggingPolicy)1 PortPolicy (com.azure.android.core.http.policy.PortPolicy)1 ResponseBase (com.azure.android.core.rest.ResponseBase)1 HttpBinFormDataJSON (com.azure.android.core.test.implementation.entities.HttpBinFormDataJSON)1 HttpBinHeaders (com.azure.android.core.test.implementation.entities.HttpBinHeaders)1