Search in sources :

Example 31 with Money

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");
}
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 32 with Money

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

Example 33 with Money

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

Example 34 with Money

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");
}
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 35 with Money

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}");
}
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)

Aggregations

Money (com.google.type.Money)35 Test (org.junit.Test)28 Color (com.google.type.Color)19 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)13 ManagedChannel (io.grpc.ManagedChannel)8 UnavailableException (com.google.api.gax.rpc.UnavailableException)6 UnknownException (com.google.api.gax.rpc.UnknownException)6 Status (com.google.rpc.Status)6 Metadata (io.grpc.Metadata)6 CallOptions (io.grpc.CallOptions)5 Channel (io.grpc.Channel)5 ClientCall (io.grpc.ClientCall)4 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)3 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)3 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)3 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)3 LocationName (com.google.cloud.aiplatform.v1.LocationName)3 Value (com.google.protobuf.Value)3 Deadline (io.grpc.Deadline)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3