Search in sources :

Example 6 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project smallrye-reactive-messaging by smallrye.

the class ConfigHelperTest method testMergedConfig.

@Test
public void testMergedConfig() {
    Map<String, String> cfg = new HashMap<>();
    cfg.put("test", "test");
    cfg.put("ov-2", "ov-cfg");
    Map<String, Object> channelSpecific = new HashMap<>();
    channelSpecific.put("spec-1", "spec");
    channelSpecific.put("spec-2", 2);
    channelSpecific.put("ov", "ov-spec");
    channelSpecific.put("ov-2", "ov-spec");
    Map<String, Object> global = new HashMap<>();
    global.put("global-1", "global");
    global.put("global-2", 3);
    global.put("ov", "ov-global");
    global.put("ov-2", "ov-global");
    SmallRyeConfigBuilder test = new SmallRyeConfigBuilder().withSources(new PropertiesConfigSource(cfg, "test", 500));
    Config config = ConfigHelper.merge(test.build(), channelSpecific, global);
    assertThat(config.getValue("test", String.class)).isEqualTo("test");
    Assertions.assertThatThrownBy(() -> config.getValue("test", Double.class)).isInstanceOf(IllegalArgumentException.class);
    assertThat(config.getOptionalValue("test", String.class)).hasValue("test");
    assertThat(config.getOptionalValue("spec-1", String.class)).hasValue("spec");
    assertThat(config.getValue("spec-1", String.class)).isEqualTo("spec");
    Assertions.assertThatThrownBy(() -> config.getValue("spec-1", Double.class)).isInstanceOf(IllegalArgumentException.class);
    assertThat(config.getValue("spec-2", Integer.class)).isEqualTo(2);
    assertThat(config.getOptionalValue("global-1", String.class)).hasValue("global");
    assertThat(config.getValue("global-1", String.class)).isEqualTo("global");
    Assertions.assertThatThrownBy(() -> config.getValue("global-1", Double.class)).isInstanceOf(IllegalArgumentException.class);
    assertThat(config.getValue("global-2", Integer.class)).isEqualTo(3);
    assertThat(config.getOptionalValue("ov", String.class)).hasValue("ov-spec");
    assertThat(config.getOptionalValue("ov-2", String.class)).hasValue("ov-cfg");
    assertThat(config.getOptionalValue("missing", String.class)).isEmpty();
    assertThatThrownBy(() -> config.getValue("missing", Integer.class)).isInstanceOf(NoSuchElementException.class);
    assertThat(config.getConfigValue("test").getValue()).isEqualTo("test");
    assertThat(config.getConfigValue("global-1").getValue()).isNull();
    assertThat(config.getPropertyNames()).containsExactlyInAnyOrder("test", "ov", "ov-2", "global-1", "global-2", "spec-1", "spec-2");
    assertThat(config.getConfigSources()).hasSize(2);
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) HashMap(java.util.HashMap) Config(org.eclipse.microprofile.config.Config) Test(org.junit.jupiter.api.Test)

Example 7 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project smallrye-reactive-messaging by smallrye.

the class ConfigHelperTest method testMergeWithoutOtherMaps.

@Test
public void testMergeWithoutOtherMaps() {
    Map<String, String> cfg = new HashMap<>();
    cfg.put("test", "test");
    Config test = new SmallRyeConfigBuilder().withSources(new PropertiesConfigSource(cfg, "test", 500)).build();
    Config config = ConfigHelper.merge(test, Collections.emptyMap(), Collections.emptyMap());
    assertThat(config).isEqualTo(test);
    assertThat(config.getValue("test", String.class)).isEqualTo("test");
    assertThat(config.getConfigSources()).hasSize(2);
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) HashMap(java.util.HashMap) Config(org.eclipse.microprofile.config.Config) Test(org.junit.jupiter.api.Test)

Aggregations

PropertiesConfigSource (io.smallrye.config.PropertiesConfigSource)7 Test (org.junit.jupiter.api.Test)4 SmallRyeConfigBuilder (io.smallrye.config.SmallRyeConfigBuilder)3 HashMap (java.util.HashMap)3 ConfigurationLoaderImpl (com.buschmais.jqassistant.core.configuration.impl.ConfigurationLoaderImpl)2 Config (org.eclipse.microprofile.config.Config)2 CliConfiguration (com.buschmais.jqassistant.commandline.configuration.CliConfiguration)1 PluginResolverFactory (com.buschmais.jqassistant.commandline.plugin.PluginResolverFactory)1 ConfigurationLoader (com.buschmais.jqassistant.core.configuration.api.ConfigurationLoader)1 PluginClassLoader (com.buschmais.jqassistant.core.plugin.api.PluginClassLoader)1 PluginResolver (com.buschmais.jqassistant.core.plugin.api.PluginResolver)1 SmallRyeConfig (io.smallrye.config.SmallRyeConfig)1 OpenApiConfigImpl (io.smallrye.openapi.api.OpenApiConfigImpl)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Node (org.jboss.shrinkwrap.api.Node)1