Search in sources :

Example 1 with Option

use of com.google.protobuf.Option in project gax-java by googleapis.

the class HttpJsonOperationSnapshotCallableTest method futureCallTestException.

@Test
public void futureCallTestException() throws InterruptedException {
    Option request = Option.newBuilder().setName("Arizona").build();
    Field field = Field.newBuilder().setName("Georgia").build();
    ApiCallContext context = mock(ApiCallContext.class);
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("California").setMetadata(2).setDone(true).setResponse("Florida").setError(0, "no error").build();
    SettableApiFuture<Field> settableApiFuture = SettableApiFuture.create();
    settableApiFuture.setException(new RuntimeException("Seattle"));
    when(operationSnapshotFactory.create(request, field)).thenReturn(operationSnapshot);
    when(innerCallable.futureCall(request, context)).thenReturn(settableApiFuture);
    try {
        operationSnapCallable.futureCall(request, context).get();
        Assert.fail("Exception should have been thrown");
    } catch (ExecutionException e) {
        Truth.assertThat(e).hasMessageThat().contains("Seattle");
    }
}
Also used : Field(com.google.protobuf.Field) Option(com.google.protobuf.Option) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with Option

use of com.google.protobuf.Option in project gax-java by googleapis.

the class HttpJsonOperationSnapshotCallableTest method futureCallTest.

@Test
public void futureCallTest() throws ExecutionException, InterruptedException {
    Option request = Option.newBuilder().setName("Arizona").build();
    Field field = Field.newBuilder().setName("Georgia").build();
    ApiCallContext context = mock(ApiCallContext.class);
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("California").setMetadata(2).setDone(true).setResponse("Florida").setError(0, "no error").build();
    SettableApiFuture<Field> settableApiFuture = SettableApiFuture.create();
    settableApiFuture.set(field);
    when(operationSnapshotFactory.create(request, field)).thenReturn(operationSnapshot);
    when(innerCallable.futureCall(request, context)).thenReturn(settableApiFuture);
    ApiFuture<OperationSnapshot> futureCall = operationSnapCallable.futureCall(request, context);
    Truth.assertThat(futureCall.get().getName()).isEqualTo("California");
}
Also used : Field(com.google.protobuf.Field) Option(com.google.protobuf.Option) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Aggregations

OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)2 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 Field (com.google.protobuf.Field)2 Option (com.google.protobuf.Option)2 Test (org.junit.Test)2 ExecutionException (java.util.concurrent.ExecutionException)1