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.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.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class ApiMessageOperationTransformersTest method testMetadataTransformer_mismatchedTypes.
@Test
public void testMetadataTransformer_mismatchedTypes() {
MetadataTransformer<FakeOperationMessage> transformer = MetadataTransformer.create(FakeOperationMessage.class);
FakeMetadataMessage<?> metadataMessage = new FakeMetadataMessage<>(Status.PENDING, Code.OK);
ApiMessage bananaResponse = new FakeApiMessage(ImmutableMap.<String, Object>of("name", "banana"), null, null);
FakeOperationMessage<?, ?> metadata = new FakeOperationMessage<>("No response method", bananaResponse, metadataMessage);
OperationSnapshot operationSnapshot = new OperationSnapshotImpl(metadata);
try {
transformer.apply(operationSnapshot);
Assert.fail("MetadataTransformer 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 testMetadataTransformer.
@Test
public void testMetadataTransformer() {
MetadataTransformer<FakeMetadataMessage> transformer = MetadataTransformer.create(FakeMetadataMessage.class);
EmptyMessage returnType = EmptyMessage.getDefaultInstance();
FakeMetadataMessage<?> metadataMessage = new FakeMetadataMessage<>(Status.PENDING, Code.OK);
FakeOperationMessage<?, ?> operation = new FakeOperationMessage<>("foo", returnType, metadataMessage);
OperationSnapshot operationSnapshot = new OperationSnapshotImpl(operation);
Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(metadataMessage);
}
use of com.google.api.gax.longrunning.OperationSnapshot 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");
}
use of com.google.api.gax.longrunning.OperationSnapshot 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);
}
Aggregations