use of com.google.api.gax.longrunning.OperationSnapshot 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.api.gax.longrunning.OperationSnapshot 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);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ProtoOperationTransformersTest method testResponseTransformer.
@Test
public void testResponseTransformer() {
ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
Money inputMoney = Money.newBuilder().setCurrencyCode("UAH").build();
OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("Madrid").setMetadata(2).setDone(true).setResponse(inputMoney).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 ApiMessageOperationTransformersTest method testResponseTransformer_mismatchedTypes.
@Test
public void testResponseTransformer_mismatchedTypes() {
ResponseTransformer<EmptyMessage> transformer = ResponseTransformer.create(EmptyMessage.class);
FakeMetadataMessage<?> metadata = new FakeMetadataMessage<>(Status.PENDING, Code.OK);
ApiMessage bananaResponse = new FakeApiMessage(ImmutableMap.<String, Object>of("name", "banana"), null, null);
OperationSnapshot operationSnapshot = new OperationSnapshotImpl(new FakeOperationMessage<>("No response method", bananaResponse, metadata));
try {
transformer.apply(operationSnapshot);
Assert.fail("ResponseTransformer should have thrown an exception");
} catch (ApiException expected) {
Truth.assertThat(expected).hasMessageThat().contains("cannot be cast");
}
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ApiMessageOperationTransformersTest method testResponseTransformer_exception.
@Test
public void testResponseTransformer_exception() {
ResponseTransformer<EmptyMessage> transformer = ResponseTransformer.create(EmptyMessage.class);
EmptyMessage emptyResponse = EmptyMessage.getDefaultInstance();
FakeMetadataMessage<?> metadata = new FakeMetadataMessage<>(Status.PENDING, Code.UNAVAILABLE);
OperationSnapshot operationSnapshot = new OperationSnapshotImpl(new FakeOperationMessage<>("Unavailable; no response method", emptyResponse, metadata));
try {
transformer.apply(operationSnapshot);
Assert.fail("ResponseTransformer should have thrown an exception");
} catch (UnavailableException expected) {
Truth.assertThat(expected).hasMessageThat().contains("Unavailable; no response method");
}
}
Aggregations