Search in sources :

Example 6 with OperationSnapshot

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");
}
Also used : Status(com.google.rpc.Status) Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) UnknownException(com.google.api.gax.rpc.UnknownException) UnavailableException(com.google.api.gax.rpc.UnavailableException) Test(org.junit.Test)

Example 7 with OperationSnapshot

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);
}
Also used : Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Example 8 with OperationSnapshot

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);
}
Also used : Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Example 9 with OperationSnapshot

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");
    }
}
Also used : FakeApiMessage(com.google.api.gax.httpjson.testing.FakeApiMessage) FakeApiMessage(com.google.api.gax.httpjson.testing.FakeApiMessage) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) ApiException(com.google.api.gax.rpc.ApiException) Test(org.junit.Test)

Example 10 with OperationSnapshot

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");
    }
}
Also used : UnavailableException(com.google.api.gax.rpc.UnavailableException) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Aggregations

OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)55 Test (org.junit.Test)44 FakeOperationSnapshot (com.google.api.gax.rpc.testing.FakeOperationSnapshot)28 Color (java.awt.Color)23 Currency (java.util.Currency)23 Money (com.google.type.Money)13 UnavailableException (com.google.api.gax.rpc.UnavailableException)7 UnknownException (com.google.api.gax.rpc.UnknownException)6 Status (com.google.rpc.Status)6 FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)4 ExecutionException (java.util.concurrent.ExecutionException)4 FakeApiClock (com.google.api.gax.core.FakeApiClock)2 FakeApiMessage (com.google.api.gax.httpjson.testing.FakeApiMessage)2 TimedRetryAlgorithm (com.google.api.gax.retrying.TimedRetryAlgorithm)2 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 ApiException (com.google.api.gax.rpc.ApiException)2 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)2 CancellationException (java.util.concurrent.CancellationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1