use of io.strimzi.kafka.config.model.ConfigModel in project strimzi-kafka-operator by strimzi.
the class ConfigModelTest method testBooleanValidation.
@Test
public void testBooleanValidation() {
ConfigModel cm = new ConfigModel();
cm.setType(Type.BOOLEAN);
assertThat(cm.validate("test", "true"), is(emptyList()));
assertThat(cm.validate("test", "false"), is(emptyList()));
assertThat(cm.validate("test", "dog"), is(singletonList("test has value 'dog' which is not a boolean")));
}
use of io.strimzi.kafka.config.model.ConfigModel in project strimzi-kafka-operator by strimzi.
the class ConfigModelTest method testPasswordValidation.
@Test
public void testPasswordValidation() {
ConfigModel cm = new ConfigModel();
cm.setType(Type.PASSWORD);
assertThat(cm.validate("test", "whatever"), is(emptyList()));
}
use of io.strimzi.kafka.config.model.ConfigModel in project strimzi-kafka-operator by strimzi.
the class ConfigModelTest method testLongValidation.
@Test
public void testLongValidation() {
ConfigModel cm = new ConfigModel();
cm.setType(Type.LONG);
assertThat(cm.validate("test", "1"), is(emptyList()));
assertThat(cm.validate("test", Long.valueOf(Long.MAX_VALUE).toString()), is(emptyList()));
assertThat(cm.validate("test", Long.valueOf(Long.MIN_VALUE).toString()), is(emptyList()));
assertThat(cm.validate("test", "9223372036854775808"), is(singletonList("test has value '9223372036854775808' which is not a long")));
assertThat(cm.validate("test", "-9223372036854775809"), is(singletonList("test has value '-9223372036854775809' which is not a long")));
cm.setMinimum(0);
assertThat(cm.validate("test", "-1"), is(singletonList("test has value -1 which less than the minimum value 0")));
cm.setMaximum(1);
assertThat(cm.validate("test", "2"), is(singletonList("test has value 2 which greater than the maximum value 1")));
}
use of io.strimzi.kafka.config.model.ConfigModel in project strimzi-kafka-operator by strimzi.
the class ConfigModelTest method testListValidation.
@Test
public void testListValidation() {
ConfigModel cm = new ConfigModel();
cm.setType(Type.LIST);
assertThat(cm.validate("test", "foo"), is(emptyList()));
assertThat(cm.validate("test", "foo,bar"), is(emptyList()));
cm.setItems(asList("foo", "bar"));
assertThat(cm.validate("test", "foo"), is(emptyList()));
assertThat(cm.validate("test", "foo,bar"), is(emptyList()));
assertThat(cm.validate("test", "foo,bar,baz"), is(singletonList("test contains values [baz] which are not in the allowed items [foo, bar]")));
assertThat(cm.validate("test", "foo, bar, baz"), is(singletonList("test contains values [baz] which are not in the allowed items [foo, bar]")));
assertThat(cm.validate("test", " foo , bar, baz "), is(singletonList("test contains values [baz] which are not in the allowed items [foo, bar]")));
assertThat(cm.validate("test", " foo , bar,,"), is(singletonList("test contains values [] which are not in the allowed items [foo, bar]")));
}
use of io.strimzi.kafka.config.model.ConfigModel in project strimzi by strimzi.
the class KafkaConfiguration method validate.
/**
* Validate the configs in this KafkaConfiguration returning a list of errors.
* @param kafkaVersion The broker version.
* @return A list of error messages.
*/
public List<String> validate(KafkaVersion kafkaVersion) {
List<String> errors = new ArrayList<>();
Map<String, ConfigModel> models = readConfigModel(kafkaVersion);
for (Map.Entry<String, String> entry : asOrderedProperties().asMap().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
ConfigModel config = models.get(key);
if (config != null) {
// It's not an error if config _is_ null because extra configs
// might be intended for plugins
errors.addAll(config.validate(key, value));
}
}
return errors;
}
Aggregations