Search in sources :

Example 6 with HttpBinJSON

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

the class RestProxyTests method putRequestWithUnexpectedResponseAndExceptionType.

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

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

the class RestProxyTests method putRequestWithUnexpectedResponseAndDeterminedExceptionType.

@Test
public void putRequestWithUnexpectedResponseAndDeterminedExceptionType() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service9.class).putWithUnexpectedResponseAndDeterminedExceptionType("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, "putRequestWithUnexpectedResponseAndDeterminedExceptionType");
    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 8 with HttpBinJSON

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

the class RestProxyTests method service16Put.

@Test
public void service16Put() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    final Service16 service16 = createService(Service16.class);
    final byte[] expectedBytes = new byte[] { 1, 2, 3, 4 };
    service16.putByteArray(expectedBytes, 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, "service16Put");
    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);
        assertTrue(json.data() instanceof String);
        final String base64String = (String) json.data();
        final byte[] actualBytes = base64String.getBytes();
        assertArrayEquals(expectedBytes, actualBytes);
    // httpbin sends the data back as a string like "\u0001\u0002\u0003\u0004"
    }
}
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 9 with HttpBinJSON

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

the class RestProxyTests method putRequestWithUnexpectedResponseAndNoFallthroughExceptionType.

@Test
public void putRequestWithUnexpectedResponseAndNoFallthroughExceptionType() {
    CountDownLatch latch = new CountDownLatch(1);
    CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
    createService(Service9.class).putWithUnexpectedResponseAndNoFallthroughExceptionType("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, "putRequestWithUnexpectedResponseAndNoFallthroughExceptionType");
    if (cbResult.response != null) {
        fail("Expected HttpResponseException would be thrown.");
    } else {
        Assertions.assertNotNull(cbResult.error);
        Assertions.assertTrue(cbResult.error instanceof HttpResponseException, "Expected HttpResponseException would be thrown. Instead got " + cbResult.error.getClass().getSimpleName());
        HttpResponseException e = (HttpResponseException) cbResult.error;
        assertNotNull(e.getValue());
        assertTrue(e.getValue() instanceof LinkedHashMap);
        @SuppressWarnings("unchecked") final LinkedHashMap<String, String> expectedBody = (LinkedHashMap<String, String>) e.getValue();
        assertEquals("I'm the body!", expectedBody.get("data"));
    }
}
Also used : HttpResponseException(com.azure.android.core.http.exception.HttpResponseException) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedHashMap(java.util.LinkedHashMap) 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)

Example 10 with HttpBinJSON

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

the class RestProxyTests method service19PutWithHeaderApplicationOctetStreamContentTypeAndStringBodyWithEmptyBody.

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

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