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());
}
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());
}
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());
}
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());
}
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"));
}
Aggregations