AbstractConfiguration { public OrderedProperties asOrderedProperties() { return options; } AbstractConfiguration(String configuration, List<String> forbiddenPrefixes);  AbstractConfiguration(String configuration, List<String> forbiddenPrefixes, Map<String, String> defaults);  AbstractConfiguration(Iterable<Map.Entry<String, Object>> jsonOptions, List<String> forbiddenPrefixes);  AbstractConfiguration(Iterable<Map.Entry<String, Object>> jsonOptions, List<String> forbiddenPrefixes, List<String> forbiddenPrefixExceptions);  AbstractConfiguration(Iterable<Map.Entry<String, Object>> jsonOptions, List<String> forbiddenPrefixes, Map<String, String> defaults);  AbstractConfiguration(Iterable<Map.Entry<String, Object>> jsonOptions, List<String> forbiddenPrefixes, List<String> forbiddenPrefixExceptions, Map<String, String> defaults); String getConfigOption(String configOption); String getConfigOption(String configOption, String defaultValue); void setConfigOption(String configOption, String value); void removeConfigOption(String configOption); String getConfiguration(); OrderedProperties asOrderedProperties();  }
@Test public void testConfigurationStringDefaults() { AbstractConfiguration config = new TestConfiguration(""); assertThat(config.asOrderedProperties(), is(defaultConfiguration)); }
@Test public void testConfigurationStringOverridingDefaults() { AbstractConfiguration config = new TestConfiguration("default.option=world"); assertThat(config.asOrderedProperties(), is(createProperties("default.option", "world"))); }
@Test public void testConfigurationStringOverridingDefaultsWithMore() { AbstractConfiguration config = new TestConfiguration("default.option=world" + LINE_SEPARATOR + "var1=aaa" + LINE_SEPARATOR); assertThat(config.asOrderedProperties(), is(createProperties("default.option", "world", "var1", "aaa"))); }
@Test public void testDefaultsFromJson() { AbstractConfiguration config = new TestConfiguration(new JsonObject()); assertThat(config.asOrderedProperties(), is(defaultConfiguration)); }
@Test public void testJsonOverridingDefaults() { AbstractConfiguration config = new TestConfiguration(new JsonObject().put("default.option", "world")); assertThat(config.asOrderedProperties(), is(createProperties("default.option", "world"))); }
@Test public void testJsonOverridingDefaultsWithMore() { AbstractConfiguration config = new TestConfiguration(new JsonObject().put("default.option", "world").put("var1", "aaa")); assertThat(config.asOrderedProperties(), is(createProperties("default.option", "world", "var1", "aaa"))); }
@Test public void testNonEmptyConfigurationString() { String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR; OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testNonEmptyJson() { JsonObject configuration = new JsonObject() .put("var1", "aaa") .put("var2", "bbb") .put("var3", "ccc"); OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testConfigurationStringWithDuplicates() { String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR + "var2=ddd" + LINE_SEPARATOR; OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "ddd", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testJsonWithDuplicates() { JsonObject configuration = new JsonObject() .put("var1", "aaa") .put("var2", "bbb") .put("var3", "ccc") .put("var2", "ddd"); OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "ddd", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testConfigurationStringWithForbiddenKeys() { String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR + "forbidden.option=ddd" + LINE_SEPARATOR; OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testConfigurationStringWithForbiddenKeysInUpperCase() { String configuration = "var1=aaa" + LINE_SEPARATOR + "var2=bbb" + LINE_SEPARATOR + "var3=ccc" + LINE_SEPARATOR + "FORBIDDEN.OPTION=ddd" + LINE_SEPARATOR; OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testJsonWithForbiddenKeys() { JsonObject configuration = new JsonObject().put("var1", "aaa") .put("var2", "bbb") .put("var3", "ccc") .put("forbidden.option", "ddd"); OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testJsonWithForbiddenKeysPrefix() { JsonObject configuration = new JsonObject().put("var1", "aaa") .put("var2", "bbb") .put("var3", "ccc") .put("forbidden.option.first", "ddd") .put("forbidden.option.second", "ddd"); OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testWithHostPort() { JsonObject configuration = new JsonObject().put("option.with.port", "my-server:9092"); OrderedProperties expectedConfiguration = createWithDefaults("option.with.port", "my-server:9092"); AbstractConfiguration config = new TestConfiguration(configuration); assertThat(config.asOrderedProperties(), is(expectedConfiguration)); }
@Test public void testKafkaZookeeperTimeout() { Map<String, Object> conf = new HashMap<>(); conf.put("valid", "validValue"); conf.put("zookeeper.connection.whatever", "invalid"); conf.put("security.invalid1", "invalid"); conf.put("zookeeper.connection.timeout.ms", "42"); conf.put("zookeeper.connection.timeout", "42"); KafkaConfiguration kc = new KafkaConfiguration(conf.entrySet()); assertThat(kc.asOrderedProperties().asMap().get("valid"), is("validValue")); assertThat(kc.asOrderedProperties().asMap().get("zookeeper.connection.whatever"), is(nullValue())); assertThat(kc.asOrderedProperties().asMap().get("security.invalid1"), is(nullValue())); assertThat(kc.asOrderedProperties().asMap().get("zookeeper.connection.timeout.ms"), is("42")); assertThat(kc.asOrderedProperties().asMap().get("zookeeper.connection.timeout"), is(nullValue())); }
@Test public void testKafkaCipherSuiteOverride() { Map<String, Object> conf = new HashMap<>(); conf.put("ssl.cipher.suites", "cipher1,cipher2,cipher3"); KafkaConfiguration kc = new KafkaConfiguration(conf.entrySet()); assertThat(kc.asOrderedProperties().asMap().get("ssl.cipher.suites"), is("cipher1,cipher2,cipher3")); }
@Test public void testKafkaConnectHostnameVerification() { Map<String, Object> conf = new HashMap<>(); conf.put("key.converter", "my.package.Converter"); conf.put("ssl.endpoint.identification.algorithm", ""); conf.put("ssl.keystore.location", "/tmp/my.keystore"); KafkaConnectConfiguration configuration = new KafkaConnectConfiguration(conf.entrySet()); assertThat(configuration.asOrderedProperties().asMap().get("key.converter"), is("my.package.Converter")); assertThat(configuration.asOrderedProperties().asMap().get("ssl.keystore.location"), is(nullValue())); assertThat(configuration.asOrderedProperties().asMap().get("ssl.endpoint.identification.algorithm"), is("")); }
@Test public void testKafkaMirrorMakerConsumerHostnameVerification() { Map<String, Object> conf = new HashMap<>(); conf.put("compression.type", "zstd"); conf.put("ssl.endpoint.identification.algorithm", ""); conf.put("ssl.keystore.location", "/tmp/my.keystore"); KafkaMirrorMakerConsumerConfiguration configuration = new KafkaMirrorMakerConsumerConfiguration(conf.entrySet()); assertThat(configuration.asOrderedProperties().asMap().get("compression.type"), is("zstd")); assertThat(configuration.asOrderedProperties().asMap().get("ssl.keystore.location"), is(nullValue())); assertThat(configuration.asOrderedProperties().asMap().get("ssl.endpoint.identification.algorithm"), is("")); }
@Test public void testKafkaMirrorMakerProducerHostnameVerification() { Map<String, Object> conf = new HashMap<>(); conf.put("compression.type", "zstd"); conf.put("ssl.endpoint.identification.algorithm", ""); conf.put("ssl.keystore.location", "/tmp/my.keystore"); KafkaMirrorMakerProducerConfiguration configuration = new KafkaMirrorMakerProducerConfiguration(conf.entrySet()); assertThat(configuration.asOrderedProperties().asMap().get("compression.type"), is("zstd")); assertThat(configuration.asOrderedProperties().asMap().get("ssl.keystore.location"), is(nullValue())); assertThat(configuration.asOrderedProperties().asMap().get("ssl.endpoint.identification.algorithm"), is("")); }