Search in sources :

Example 11 with Field

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());
    }
}
Also used : Field(com.google.protobuf.Field) HttpResponseException(com.google.api.client.http.HttpResponseException) ExecutionException(java.util.concurrent.ExecutionException) HttpResponseException(com.google.api.client.http.HttpResponseException) ApiException(com.google.api.gax.rpc.ApiException) ExecutionException(java.util.concurrent.ExecutionException) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Aggregations

Field (com.google.protobuf.Field)11 Test (org.junit.Test)11 StringReader (java.io.StringReader)4 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)2 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 Option (com.google.protobuf.Option)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 HttpResponseException (com.google.api.client.http.HttpResponseException)1 ApiException (com.google.api.gax.rpc.ApiException)1