Search in sources :

Example 46 with HttpBinJSON

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

the class RestProxyTests method service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringBodyWithNullBody.

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

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

the class RestProxyTests method getRequestWithQueryParametersAndAnything.

@Test
public void getRequestWithQueryParametersAndAnything() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service6.class).getAnything("A", 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, "getRequestWithQueryParametersAndAnything");
    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=A&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)

Example 48 with HttpBinJSON

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

the class RestProxyTests method headersRequest.

@Test
public void headersRequest() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service13.class).get(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, "headersRequest");
    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/anything", json.url());
        assertNotNull(json.headers());
        final HttpHeaders headers = new HttpHeaders(json.headers());
        assertEquals("MyHeaderValue", headers.getValue("MyHeader"));
        assertArrayEquals(new String[] { "MyHeaderValue" }, headers.getValues("MyHeader"));
        assertEquals("My,Header,Value", headers.getValue("MyOtherHeader"));
        assertArrayEquals(new String[] { "My", "Header", "Value" }, headers.getValues("MyOtherHeader"));
    }
}
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 49 with HttpBinJSON

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

the class RestProxyTests method service19PutWithHeaderApplicationJsonContentTypeAndByteArrayBodyWithNonEmptyBody.

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

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

the class RestProxyTests method service19PutWithNoContentTypeAndStringBodyWithNonEmptyBody.

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

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