Search in sources :

Example 1 with AllowedPayload

use of org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload in project spring-cloud-gcp by spring-cloud.

the class PubSubTemplateTests method testPublish_Object.

@Test
public void testPublish_Object() throws IOException {
    AllowedPayload allowedPayload = new AllowedPayload();
    allowedPayload.name = "allowed";
    allowedPayload.value = 12345;
    PubSubPublisherTemplate pubSubPublisherTemplate = spy(createPublisherTemplate());
    doAnswer((invocation) -> {
        PubsubMessage message = invocation.getArgument(1);
        assertThat(message.getData().toStringUtf8()).isEqualTo("{\"@class\":" + "\"org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload\"" + ",\"name\":\"allowed\",\"value\":12345}");
        return null;
    }).when(pubSubPublisherTemplate).publish(eq("test"), any());
    pubSubPublisherTemplate.publish("test", allowedPayload);
    verify(pubSubPublisherTemplate, times(1)).publish(eq("test"), isA(PubsubMessage.class));
}
Also used : PubSubPublisherTemplate(org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate) AllowedPayload(org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload) PubsubMessage(com.google.pubsub.v1.PubsubMessage) Test(org.junit.Test)

Aggregations

PubsubMessage (com.google.pubsub.v1.PubsubMessage)1 Test (org.junit.Test)1 PubSubPublisherTemplate (org.springframework.cloud.gcp.pubsub.core.publisher.PubSubPublisherTemplate)1 AllowedPayload (org.springframework.cloud.gcp.pubsub.core.test.allowed.AllowedPayload)1