use of com.google.type.Money in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testBidiStreaming.
@Test
public void testBidiStreaming() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
stream.send(request);
stream.closeSend();
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNull();
Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
assertThat(moneyObserver.response).isEqualTo(expected);
assertThat(moneyObserver.completed).isTrue();
}
use of com.google.type.Money in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testBidiStreamingServerError.
@Test
public void testBidiStreamingServerError() throws Exception {
BidiStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createBidiStreamingCallable(GrpcCallSettings.create(METHOD_STREAMING_RECOGNIZE_ERROR), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
GrpcDirectServerStreamingCallableTest.MoneyObserver moneyObserver = new GrpcDirectServerStreamingCallableTest.MoneyObserver(true, latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ClientStream<Color> stream = streamingCallable.splitCall(moneyObserver);
stream.send(request);
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNotNull();
assertThat(moneyObserver.error).isInstanceOf(ApiException.class);
assertThat(moneyObserver.error.getCause()).isInstanceOf(StatusRuntimeException.class);
assertThat(((StatusRuntimeException) moneyObserver.error.getCause()).getStatus()).isEqualTo(Status.INVALID_ARGUMENT);
assertThat(moneyObserver.response).isNull();
}
use of com.google.type.Money in project gax-java by googleapis.
the class GrpcDirectStreamingCallableTest method testClientStreaming.
@Test
public void testClientStreaming() throws Exception {
ClientStreamingCallable<Color, Money> streamingCallable = GrpcCallableFactory.createClientStreamingCallable(GrpcCallSettings.create(METHOD_CLIENT_STREAMING_RECOGNIZE), null, clientContext);
CountDownLatch latch = new CountDownLatch(1);
MoneyObserver moneyObserver = new MoneyObserver(latch);
Color request = Color.newBuilder().setRed(0.5f).build();
ApiStreamObserver<Color> requestObserver = streamingCallable.clientStreamingCall(moneyObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
latch.await(20, TimeUnit.SECONDS);
assertThat(moneyObserver.error).isNull();
Money expected = Money.newBuilder().setCurrencyCode("USD").setUnits(127).build();
assertThat(moneyObserver.response).isEqualTo(expected);
assertThat(moneyObserver.completed).isTrue();
}
use of com.google.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyResponseTransformer_mismatchedTypes.
@Test
public void testAnyResponseTransformer_mismatchedTypes() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Status status = Status.newBuilder().setCode(Code.OK.getNumber()).build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setResponse(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.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyMetadataTransformer.
@Test
public void testAnyMetadataTransformer() {
MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setMetadata(Any.pack(inputMoney)).build());
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
Aggregations