use of com.google.pubsub.v1.ListSubscriptionsRequest 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.pubsub.v1.ListSubscriptionsRequest 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