use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testMetadataTransformer.
@Test
public void testMetadataTransformer() {
MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("UAH").build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("Barcelona").setMetadata(inputMoney).setDone(true).setResponse("Gary").setError(0, "no error").build();
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyMetadataTransformer_mismatchedTypes.
@Test
public void testAnyMetadataTransformer_mismatchedTypes() {
MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
Status status = Status.newBuilder().setCode(Code.OK.getNumber()).build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setMetadata(Any.pack(Color.getDefaultInstance())).setError(status).build());
Exception exception = assertThrows(UnknownException.class, () -> transformer.apply(operationSnapshot));
Truth.assertThat(exception).hasMessageThat().contains("encountered a problem unpacking it");
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyResponseTransformer_exception.
@Test
public void testAnyResponseTransformer_exception() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.getNumber()).build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build());
Exception exception = assertThrows(UnavailableException.class, () -> transformer.apply(operationSnapshot));
Truth.assertThat(exception).hasMessageThat().contains("failed with status = HttpJsonStatusCode{statusCode=UNAVAILABLE}");
}
use of com.google.api.gax.longrunning.OperationSnapshot in project java-bigtable by googleapis.
the class BigtableTableAdminClientTest method mockOperationResult.
private <ReqT, RespT, MetaT> void mockOperationResult(OperationCallable<ReqT, RespT, MetaT> callable, ReqT request, RespT response, MetaT metadata) {
OperationSnapshot operationSnapshot = FakeOperationSnapshot.newBuilder().setDone(true).setErrorCode(GrpcStatusCode.of(Code.OK)).setName("fake-name").setResponse(response).setMetadata(metadata).build();
OperationFuture<RespT, MetaT> operationFuture = OperationFutures.immediateOperationFuture(operationSnapshot);
Mockito.when(callable.futureCall(request)).thenReturn(operationFuture);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method mockOperationResult.
private <ReqT, RespT, MetaT> void mockOperationResult(OperationCallable<ReqT, RespT, MetaT> callable, ReqT request, RespT response) {
OperationSnapshot operationSnapshot = FakeOperationSnapshot.newBuilder().setDone(true).setErrorCode(GrpcStatusCode.of(Code.OK)).setName("fake-name").setResponse(response).build();
OperationFuture<RespT, MetaT> operationFuture = OperationFutures.immediateOperationFuture(operationSnapshot);
Mockito.when(callable.futureCall(request)).thenReturn(operationFuture);
}
Aggregations