use of org.neo4j.graphdb.config.SettingValidator in project neo4j by neo4j.
the class ServerConfigurationValidator method validate.
/**
* Verifies that at least one http connector is specified and enabled.
*/
@Override
@Nonnull
public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
Pattern pattern = Pattern.compile(Pattern.quote("dbms.connector.") + "([^\\.]+)\\.(.+)");
List<Connector> connectors = rawConfig.keySet().stream().map(pattern::matcher).filter(Matcher::matches).map(match -> match.group(1)).distinct().map(Connector::new).collect(Collectors.toList());
Map<String, String> validSettings = new HashMap<>(rawConfig);
// Add missing type info -- validation has succeeded so we can do this with confidence
connectors.stream().filter(connector -> connector.type.apply(rawConfig::get) == null).forEach(connector -> {
if ("http".equalsIgnoreCase(connector.group.groupKey) || "https".equalsIgnoreCase(connector.group.groupKey)) {
validSettings.put(connector.type.name(), HTTP.name());
} else {
validSettings.put(connector.type.name(), BOLT.name());
}
});
if (connectors.stream().filter(connector -> connector.type.apply(validSettings::get).equals(HTTP)).noneMatch(connector -> connector.enabled.apply(validSettings::get))) {
throw new InvalidSettingException(String.format("Missing mandatory enabled connector of type '%s'", HTTP));
}
return validSettings;
}
use of org.neo4j.graphdb.config.SettingValidator in project neo4j by neo4j.
the class ConfigTest method shouldPassOnValidatorsOnWithMethods.
@Test
public void shouldPassOnValidatorsOnWithMethods() throws Exception {
// Given
ConfigurationValidator validator = spy(new ConfigurationValidator() {
@Nonnull
@Override
public Map<String, String> validate(@Nonnull Collection<SettingValidator> settingValidators, @Nonnull Map<String, String> rawConfig, @Nonnull Log log, boolean parsingFile) throws InvalidSettingException {
return rawConfig;
}
});
Config first = Config.embeddedDefaults(stringMap("first.jibberish", "bah"), Collections.singleton(validator));
// When
Config second = first.withDefaults(stringMap("second.jibberish", "baah"));
second.with(stringMap("third.jibberish", "baah"));
// Then
verify(validator, times(3)).validate(any(), any(), any(), anyBoolean());
}
Aggregations