use of com.google.protobuf.Field in project gax-java by googleapis.
the class HttpJsonDirectCallableTest method testErrorUnaryResponse.
@Test
public void testErrorUnaryResponse() throws InterruptedException {
HttpJsonDirectCallable<Field, Field> callable = new HttpJsonDirectCallable<>(FAKE_METHOD_DESCRIPTOR);
HttpJsonCallContext callContext = HttpJsonCallContext.createDefault().withChannel(channel);
Field request;
request = // "echo" service
Field.newBuilder().setName("imTheBestField").setNumber(2).setCardinality(Cardinality.CARDINALITY_OPTIONAL).setDefaultValue("blah").build();
ApiException exception = ApiExceptionFactory.createException(new Exception(), FakeStatusCode.of(Code.NOT_FOUND), false);
MOCK_SERVICE.addException(exception);
try {
callable.futureCall(request, callContext).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
HttpResponseException respExp = (HttpResponseException) e.getCause();
assertThat(respExp.getStatusCode()).isEqualTo(400);
assertThat(respExp.getContent()).isEqualTo(exception.toString());
}
}
Aggregations