Search in sources :

Example 1 with FakeApiMessage

use of com.google.api.gax.httpjson.testing.FakeApiMessage 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 2 with FakeApiMessage

use of com.google.api.gax.httpjson.testing.FakeApiMessage 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");
    }
}
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)

Aggregations

FakeApiMessage (com.google.api.gax.httpjson.testing.FakeApiMessage)2 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)2 ApiException (com.google.api.gax.rpc.ApiException)2 Test (org.junit.Test)2