Search in sources :

Example 1 with MyRestException

use of com.azure.android.core.test.MyRestException 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 2 with MyRestException

use of com.azure.android.core.test.MyRestException 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 3 with MyRestException

use of com.azure.android.core.test.MyRestException in project azure-sdk-for-android by Azure.

the class RestProxyTests method putRequestWithUnexpectedResponseAndFallthroughExceptionType.

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

Aggregations

Response (com.azure.android.core.rest.Response)3 StreamResponse (com.azure.android.core.rest.StreamResponse)3 MyRestException (com.azure.android.core.test.MyRestException)3 HttpBinJSON (com.azure.android.core.test.implementation.entities.HttpBinJSON)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.jupiter.api.Test)3