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