use of io.smallrye.config.ConfigValidationException in project quarkus by quarkusio.
the class ConfigRecorder method registerConfigProperties.
public void registerConfigProperties(final Set<ConfigClassWithPrefix> configClasses) {
try {
SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
ConfigMappings.registerConfigProperties(config, configClasses);
} catch (ConfigValidationException e) {
throw new DeploymentException(e.getMessage(), e);
}
}
use of io.smallrye.config.ConfigValidationException in project quarkus by quarkusio.
the class ConfigRecorder method registerConfigMappings.
public void registerConfigMappings(final Set<ConfigClassWithPrefix> configClasses) {
try {
SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
ConfigMappings.registerConfigMappings(config, configClasses);
} catch (ConfigValidationException e) {
throw new DeploymentException(e.getMessage(), e);
}
}
use of io.smallrye.config.ConfigValidationException in project smallrye-config by smallrye.
the class BeanValidationConfigValidator method validateMapping.
@Override
default void validateMapping(final Class<?> mappingClass, final String prefix, final Object mappingObject) throws ConfigValidationException {
final List<Problem> problems = new ArrayList<>();
final ConfigMappingInterface mappingInterface = ConfigMappingInterface.getConfigurationInterface(mappingClass);
if (mappingInterface != null) {
validateMappingInterface(mappingInterface, prefix, mappingInterface.getNamingStrategy(), mappingObject, problems);
} else {
validateMappingClass(mappingObject, problems);
}
if (!problems.isEmpty()) {
throw new ConfigValidationException(problems.toArray(ConfigValidationException.Problem.NO_PROBLEMS));
}
}
use of io.smallrye.config.ConfigValidationException in project smallrye-config by smallrye.
the class ValidateConfigTest method validateConfigMapping.
@Test
void validateConfigMapping() {
SmallRyeConfig config = new SmallRyeConfigBuilder().withValidator(new BeanValidationConfigValidatorImpl()).withSources(config("server.host", "localhost", "server.port", "8080", "server.log.days", "20", "server.proxy.enable", "true", "server.proxy.timeout", "20", "server.form.login-page", "login.html", "server.form.error-page", "error.html", "server.form.landing-page", "index.html", "server.cors.origins[0].host", "some-server", "server.cors.origins[0].port", "9000", "server.cors.origins[1].host", "localhost", "server.cors.origins[1].port", "1", "server.cors.methods[0]", "GET", "server.cors.methods[1]", "POST", "server.info.name", "Bond", "server.info.code", "007", "server.info.alias[0]", "James", "server.info.admins.root.username", "root")).withMapping(Server.class, "server").build();
ConfigValidationException validationException = assertThrows(ConfigValidationException.class, () -> config.getConfigMapping(Server.class, "server"));
List<String> validations = new ArrayList<>();
for (int i = 0; i < validationException.getProblemCount(); i++) {
validations.add(validationException.getProblem(i).getMessage());
}
assertTrue(validations.contains("server.port must be less than or equal to 10"));
assertTrue(validations.contains("server.log.days must be less than or equal to 15"));
assertTrue(validations.contains("server.proxy.timeout must be less than or equal to 10"));
assertTrue(validations.contains("server.cors.origins[0].host size must be between 0 and 10"));
assertTrue(validations.contains("server.cors.origins[0].port must be less than or equal to 10"));
assertTrue(validations.contains("server.cors.methods[1] size must be between 0 and 3"));
assertTrue(validations.contains("server.form.login-page size must be between 0 and 3"));
assertTrue(validations.contains("server.form.error-page size must be between 0 and 3"));
assertTrue(validations.contains("server.form.landing-page size must be between 0 and 3"));
assertTrue(validations.contains("server.info.name size must be between 0 and 3"));
assertTrue(validations.contains("server.info.code must be less than or equal to 3"));
assertTrue(validations.contains("server.info.alias[0] size must be between 0 and 3"));
assertTrue(validations.contains("server.info.admins.root.username size must be between 0 and 3"));
}
use of io.smallrye.config.ConfigValidationException in project smallrye-config by smallrye.
the class ValidateConfigTest method validateParent.
@Test
void validateParent() {
SmallRyeConfig config = new SmallRyeConfigBuilder().withValidator(new BeanValidationConfigValidatorImpl()).withSources(config("server.host", "localhost", "server.port", "80")).withMapping(ServerParent.class, "server").build();
ConfigValidationException validationException = assertThrows(ConfigValidationException.class, () -> config.getConfigMapping(ServerParent.class, "server"));
assertEquals("server.port must be greater than or equal to 8000", validationException.getProblem(0).getMessage());
}
Aggregations