Search in sources :

Example 66 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidCharsetTest method unsupportedCharset.

@Test
public void unsupportedCharset() {
    ConfigException configException = assertThrows(ConfigException.class, () -> {
        ConfigDef.Validator validator = new ValidCharset();
        validator.ensureValid("testing", "utf9");
    });
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) ConfigDef(org.apache.kafka.common.config.ConfigDef) Test(org.junit.jupiter.api.Test)

Example 67 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidHostnameAndPortTest method ensureValidExceptions.

@Test
public void ensureValidExceptions() {
    ConfigException exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", null);
    });
    assertTrue(exception.getMessage().contains("must be a string or a list."));
    exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", "");
    });
    assertTrue(exception.getMessage().contains("does not match pattern"));
    exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", "localhost:99999");
    });
    assertTrue(exception.getMessage().contains("Port must be between 1 and 65535"));
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.jupiter.api.Test)

Example 68 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class PatternValidatorTest method invalidType.

@Test
public void invalidType() {
    ConfigException configException = assertThrows(ConfigException.class, () -> {
        PatternValidator validator = new PatternValidator();
        validator.ensureValid("foo", 1234);
    });
    assertTrue(configException.getMessage().contains("foo"));
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.jupiter.api.Test)

Example 69 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class Validators method validKeyStoreType.

/**
 * Validator is used to ensure that the KeyStore type specified is valid.
 * @return
 */
public static Validator validKeyStoreType() {
    return (s, o) -> {
        if (!(o instanceof String)) {
            throw new ConfigException(s, o, "Must be a string.");
        }
        String keyStoreType = o.toString();
        try {
            KeyStore.getInstance(keyStoreType);
        } catch (KeyStoreException e) {
            ConfigException exception = new ConfigException(s, o, "Invalid KeyStore type");
            exception.initCause(e);
            throw exception;
        }
    };
}
Also used : ValidEnum(com.github.jcustenborder.kafka.connect.utils.config.ValidEnum) SSLContext(javax.net.ssl.SSLContext) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) ConfigException(org.apache.kafka.common.config.ConfigException) ValidPattern(com.github.jcustenborder.kafka.connect.utils.config.ValidPattern) ValidPort(com.github.jcustenborder.kafka.connect.utils.config.ValidPort) Validator(org.apache.kafka.common.config.ConfigDef.Validator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException) KeyStoreException(java.security.KeyStoreException)

Example 70 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidFileSystem method ensureValid.

@Override
public void ensureValid(String setting, Object input) {
    log.trace("ensureValid('{}', '{}')", setting, input);
    if (!(input instanceof String)) {
        throw new ConfigException(setting, "Input must be a string.");
    }
    final String value = input.toString();
    if (Strings.isNullOrEmpty(value)) {
        throw new ConfigException(setting, "Cannot be null or empty.");
    }
    final File file = new File(value);
    if (!file.isAbsolute()) {
        throw new ConfigException(setting, String.format("File '%s' is not an absolute path.", file));
    }
    ensureValid(setting, input, file);
    if (this.ensureWritable) {
        if (!file.canWrite()) {
            throw new ConfigException(setting, String.format("File '%s' should be writable.", file));
        }
    }
    if (!file.canRead()) {
        throw new ConfigException(setting, String.format("File '%s' should be readable.", file));
    }
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) File(java.io.File)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4