use of com.google.pubsub.v1.PubsubMessage in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method publishTest.
@Test
@SuppressWarnings("all")
public void publishTest() {
String messageIdsElement = "messageIdsElement-744837059";
List<String> messageIds = Arrays.asList(messageIdsElement);
PublishResponse expectedResponse = PublishResponse.newBuilder().addAllMessageIds(messageIds).build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
ByteString data = ByteString.copyFromUtf8("-86");
PubsubMessage messagesElement = PubsubMessage.newBuilder().setData(data).build();
List<PubsubMessage> messages = Arrays.asList(messagesElement);
PublishResponse actualResponse = client.publish(topic, messages);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
PublishRequest actualRequest = (PublishRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
Assert.assertEquals(messages, actualRequest.getMessagesList());
}
use of com.google.pubsub.v1.PubsubMessage in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method publishExceptionTest.
@Test
@SuppressWarnings("all")
public void publishExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
ByteString data = ByteString.copyFromUtf8("-86");
PubsubMessage messagesElement = PubsubMessage.newBuilder().setData(data).build();
List<PubsubMessage> messages = Arrays.asList(messagesElement);
client.publish(topic, messages);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
Aggregations