Search in sources :

Example 6 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class GitConfigSourceBuilderTest method testFromConfigAll.

@Test
public void testFromConfigAll() throws IOException {
    Path directory = folder.newFolder().toPath();
    Config metaConfig = Config.builder(ConfigSources.create(Map.of("path", "application.properties", "uri", fileUri(), "branch", "test", "directory", directory.toString()))).disableSystemPropertiesSource().disableEnvironmentVariablesSource().build();
    GitConfigSourceBuilder builder = GitConfigSource.builder().config(metaConfig);
    assertThat(builder.target().path(), is("application.properties"));
    assertThat(builder.target().uri(), is(URI.create(fileUri())));
    assertThat(builder.target().branch(), is("test"));
    assertThat(builder.target().directory(), is(directory));
}
Also used : Path(java.nio.file.Path) Config(io.helidon.config.Config) MetaConfig(io.helidon.config.MetaConfig) Test(org.junit.jupiter.api.Test)

Example 7 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class GitConfigSourceBuilderTest method testFromConfigMandatory.

@Test
public void testFromConfigMandatory() {
    Config metaConfig = Config.builder(ConfigSources.create(Map.of("path", "application.properties"))).disableSystemPropertiesSource().disableEnvironmentVariablesSource().build();
    GitConfigSourceBuilder builder = GitConfigSource.builder().config(metaConfig);
    assertThat(builder.target().path(), is("application.properties"));
    assertThat(builder.target().uri(), is(nullValue()));
    assertThat(builder.target().branch(), is("master"));
    assertThat(builder.target().directory(), is(nullValue()));
}
Also used : Config(io.helidon.config.Config) MetaConfig(io.helidon.config.MetaConfig) Test(org.junit.jupiter.api.Test)

Example 8 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class GitConfigSourceBuilderTest method testSourceFromConfigByType.

@Test
public void testSourceFromConfigByType() throws Exception {
    Path directory = folder.newFolder().toPath();
    Config metaConfig = Config.builder(ConfigSources.create(ObjectNode.builder().addValue("type", "git").addObject("properties", ObjectNode.builder().addValue("path", "application.properties").addValue("uri", fileUri()).addValue("branch", "test").addValue("directory", directory.toString()).build()).build())).disableSystemPropertiesSource().disableEnvironmentVariablesSource().build();
    try (GitConfigSource gitSource = (GitConfigSource) MetaConfig.configSource(metaConfig).get(0)) {
        assertThat(gitSource.gitEndpoint().path(), is("application.properties"));
        assertThat(gitSource.gitEndpoint().uri(), is(URI.create(fileUri())));
        assertThat(gitSource.gitEndpoint().branch(), is("test"));
        assertThat(gitSource.gitEndpoint().directory(), is(directory));
    }
}
Also used : Path(java.nio.file.Path) Config(io.helidon.config.Config) MetaConfig(io.helidon.config.MetaConfig) Test(org.junit.jupiter.api.Test)

Example 9 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class HoconConfigParserTest method testParserFromJson.

@Test
void testParserFromJson() {
    Config config = Config.builder().disableSystemPropertiesSource().disableEnvironmentVariablesSource().disableParserServices().addParser(HoconConfigParser.create()).addSource(ConfigSources.classpath("config.json")).build();
    Optional<String> property = config.get("oracle.com").asString().asOptional();
    assertThat(property, is(Optional.of("1")));
    property = config.get("nulls.null").asString().asOptional();
    assertThat(property, is(Optional.of("")));
    List<String> properties = config.get("nulls-array").asList(String.class).get();
    assertThat(properties, hasItems("test", ""));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Example 10 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class HoconConfigParserTest method testConfigKeyEscapedNameComplex.

/**
 * This is same test as in {@code config} module, {@code ConfigTest} class, method {@code testConfigKeyEscapedNameComplex}.
 */
@Test
public void testConfigKeyEscapedNameComplex() {
    String JSON = "" + "{\n" + "    \"oracle.com\": {\n" + "        \"prop1\": \"val1\",\n" + "        \"prop2\": \"val2\"\n" + "    },\n" + "    \"oracle\": {\n" + "        \"com\": \"1\",\n" + "        \"cz\": \"2\"\n" + "    }\n" + "}\n";
    Config config = Config.builder(ConfigSources.create(JSON, HoconConfigParser.MEDIA_TYPE_APPLICATION_JSON)).addParser(HoconConfigParser.create()).disableEnvironmentVariablesSource().disableSystemPropertiesSource().disableParserServices().disableMapperServices().disableFilterServices().build();
    // key
    assertThat(config.get("oracle~1com.prop1").asString(), is(simpleValue("val1")));
    assertThat(config.get("oracle~1com.prop2").asString(), is(simpleValue("val2")));
    assertThat(config.get("oracle.com").asString(), is(simpleValue("1")));
    assertThat(config.get("oracle.cz").asString(), is(simpleValue("2")));
    // name
    assertThat(config.get("oracle~1com").name(), is("oracle.com"));
    assertThat(config.get("oracle~1com.prop1").name(), is("prop1"));
    assertThat(config.get("oracle~1com.prop2").name(), is("prop2"));
    assertThat(config.get("oracle").name(), is("oracle"));
    assertThat(config.get("oracle.com").name(), is("com"));
    assertThat(config.get("oracle.cz").name(), is("cz"));
    // child nodes
    List<Config> children = config.asNodeList().get();
    assertThat(children, hasSize(2));
    assertThat(children.stream().map(Config::name).collect(Collectors.toSet()), containsInAnyOrder("oracle.com", "oracle"));
    // traverse
    Set<String> keys = config.traverse().map(Config::key).map(Config.Key::toString).collect(Collectors.toSet());
    assertThat(keys, hasSize(6));
    assertThat(keys, containsInAnyOrder("oracle~1com", "oracle~1com.prop1", "oracle~1com.prop2", "oracle", "oracle.com", "oracle.cz"));
    // map
    Map<String, String> map = config.asMap().get();
    assertThat(map.keySet(), hasSize(4));
    assertThat(map.get("oracle~1com.prop1"), is("val1"));
    assertThat(map.get("oracle~1com.prop2"), is("val2"));
    assertThat(map.get("oracle.com"), is("1"));
    assertThat(map.get("oracle.cz"), is("2"));
}
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