Search in sources :

Example 1 with ListTopicsResponse

use of com.google.api.services.pubsub.model.ListTopicsResponse in project beam by apache.

the class PubsubJsonClientTest method listTopics.

@Test
public void listTopics() throws Exception {
    ListTopicsResponse expectedResponse1 = new ListTopicsResponse();
    expectedResponse1.setTopics(Collections.singletonList(buildTopic(1)));
    expectedResponse1.setNextPageToken("AVgJH3Z7aHxiDBs");
    ListTopicsResponse expectedResponse2 = new ListTopicsResponse();
    expectedResponse2.setTopics(Collections.singletonList(buildTopic(2)));
    Topics.List request = mockPubsub.projects().topics().list(PROJECT.getPath());
    when((Object) request.execute()).thenReturn(expectedResponse1, expectedResponse2);
    List<TopicPath> topicPaths = client.listTopics(PROJECT);
    assertEquals(2, topicPaths.size());
}
Also used : TopicPath(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath) Topics(com.google.api.services.pubsub.Pubsub.Projects.Topics) ListTopicsResponse(com.google.api.services.pubsub.model.ListTopicsResponse) Test(org.junit.Test)

Example 2 with ListTopicsResponse

use of com.google.api.services.pubsub.model.ListTopicsResponse in project beam by apache.

the class PubsubJsonClient method listTopics.

@Override
public List<TopicPath> listTopics(ProjectPath project) throws IOException {
    Topics.List request = pubsub.projects().topics().list(project.getPath());
    ListTopicsResponse response = request.execute();
    if (response.getTopics() == null || response.getTopics().isEmpty()) {
        return ImmutableList.of();
    }
    List<TopicPath> topics = new ArrayList<>(response.getTopics().size());
    while (true) {
        for (Topic topic : response.getTopics()) {
            topics.add(topicPathFromPath(topic.getName()));
        }
        if (Strings.isNullOrEmpty(response.getNextPageToken())) {
            break;
        }
        request.setPageToken(response.getNextPageToken());
        response = request.execute();
    }
    return topics;
}
Also used : Topics(com.google.api.services.pubsub.Pubsub.Projects.Topics) ArrayList(java.util.ArrayList) ListTopicsResponse(com.google.api.services.pubsub.model.ListTopicsResponse) Topic(com.google.api.services.pubsub.model.Topic)

Aggregations

Topics (com.google.api.services.pubsub.Pubsub.Projects.Topics)2 ListTopicsResponse (com.google.api.services.pubsub.model.ListTopicsResponse)2 Topic (com.google.api.services.pubsub.model.Topic)1 ArrayList (java.util.ArrayList)1 TopicPath (org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath)1 Test (org.junit.Test)1