@Override public Config validate(Map<String, String> connectorConfigs) { Configuration config = Configuration.from(connectorConfigs); // First, validate all of the individual fields, which is easy since don't make any of the fields invisible ... Map<String, ConfigValue> results = config.validate(MongoDbConnectorConfig.EXPOSED_FIELDS); // Get the config values for each of the connection-related fields ... ConfigValue hostsValue = results.get(MongoDbConnectorConfig.HOSTS.name()); ConfigValue userValue = results.get(MongoDbConnectorConfig.USER.name()); ConfigValue passwordValue = results.get(MongoDbConnectorConfig.PASSWORD.name()); // If there are no errors on any of these ... if (hostsValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty()) { // Try to connect to the database ... try (ConnectionContext connContext = new ConnectionContext(config)) { try ( MongoClient client = connContext.clientFor(connContext.hosts()) ) { client.listDatabaseNames(); } } catch (MongoException e) { hostsValue.addErrorMessage("Unable to connect: " + e.getMessage()); } } return new Config(new ArrayList<>(results.values())); } }
if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty() && databaseValue.errorMessages().isEmpty()) {
if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty()) {
protected void assertNoConfigurationErrors(Config config, io.debezium.config.Field... fields) { for (io.debezium.config.Field field : fields) { ConfigValue value = configValue(config, field.name()); if (value != null) { if (!value.errorMessages().isEmpty()) { fail("Error messages on field '" + field.name() + "': " + value.errorMessages()); } } } }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field, int minErrorsInclusive, int maxErrorsInclusive) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isGreaterThanOrEqualTo(minErrorsInclusive); assertThat(value.errorMessages().size()).isLessThanOrEqualTo(maxErrorsInclusive); }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field, int numErrors) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isEqualTo(numErrors); }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isGreaterThan(0); }
@Test public void shouldValidateMinimalConfiguration() throws Exception { Configuration config = TestHelper.defaultConfig().build(); Config validateConfig = new PostgresConnector().validate(config.asMap()); validateConfig.configValues().forEach(configValue -> assertTrue("Unexpected error for: " + configValue.name(), configValue.errorMessages().isEmpty())); }
public static ConfigInfos generateResult(String connType, Map<String, ConfigKey> configKeys, List<ConfigValue> configValues, List<String> groups) { int errorCount = 0; List<ConfigInfo> configInfoList = new LinkedList<>(); Map<String, ConfigValue> configValueMap = new HashMap<>(); for (ConfigValue configValue: configValues) { String configName = configValue.name(); configValueMap.put(configName, configValue); if (!configKeys.containsKey(configName)) { configValue.addErrorMessage("Configuration is not defined: " + configName); configInfoList.add(new ConfigInfo(null, convertConfigValue(configValue, null))); } } for (Map.Entry<String, ConfigKey> entry : configKeys.entrySet()) { String configName = entry.getKey(); ConfigKeyInfo configKeyInfo = convertConfigKey(entry.getValue()); Type type = entry.getValue().type; ConfigValueInfo configValueInfo = null; if (configValueMap.containsKey(configName)) { ConfigValue configValue = configValueMap.get(configName); configValueInfo = convertConfigValue(configValue, type); errorCount += configValue.errorMessages().size(); } configInfoList.add(new ConfigInfo(configKeyInfo, configValueInfo)); } return new ConfigInfos(connType, errorCount, groups, configInfoList); }
if (hostnameValue.errorMessages().isEmpty() && portValue.errorMessages().isEmpty() && userValue.errorMessages().isEmpty() && passwordValue.errorMessages().isEmpty() && databaseValue.errorMessages().isEmpty()) {
protected void assertNoConfigurationErrors(Config config, io.debezium.config.Field... fields) { for (io.debezium.config.Field field : fields) { ConfigValue value = configValue(config, field.name()); if (value != null) { if (!value.errorMessages().isEmpty()) { fail("Error messages on field '" + field.name() + "': " + value.errorMessages()); } } } }
private static ConfigValueInfo convertConfigValue(ConfigValue configValue, Type type) { String value = ConfigDef.convertToString(configValue.value(), type); List<String> recommendedValues = new LinkedList<>(); if (type == Type.LIST) { for (Object object: configValue.recommendedValues()) { recommendedValues.add(ConfigDef.convertToString(object, Type.STRING)); } } else { for (Object object : configValue.recommendedValues()) { recommendedValues.add(ConfigDef.convertToString(object, type)); } } return new ConfigValueInfo(configValue.name(), value, recommendedValues, configValue.errorMessages(), configValue.visible()); }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field, int minErrorsInclusive, int maxErrorsInclusive) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isGreaterThanOrEqualTo(minErrorsInclusive); assertThat(value.errorMessages().size()).isLessThanOrEqualTo(maxErrorsInclusive); }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field, int numErrors) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isEqualTo(numErrors); }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isGreaterThan(0); }
@Test public void shouldValidateMinimalConfiguration() throws Exception { Configuration config = TestHelper.defaultConfig().build(); Config validateConfig = new PostgresConnector().validate(config.asMap()); validateConfig.configValues().forEach(configValue -> assertTrue("Unexpected error for: " + configValue.name(), configValue.errorMessages().isEmpty())); }