use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method listSubscriptionsTest.
@Test
@SuppressWarnings("all")
public void listSubscriptionsTest() {
String nextPageToken = "";
Subscription subscriptionsElement = Subscription.newBuilder().build();
List<Subscription> subscriptions = Arrays.asList(subscriptionsElement);
ListSubscriptionsResponse expectedResponse = ListSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptions(subscriptions).build();
mockSubscriber.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListSubscriptionsPagedResponse pagedListResponse = client.listSubscriptions(project);
List<Subscription> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSubscriptionsRequest actualRequest = (ListSubscriptionsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class ITSubscriptionAdminClientSnippets method listSubscriptionsRetrievesAllAddedSubscriptions.
@Test
public void listSubscriptionsRetrievesAllAddedSubscriptions() throws Exception {
List<Subscription> addedSubscriptions = new ArrayList<>();
String topicName1 = topics[0];
String subscriptionName1 = subscriptions[0];
String topicName2 = topics[1];
String subscriptionName2 = subscriptions[1];
addedSubscriptions.add(createSubscription(topicName1, subscriptionName1));
addedSubscriptions.add(createSubscription(topicName2, subscriptionName2));
boolean[] subFound = { false, false };
ListSubscriptionsPagedResponse response = subscriptionAdminClientSnippets.listSubscriptions();
assertNotNull(response);
Iterable<Subscription> 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]);
}
use of com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method listSubscriptions.
/** Example of listing subscriptions. */
public ListSubscriptionsPagedResponse listSubscriptions() throws Exception {
// [START pubsub_list_subscriptions]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ListSubscriptionsRequest listSubscriptionsRequest = ListSubscriptionsRequest.newBuilder().setProjectWithProjectName(ProjectName.create(projectId)).build();
ListSubscriptionsPagedResponse response = subscriptionAdminClient.listSubscriptions(listSubscriptionsRequest);
Iterable<Subscription> subscriptions = response.iterateAll();
for (Subscription subscription : subscriptions) {
// do something with the subscription
}
return response;
}
// [END pubsub_list_subscriptions]
}
Aggregations