use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method listTopicSubscriptions.
/** Example of listing topics for a subscription. */
public ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topicId) throws Exception {
// [START pubsub_list_topic_subscriptions]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder().setTopicWithTopicName(topicName).build();
ListTopicSubscriptionsPagedResponse response = topicAdminClient.listTopicSubscriptions(request);
Iterable<String> subscriptionNames = response.iterateAll();
for (String subscriptionName : subscriptionNames) {
// do something with the subscription name
}
return response;
}
// [END pubsub_list_topic_subscriptions]
}
use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicSubscriptionsTest.
@Test
@SuppressWarnings("all")
public void listTopicSubscriptionsTest() {
String nextPageToken = "";
SubscriptionName subscriptionsElement = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<SubscriptionName> subscriptions = Arrays.asList(subscriptionsElement);
ListTopicSubscriptionsResponse expectedResponse = ListTopicSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptionsWithSubscriptionNameList(subscriptions).build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsPagedResponse pagedListResponse = client.listTopicSubscriptions(topic);
List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
List<SubscriptionName> resourceNames = Lists.newArrayList(pagedListResponse.iterateAllAsSubscriptionName());
Assert.assertEquals(1, resourceNames.size());
Assert.assertEquals(expectedResponse.getSubscriptionsListAsSubscriptionNameList().get(0), resourceNames.get(0));
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTopicSubscriptionsRequest actualRequest = (ListTopicSubscriptionsRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class ITTopicAdminClientSnippets method listTopicSubscriptionsRetrievesAddedSubscriptions.
@Test
public void listTopicSubscriptionsRetrievesAddedSubscriptions() throws Exception {
List<String> addedSubscriptions = new ArrayList<>();
String topicName1 = topics[0];
topicAdminClientSnippets.createTopic(topicName1);
String subscriptionName1 = subscriptions[0];
String subscriptionName2 = subscriptions[1];
addedSubscriptions.add(createSubscription(topicName1, subscriptionName1));
addedSubscriptions.add(createSubscription(topicName1, subscriptionName2));
boolean[] subFound = { false, false };
ListTopicSubscriptionsPagedResponse response = topicAdminClientSnippets.listTopicSubscriptions(topicName1);
assertNotNull(response);
Iterable<String> subscriptions = response.iterateAll();
for (int i = 0; i < 2; i++) {
if (!subFound[i]) {
subFound[i] = Iterables.contains(subscriptions, addedSubscriptions.get(i));
}
}
assertTrue(subFound[0] && subFound[1]);
}
Aggregations