use of com.azure.android.core.rest.Response 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.rest.Response in project azure-sdk-for-android by Azure.
the class RestProxyTests method syncVoidHeadRequest.
@Test
public void syncVoidHeadRequest() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<Void> cbResult = new CallbackResult<>();
createService(Service10.class).voidHead(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, "syncVoidHeadRequest");
if (cbResult.error != null) {
Assertions.fail(cbResult.error);
} else {
final Response<Void> response = cbResult.response;
Assertions.assertNotNull(response);
Assertions.assertNull(response.getValue());
}
}
use of com.azure.android.core.rest.Response 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());
}
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class ChatAsyncImplClientTest method canGetExistingChatThreadWithResponse.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void canGetExistingChatThreadWithResponse(HttpClient httpClient) throws ExecutionException, InterruptedException {
setupTest(httpClient);
final CreateChatThreadOptions threadRequest = createThreadOptions(firstThreadMember.getId(), secondThreadMember.getId());
CompletableFuture<Response<CreateChatThreadResult>> completableFuture1 = this.client.getChatClient().createChatThreadWithResponseAsync(threadRequest, null);
assertNotNull(completableFuture1);
Response<CreateChatThreadResult> response1 = completableFuture1.get();
assertNotNull(response1);
CreateChatThreadResult result1 = response1.getValue();
assertNotNull(result1);
assertNotNull(result1.getChatThread());
assertNotNull(result1.getChatThread().getId());
String expectedThreadId = result1.getChatThread().getId();
CompletableFuture<Response<ChatThreadProperties>> completableFuture2 = this.client.getChatThreadClient().getChatThreadPropertiesWithResponseAsync(expectedThreadId);
assertNotNull(completableFuture2);
Response<ChatThreadProperties> response2 = completableFuture2.get();
assertNotNull(response2);
ChatThreadProperties result2 = response2.getValue();
assertNotNull(result2);
assertNotNull(result2.getId());
assertEquals(expectedThreadId, result2.getId());
}
use of com.azure.android.core.rest.Response in project azure-sdk-for-android by Azure.
the class ChatAsyncImplClientTest method getNotFoundOnNonExistingChatThreadWithResponse.
@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void getNotFoundOnNonExistingChatThreadWithResponse(HttpClient httpClient) {
setupTest(httpClient);
ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
CompletableFuture<Response<ChatThreadProperties>> completableFuture = client.getChatThreadClient().getChatThreadPropertiesWithResponseAsync("19:00000000000000000000000000000000@thread.v2", null);
completableFuture.get();
});
Throwable cause = executionException.getCause();
assertNotNull(cause);
assertTrue(cause instanceof CommunicationErrorResponseException);
HttpResponseException exception = (HttpResponseException) cause;
assertNotNull(exception.getResponse());
assertEquals(404, exception.getResponse().getStatusCode());
}
Aggregations