Search in sources :

Example 16 with Config

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")));
}
Also used : Config(io.helidon.config.Config) ConfigMappingException(io.helidon.config.ConfigMappingException) Test(org.junit.jupiter.api.Test)

Example 17 with Config

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'.")));
}
Also used : Config(io.helidon.config.Config) ConfigMappingException(io.helidon.config.ConfigMappingException) Test(org.junit.jupiter.api.Test)

Example 18 with Config

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")));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Example 19 with Config

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")));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Example 20 with Config

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));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Aggregations

Config (io.helidon.config.Config)329 Test (org.junit.jupiter.api.Test)169 LogConfig (io.helidon.common.LogConfig)56 WebServer (io.helidon.webserver.WebServer)54 Routing (io.helidon.webserver.Routing)51 BeforeAll (org.junit.jupiter.api.BeforeAll)24 Security (io.helidon.security.Security)20 HealthSupport (io.helidon.health.HealthSupport)18 Single (io.helidon.common.reactive.Single)17 MetricsSupport (io.helidon.metrics.MetricsSupport)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 ConfigSources (io.helidon.config.ConfigSources)15 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)15 SecurityContext (io.helidon.security.SecurityContext)15 Optional (java.util.Optional)15 TimeUnit (java.util.concurrent.TimeUnit)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 HealthChecks (io.helidon.health.checks.HealthChecks)12 WebClient (io.helidon.webclient.WebClient)12 GrpcRouting (io.helidon.grpc.server.GrpcRouting)11