use of org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage in project spring-cloud-gcp by spring-cloud.
the class PubSubTemplateIntegrationTests method testPubSubTemplateLoadsMessageConverter.
@Test
public void testPubSubTemplateLoadsMessageConverter() {
this.contextRunner.withUserConfiguration(JsonPayloadTestConfiguration.class).run((context) -> {
PubSubAdmin pubSubAdmin = context.getBean(PubSubAdmin.class);
PubSubTemplate pubSubTemplate = context.getBean(PubSubTemplate.class);
String topicName = "json-payload-topic" + UUID.randomUUID();
String subscriptionName = "json-payload-subscription" + UUID.randomUUID();
pubSubAdmin.createTopic(topicName);
pubSubAdmin.createSubscription(subscriptionName, topicName, 10);
TestUser user = new TestUser("John", "password");
pubSubTemplate.publish(topicName, user);
await().atMost(Duration.TEN_SECONDS).untilAsserted(() -> {
List<ConvertedAcknowledgeablePubsubMessage<TestUser>> messages = pubSubTemplate.pullAndConvert(subscriptionName, 1, true, TestUser.class);
assertThat(messages).hasSize(1);
TestUser receivedTestUser = messages.get(0).getPayload();
assertThat(receivedTestUser.username).isEqualTo("John");
assertThat(receivedTestUser.password).isEqualTo("password");
});
pubSubAdmin.deleteSubscription(subscriptionName);
pubSubAdmin.deleteTopic(topicName);
});
}
Aggregations