Search in sources :

Example 6 with SmallRyeConfigBuilder

use of io.smallrye.config.SmallRyeConfigBuilder in project smallrye-config by smallrye.

the class ConfigPropertiesInjectionTest method beforeAll.

@BeforeAll
static void beforeAll() {
    SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(config("server.theHost", "localhost", "server.port", "8080")).withSources(config("cloud.theHost", "cloud", "cloud.port", "9090", "cloud.array", "2,3", "cloud.list", "3,4", "cloud.set", "4,5", "cloud.optionalArray", "2,3", "cloud.optionalList", "3,4", "cloud.optionalSet", "4,5")).addDefaultInterceptors().build();
    ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader());
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with SmallRyeConfigBuilder

use of io.smallrye.config.SmallRyeConfigBuilder in project smallrye-config by smallrye.

the class OptionalInjectionTest method beforeAll.

@BeforeAll
static void beforeAll() {
    SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(config("optional.int.value", "1", "optional.long.value", "2", "optional.double.value", "3.3")).addDefaultInterceptors().build();
    ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader());
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with SmallRyeConfigBuilder

use of io.smallrye.config.SmallRyeConfigBuilder in project smallrye-config by smallrye.

the class SupplierInjectionTest method beforeAll.

@BeforeAll
static void beforeAll() {
    SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(config("my.prop", "1234")).withSources(new ConfigSource() {

        int counter = 1;

        @Override
        public Map<String, String> getProperties() {
            return new HashMap<>();
        }

        @Override
        public Set<String> getPropertyNames() {
            return new HashSet<>();
        }

        @Override
        public String getValue(final String propertyName) {
            return "my.counter".equals(propertyName) ? "" + counter++ : null;
        }

        @Override
        public String getName() {
            return this.getClass().getName();
        }
    }).addDefaultInterceptors().build();
    ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader());
}
Also used : ConfigSource(org.eclipse.microprofile.config.spi.ConfigSource) SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) Set(java.util.Set) HashSet(java.util.HashSet) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) HashMap(java.util.HashMap) Map(java.util.Map) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with SmallRyeConfigBuilder

use of io.smallrye.config.SmallRyeConfigBuilder in project smallrye-config by smallrye.

the class HoconConfigSourceTest method list.

@Test
void list() throws Exception {
    SmallRyeConfig config = new SmallRyeConfigBuilder().withSources(new HoconConfigSource(HoconConfigSource.class.getResource("/list.conf"))).withMapping(Countries.class, "countries").build();
    Countries mapping = config.getConfigMapping(Countries.class);
    assertFalse(mapping.countries().isEmpty());
    assertEquals(8, mapping.countries().size());
    assertEquals("FJ", mapping.countries().get(0).code());
    assertEquals("Fiji", mapping.countries().get(0).name());
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.jupiter.api.Test)

Example 10 with SmallRyeConfigBuilder

use of io.smallrye.config.SmallRyeConfigBuilder 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)

Aggregations

SmallRyeConfigBuilder (io.smallrye.config.SmallRyeConfigBuilder)37 SmallRyeConfig (io.smallrye.config.SmallRyeConfig)32 Test (org.junit.jupiter.api.Test)22 BeforeAll (org.junit.jupiter.api.BeforeAll)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ConfigSource (org.eclipse.microprofile.config.spi.ConfigSource)5 ConfigValidationException (io.smallrye.config.ConfigValidationException)4 PropertiesConfigSource (io.smallrye.config.PropertiesConfigSource)3 Config (org.eclipse.microprofile.config.Config)3 Map (java.util.Map)2 Set (java.util.Set)2 Configuration (com.buschmais.jqassistant.core.configuration.api.Configuration)1 ConfigValuePropertiesConfigSource (io.smallrye.config.ConfigValuePropertiesConfigSource)1 PropertiesConfigSourceProvider (io.smallrye.config.PropertiesConfigSourceProvider)1 PropertiesLocationConfigSourceFactory (io.smallrye.config.PropertiesLocationConfigSourceFactory)1 SmallRyeConfigProviderResolver (io.smallrye.config.SmallRyeConfigProviderResolver)1 SysPropConfigSource (io.smallrye.config.SysPropConfigSource)1 YamlConfigSource (io.smallrye.config.source.yaml.YamlConfigSource)1 OpenApiConfigImpl (io.smallrye.openapi.api.OpenApiConfigImpl)1