use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method requestWithByteArrayReturnType.
@Test
public void requestWithByteArrayReturnType() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<byte[]> cbResult = new CallbackResult<>();
createService(Service1.class).getByteArray(new Callback<Response<byte[]>>() {
@Override
public void onSuccess(Response<byte[]> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "requestWithByteArrayReturnType");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<byte[]> response = cbResult.response;
Assertions.assertNotNull(response);
byte[] value = response.getValue();
assertNotNull(value);
assertEquals(100, value.length);
}
}
use of com.azure.android.core.rest.Response 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"
}
}
use of com.azure.android.core.rest.Response 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"));
}
}
use of com.azure.android.core.rest.Response 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());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithNoContentTypeAndStringBodyWithNullBody.
@Test
public void service19PutWithNoContentTypeAndStringBodyWithNullBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithNoContentTypeAndStringBody(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, "service19PutWithNoContentTypeAndStringBodyWithNullBody");
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());
}
}
Aggregations