Search in sources :

Example 1 with ConfigValidationException

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);
    }
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) DeploymentException(javax.enterprise.inject.spi.DeploymentException) ConfigValidationException(io.smallrye.config.ConfigValidationException)

Example 2 with ConfigValidationException

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);
    }
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) DeploymentException(javax.enterprise.inject.spi.DeploymentException) ConfigValidationException(io.smallrye.config.ConfigValidationException)

Example 3 with ConfigValidationException

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));
    }
}
Also used : ArrayList(java.util.ArrayList) Problem(io.smallrye.config.ConfigValidationException.Problem) ConfigMappingInterface(io.smallrye.config.ConfigMappingInterface) ConfigValidationException(io.smallrye.config.ConfigValidationException)

Example 4 with ConfigValidationException

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"));
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) ArrayList(java.util.ArrayList) ConfigValidationException(io.smallrye.config.ConfigValidationException) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigValidationException

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());
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) ConfigValidationException(io.smallrye.config.ConfigValidationException) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigValidationException (io.smallrye.config.ConfigValidationException)8 SmallRyeConfig (io.smallrye.config.SmallRyeConfig)7 SmallRyeConfigBuilder (io.smallrye.config.SmallRyeConfigBuilder)4 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 DeploymentException (javax.enterprise.inject.spi.DeploymentException)2 ConfigMappingInterface (io.smallrye.config.ConfigMappingInterface)1 ConfigClassWithPrefix (io.smallrye.config.ConfigMappings.ConfigClassWithPrefix)1 Problem (io.smallrye.config.ConfigValidationException.Problem)1 ConfigMappingInjectionBean.getPrefixFromInjectionPoint (io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromInjectionPoint)1 ConfigMappingInjectionBean.getPrefixFromType (io.smallrye.config.inject.ConfigMappingInjectionBean.getPrefixFromType)1 InjectionMessages.formatInjectionPoint (io.smallrye.config.inject.InjectionMessages.formatInjectionPoint)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Optional (java.util.Optional)1 OptionalDouble (java.util.OptionalDouble)1 OptionalInt (java.util.OptionalInt)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)1