use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method deleteRequest.
@Test
public void deleteRequest() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service11.class).delete(false, 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, "deleteRequest");
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();
assertEquals(String.class, json.data().getClass());
assertEquals("false", json.data());
}
}
use of com.azure.android.core.rest.Response 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());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service18GetStatus200WithExpectedResponse200.
@Test
public void service18GetStatus200WithExpectedResponse200() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<Void> cbResult = new CallbackResult<>();
createService(Service18.class).getStatus200WithExpectedResponse200(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, "service18GetStatus200WithExpectedResponse200");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<Void> response = cbResult.response;
Assertions.assertEquals(200, response.getStatusCode());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service20GetVoidResponse.
@Test
public void service20GetVoidResponse() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<Void> cbResult = new CallbackResult<>();
createService(Service20.class).getVoidResponse(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, "service20PutBodyAndHeaders");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<Void> response = cbResult.response;
assertNotNull(response);
assertEquals(200, response.getStatusCode());
}
}
use of com.azure.android.core.rest.Response 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());
}
}
Aggregations