use of com.google.api.services.pubsub.Pubsub.Projects.Topics 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());
}
use of com.google.api.services.pubsub.Pubsub.Projects.Topics 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;
}
Aggregations