use of com.google.type.Money 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.value()).build();
OperationSnapshot operationSnapshot = GrpcOperationSnapshot.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.type.Money in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testAnyResponseTransformer.
@Test
public void testAnyResponseTransformer() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(inputMoney)).build());
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
use of com.google.type.Money 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.type.Money 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.type.Money 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}");
}
Aggregations