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");
});
}
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"));
}
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"));
}
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;
}
};
}
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));
}
}
Aggregations