use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.
the class RestProxyTests method postRequestWithStringBody.
@Test
public void postRequestWithStringBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service8.class).post("I'm a post 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, "postRequestWithStringBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
Assertions.assertNotNull(response);
HttpBinJSON json = response.getValue();
assertEquals(String.class, json.data().getClass());
assertEquals("I'm a post body!", json.data());
}
}
use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.
the class RestProxyTests method getRequestWithAnythingWithPlus.
@Test
public void getRequestWithAnythingWithPlus() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service5.class).getAnythingWithPlus(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, "getRequestWithAnythingWithPlus");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
Assertions.assertNotNull(response);
HttpBinJSON json = response.getValue();
assertNotNull(json);
assertMatchWithHttpOrHttps("localhost/anything/with+plus", json.url());
}
}
use of com.azure.android.core.test.implementation.entities.HttpBinJSON in project azure-sdk-for-android by Azure.
the class RestProxyTests method putRequestWithIntBody.
@Test
public void putRequestWithIntBody() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service9.class).put(42, 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, "putRequestWithIntBody");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<HttpBinJSON> response = cbResult.response;
Assertions.assertNotNull(response);
HttpBinJSON json = response.getValue();
Assertions.assertNotNull(json);
assertEquals(String.class, json.data().getClass());
assertEquals("42", json.data());
}
}
use of com.azure.android.core.test.implementation.entities.HttpBinJSON 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());
}
}
Aggregations