Search in sources :

Example 1 with ListSubscriptionsRequest

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());
}
Also used : ListSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse) ListSubscriptionsResponse(com.google.pubsub.v1.ListSubscriptionsResponse) ProjectName(com.google.pubsub.v1.ProjectName) ListSubscriptionsRequest(com.google.pubsub.v1.ListSubscriptionsRequest) ByteString(com.google.protobuf.ByteString) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with ListSubscriptionsRequest

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]
}
Also used : ListSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse) ListSubscriptionsRequest(com.google.pubsub.v1.ListSubscriptionsRequest) SubscriptionAdminClient(com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription)

Aggregations

ListSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse)2 ListSubscriptionsRequest (com.google.pubsub.v1.ListSubscriptionsRequest)2 Subscription (com.google.pubsub.v1.Subscription)2 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)1 ByteString (com.google.protobuf.ByteString)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ListSubscriptionsResponse (com.google.pubsub.v1.ListSubscriptionsResponse)1 ProjectName (com.google.pubsub.v1.ProjectName)1 Test (org.junit.Test)1