Skip to content

Commit

Permalink
Fix broken DefaultKafkaClusterConfigSupplier get API (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#3529)

Signed-off-by: Kondaka <[email protected]>
  • Loading branch information
kkondaka authored Oct 19, 2023
1 parent 61efeae commit c63dea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opensearch.dataprepper.plugins.kafka.configuration.EncryptionConfig;

import java.util.List;
import java.util.Objects;

public class DefaultKafkaClusterConfigSupplier implements KafkaClusterConfigSupplier {
private final KafkaClusterConfig kafkaClusterConfig;
Expand All @@ -19,21 +20,21 @@ public DefaultKafkaClusterConfigSupplier(KafkaClusterConfig kafkaClusterConfig)

@Override
public List<String> getBootStrapServers() {
return kafkaClusterConfig.getBootStrapServers();
return Objects.nonNull(kafkaClusterConfig) ? kafkaClusterConfig.getBootStrapServers() : null;
}

@Override
public AuthConfig getAuthConfig() {
return kafkaClusterConfig.getAuthConfig();
return Objects.nonNull(kafkaClusterConfig) ? kafkaClusterConfig.getAuthConfig() : null;
}

@Override
public AwsConfig getAwsConfig() {
return kafkaClusterConfig.getAwsConfig();
return Objects.nonNull(kafkaClusterConfig) ? kafkaClusterConfig.getAwsConfig() : null;
}

@Override
public EncryptionConfig getEncryptionConfig() {
return kafkaClusterConfig.getEncryptionConfig();
return Objects.nonNull(kafkaClusterConfig) ? kafkaClusterConfig.getEncryptionConfig() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private DefaultKafkaClusterConfigSupplier createObjectUnderTest() {
}

@Test
void test_getters() {
void testGetters() {
final List<String> bootstrapServers = List.of("localhost:9092");
final AuthConfig authConfig = mock(AuthConfig.class);
final AwsConfig awsConfig = mock(AwsConfig.class);
Expand All @@ -45,4 +45,14 @@ void test_getters() {
assertThat(defaultKafkaClusterConfigSupplier.getAwsConfig(), equalTo(awsConfig));
assertThat(defaultKafkaClusterConfigSupplier.getEncryptionConfig(), equalTo(encryptionConfig));
}

@Test
void testGettersWithNullClusterConfig() {
DefaultKafkaClusterConfigSupplier defaultKafkaClusterConfigSupplier =
new DefaultKafkaClusterConfigSupplier(null);
assertThat(defaultKafkaClusterConfigSupplier.getBootStrapServers(), equalTo(null));
assertThat(defaultKafkaClusterConfigSupplier.getAuthConfig(), equalTo(null));
assertThat(defaultKafkaClusterConfigSupplier.getAwsConfig(), equalTo(null));
assertThat(defaultKafkaClusterConfigSupplier.getEncryptionConfig(), equalTo(null));
}
}

0 comments on commit c63dea3

Please sign in to comment.