use of io.helidon.config.Config in project helidon by oracle.
the class FactoryMethodConfigMapperTest method testAmbiguousConstructors.
//
// constructor
//
@Test
public void testAmbiguousConstructors() {
Config config = Config.empty();
ConfigMappingException ex = assertThrows(ConfigMappingException.class, () -> {
config.as(AmbiguousConstructorsBean.class).get();
});
assertThat(ex.getMessage(), stringContainsInOrder(List.of(AmbiguousConstructorsBean.class.getName(), "No mapper configured")));
}
use of io.helidon.config.Config in project helidon by oracle.
the class FactoryMethodConfigMapperTest method testMissingParamsFromMethod.
@Test
public void testMissingParamsFromMethod() {
Config config = Config.create(ConfigSources.create(Map.of("app.number", "1")));
ConfigMappingException ex = assertThrows(ConfigMappingException.class, () -> {
config.get("app").as(FromMethodBean.class).get();
});
assertThat(ex.getMessage(), stringContainsInOrder(List.of("'app'", "FromMethodBean", "Missing value for parameter 'uri'.")));
}
use of io.helidon.config.Config in project helidon by oracle.
the class FactoryMethodConfigMapperTest method testNoConfigValueConstructor.
@Test
public void testNoConfigValueConstructor() {
Config config = Config.create(ConfigSources.create(ObjectNode.builder().addValue("app.arg0", "1").addValue("app.arg1", "this:is/my?uri").addValue("app.arg2", "/this/is/my.path").addList("app.arg3", ListNode.builder().addValue("1").addValue("2").build()).addList("app.arg4", ListNode.builder().addValue("this:is/my?uri").addValue("http://another/uri").build()).addList("app.arg5", ListNode.builder().addValue("/this/is/my.path").addValue("/and/another.path").build()).build()));
NoConfigValueConstructorBean bean = config.get("app").as(NoConfigValueConstructorBean.class).get();
assertThat(bean.getNumber(), is(1));
assertThat(bean.getUri(), is(URI.create("this:is/my?uri")));
assertThat(bean.getCustom(), is(CustomType.from("/this/is/my.path")));
assertThat(bean.getNumbers(), contains(1, 2));
assertThat(bean.getUris(), contains(URI.create("this:is/my?uri"), URI.create("http://another/uri")));
assertThat(bean.getCustoms(), contains(CustomType.from("/this/is/my.path"), CustomType.from("/and/another.path")));
}
use of io.helidon.config.Config in project helidon by oracle.
the class FactoryMethodConfigMapperTest method testDefaultsFromMethod.
@Test
public void testDefaultsFromMethod() {
Config config = Config.create(ConfigSources.create(Map.of("app.number", "1")));
DefaultsFromMethodBean bean = config.get("app").as(DefaultsFromMethodBean.class).get();
assertThat(bean.getNumber(), is(1));
assertThat(bean.getUri(), is(URI.create("default:uri")));
assertThat(bean.getCustom(), is(CustomType.from("/tmp/default")));
assertThat(bean.getNumbers(), contains(23, 42));
assertThat(bean.getUris(), contains(URI.create("default:uri"), URI.create("default:another:uri")));
assertThat(bean.getCustoms(), contains(CustomType.from("/tmp/default"), CustomType.from("/tmp/another/default")));
}
use of io.helidon.config.Config in project helidon by oracle.
the class GenericConfigMapperTest method testNotSetValues.
@Test
public void testNotSetValues() {
Config config = Config.builder().sources(ConfigSources.create(prepareConfigApp(// uid
false, // greeting
true, // pageSize
true, // basicRange
true, // LOGGING
false, // SECURITY
false, // NAMES
false).build())).disableEnvironmentVariablesSource().disableSystemPropertiesSource().build();
print(config);
AppConfig appConfig = config.get("app").as(AppConfig.class).get();
assertThat(appConfig.getLogging().getLevel(""), is(Optional.empty()));
assertThat(appConfig.getLogging().getLevel("io.helidon.config"), is(Optional.empty()));
assertThat(appConfig.getLogging().getLevel("my.app"), is(Optional.empty()));
assertThat(appConfig.getSecurity(), is(nullValue()));
assertThat(appConfig.getNames().entrySet(), hasSize(0));
}
Aggregations