use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringBodyWithNonEmptyBody.
@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringBodyWithNonEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithHeaderApplicationJsonContentTypeAndCharsetAndStringBody("soups and stuff", 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, "service19PutWithHeaderApplicationJsonContentTypeAndCharsetAndStringBodyWithEmptyBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
HttpBinJSON json = response.getValue();
Assertions.assertNotNull(json);
assertEquals("soups and stuff", json.data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithHeaderApplicationOctetStreamContentTypeAndStringBodyWithNonEmptyBody.
@Test
public void service19PutWithHeaderApplicationOctetStreamContentTypeAndStringBodyWithNonEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithHeaderApplicationOctetStreamContentTypeAndStringBody("penguins", 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("penguins", json.data());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service23GetBytes.
@Test
public void service23GetBytes() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<byte[]> cbResult = new CallbackResult<>();
createService(Service23.class).getBytes(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, "service23GetBytes");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<byte[]> response = cbResult.response;
assertNotNull(response);
assertEquals(200, response.getStatusCode());
byte[] bytes = response.getValue();
assertNotNull(bytes);
assertEquals(28, bytes.length);
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method service19PutWithHeaderApplicationJsonContentTypeAndStringBodyWithEmptyBody.
@Test
public void service19PutWithHeaderApplicationJsonContentTypeAndStringBodyWithEmptyBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service19.class).putWithHeaderApplicationJsonContentTypeAndStringBody("", 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, "service19PutWithHeaderApplicationJsonContentTypeAndStringBodyWithEmptyBody");
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 putRequestWithUnexpectedResponse.
// @Test
// public void putRequestWithBodyLessThanContentLength() {
// CountDownLatch latch = new CountDownLatch(1);
// CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
//
// final byte[] body = "test".getBytes(StandardCharsets.UTF_8);
// createService(Service9.class).putBodyAndContentLength(body, 5L,
// 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, "putRequestWithBodyLessThanContentLength");
//
// if (cbResult.error == null) {
// Assertions.fail();
// } else {
// final Throwable error = cbResult.error;
// Assertions.assertNotNull(error);
// Assertions.assertTrue(error instanceof UnexpectedLengthException);
// assertTrue(((UnexpectedLengthException) error).getMessage().contains("less than"));
// }
// }
//
// @Test
// public void putRequestWithBodyMoreThanContentLength() {
// CountDownLatch latch = new CountDownLatch(1);
// CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
//
// final byte[] body = "test".getBytes(StandardCharsets.UTF_8);
// createService(Service9.class).putBodyAndContentLength(body, 3L,
// 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, "putRequestWithBodyLessThanContentLength");
//
// if (cbResult.error == null) {
// Assertions.fail();
// } else {
// final Throwable error = cbResult.error;
// Assertions.assertNotNull(error);
// Assertions.assertTrue(error instanceof UnexpectedLengthException);
// assertTrue(((UnexpectedLengthException) error).getMessage().contains("more than"));
// }
// }
@Test
public void putRequestWithUnexpectedResponse() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service9.class).putWithUnexpectedResponse("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, "putRequestWithUnexpectedResponse");
if (cbResult.response != null) {
fail("Expected HttpResponseException would be thrown.");
} else {
Assertions.assertNotNull(cbResult.error);
Assertions.assertTrue(cbResult.error instanceof HttpResponseException);
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"));
}
}
Aggregations