Search in sources :

Example 11 with ConfigModel

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")));
}
Also used : ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Test(org.junit.jupiter.api.Test)

Example 12 with ConfigModel

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()));
}
Also used : ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigModel

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")));
}
Also used : ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigModel

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]")));
}
Also used : ConfigModel(io.strimzi.kafka.config.model.ConfigModel) Test(org.junit.jupiter.api.Test)

Example 15 with ConfigModel

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;
}
Also used : ConfigModel(io.strimzi.kafka.config.model.ConfigModel) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

ConfigModel (io.strimzi.kafka.config.model.ConfigModel)28 Test (org.junit.jupiter.api.Test)18 Scope (io.strimzi.kafka.config.model.Scope)4 Type (io.strimzi.kafka.config.model.Type)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 PatchUtils.patchMapper (io.fabric8.kubernetes.client.internal.PatchUtils.patchMapper)2 JsonDiff (io.fabric8.zjsonpatch.JsonDiff)2 ConfigModels (io.strimzi.kafka.config.model.ConfigModels)2 KafkaConfiguration (io.strimzi.operator.cluster.model.KafkaConfiguration)2 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 ReconciliationLogger (io.strimzi.operator.common.ReconciliationLogger)2 OrderedProperties (io.strimzi.operator.common.model.OrderedProperties)2 AbstractJsonDiff (io.strimzi.operator.common.operator.resource.AbstractJsonDiff)2 File (java.io.File)2 Method (java.lang.reflect.Method)2