use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method getTopicTest.
@Test
@SuppressWarnings("all")
public void getTopicTest() {
TopicName name = TopicName.create("[PROJECT]", "[TOPIC]");
Topic expectedResponse = Topic.newBuilder().setNameWithTopicName(name).build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
Topic actualResponse = client.getTopic(topic);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetTopicRequest actualRequest = (GetTopicRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method createTopicExceptionTest.
@Test
@SuppressWarnings("all")
public void createTopicExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
TopicName name = TopicName.create("[PROJECT]", "[TOPIC]");
client.createTopic(name);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.TopicName 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());
}
}
use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method deleteTopicTest.
@Test
@SuppressWarnings("all")
public void deleteTopicTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
client.deleteTopic(topic);
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteTopicRequest actualRequest = (DeleteTopicRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Aggregations