KafkaOperations implements AutoCloseable { public TopicList getAvailableTopics() { final List<org.sourcelab.kafka.webview.ui.manager.kafka.dto.TopicListing> topicListings = new ArrayList<>(); try { final ListTopicsOptions listTopicsOptions = new ListTopicsOptions().listInternal(true); final Collection<TopicListing> results = adminClient .listTopics(listTopicsOptions) .listings() .get(); for (final TopicListing entry: results) { topicListings.add( new org.sourcelab.kafka.webview.ui.manager.kafka.dto.TopicListing(entry.name(), entry.isInternal()) ); } return new TopicList(topicListings); } catch (final ExecutionException e) { throw handleExecutionException(e); } catch (final InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } } KafkaOperations(final AdminClient adminClient, final KafkaConsumer<String, String> consumerClient); TopicList getAvailableTopics(); NodeList getClusterNodes(); Map<String, TopicDetails> getTopicDetails(final Collection<String> topics); TopicDetails getTopicDetails(final String topic); TopicConfig getTopicConfig(final String topic); BrokerConfig getBrokerConfig(final String brokerId); boolean createTopic(final CreateTopic createTopic); TopicConfig alterTopicConfig(final String topic, final Map<String, String> configItems); boolean removeTopic(final String topic); List<ConsumerGroupIdentifier> listConsumers(); boolean removeConsumerGroup(final String id); ConsumerGroupDetails getConsumerGroupDetails(final String consumerGroupId); List<ConsumerGroupDetails> getConsumerGroupDetails(final List<String> consumerGroupIds); ConsumerGroupOffsets getConsumerGroupOffsets(final String consumerGroupId); ConsumerGroupOffsetsWithTailPositions getConsumerGroupOffsetsWithTailOffsets(final String consumerGroupId); TailOffsets getTailOffsets(final String topic); TailOffsets getTailOffsets(final String topic, final Collection<Integer> partitions); void close();  }
@Test public void testGetAvailableTopics() { final String topic1 = "MyTopic1" + System.currentTimeMillis(); final String topic2 = "MyTopic2" + System.currentTimeMillis(); sharedKafkaTestResource .getKafkaTestUtils() .createTopic(topic1, 2, (short) 1); sharedKafkaTestResource .getKafkaTestUtils() .createTopic(topic2, 1, (short) 1); final TopicList topics = kafkaOperations.getAvailableTopics(); assertTrue("Should have topic1", topics.getTopicNames().contains(topic1)); assertTrue("Should have topic2", topics.getTopicNames().contains(topic2)); boolean foundTopic1 = false; boolean foundTopic2 = false; for (final TopicListing topicList: topics.getTopics()) { if (topicList.getName().equals(topic1)) { assertFalse("Haven't seen topic1 yet", foundTopic1); assertFalse("Shouldn't be an internal topic", topicList.isInternal()); foundTopic1 = true; } else if (topicList.getName().equals(topic2)) { assertFalse("Haven't seen topic2 yet", foundTopic2); assertFalse("Shouldn't be an internal topic", topicList.isInternal()); foundTopic2 = true; } } assertTrue("Found topic1", foundTopic1); assertTrue("Found topic1", foundTopic2); }