use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClient method deleteTopic.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes the topic with the given name. Returns `NOT_FOUND` if the topic does not exist. After a
* topic is deleted, a new topic may be created with the same name; this is an entirely new topic
* with none of the old configuration or subscriptions. Existing subscriptions to this topic are
* not deleted, but their `topic` field is set to `_deleted-topic_`.
*
* <p>Sample code:
*
* <pre><code>
* try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
* TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
* topicAdminClient.deleteTopic(topic);
* }
* </code></pre>
*
* @param topic Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteTopic(TopicName topic) {
DeleteTopicRequest request = DeleteTopicRequest.newBuilder().setTopicWithTopicName(topic).build();
deleteTopic(request);
}
use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSnapshotTest.
@Test
@SuppressWarnings("all")
public void createSnapshotTest() {
SnapshotName name2 = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
Snapshot expectedResponse = Snapshot.newBuilder().setNameWithSnapshotName(name2).setTopicWithTopicName(topic).build();
mockSubscriber.addResponse(expectedResponse);
SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
Snapshot actualResponse = client.createSnapshot(name, subscription);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSnapshotRequest actualRequest = (CreateSnapshotRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsSnapshotName());
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method getTopicExceptionTest.
@Test
@SuppressWarnings("all")
public void getTopicExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
client.getTopic(topic);
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 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.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method deleteTopicExceptionTest.
@Test
@SuppressWarnings("all")
public void deleteTopicExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);
try {
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
client.deleteTopic(topic);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
Aggregations