Search in sources :

Example 1 with ListSubscriptionsPagedResponse

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());
}
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 ListSubscriptionsPagedResponse

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]);
}
Also used : ListSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Subscription(com.google.pubsub.v1.Subscription) Test(org.junit.Test)

Example 3 with ListSubscriptionsPagedResponse

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]
}
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)3 Subscription (com.google.pubsub.v1.Subscription)3 ByteString (com.google.protobuf.ByteString)2 ListSubscriptionsRequest (com.google.pubsub.v1.ListSubscriptionsRequest)2 Test (org.junit.Test)2 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ListSubscriptionsResponse (com.google.pubsub.v1.ListSubscriptionsResponse)1 ProjectName (com.google.pubsub.v1.ProjectName)1 ArrayList (java.util.ArrayList)1