Search in sources :

Example 6 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project keycloak by keycloak.

the class ConfigurationTest method testDatabaseDefaults.

@Test
public void testDatabaseDefaults() {
    System.setProperty(CLI_ARGS, "--db=dev-file");
    SmallRyeConfig config = createConfig();
    assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue());
    assertEquals("jdbc:h2:file:~/data/h2/keycloakdb;;AUTO_SERVER=TRUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
    System.setProperty(CLI_ARGS, "--db=dev-mem");
    config = createConfig();
    assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue());
    assertEquals("jdbc:h2:mem:keycloakdb", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());
    assertEquals("h2", config.getConfigValue("quarkus.datasource.db-kind").getValue());
    System.setProperty(CLI_ARGS, "--db=dev-mem" + ARG_SEPARATOR + "--db-username=other");
    config = createConfig();
    assertEquals("sa", config.getConfigValue("quarkus.datasource.username").getValue());
    System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-username=other");
    config = createConfig();
    assertEquals("other", config.getConfigValue("quarkus.datasource.username").getValue());
    System.setProperty(CLI_ARGS, "--db=postgres");
    config = createConfig();
    assertEquals(null, config.getConfigValue("quarkus.datasource.username").getValue());
}
Also used : QuarkusH2Dialect(io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.Test)

Example 7 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project keycloak by keycloak.

the class ConfigurationTest method testOptionValueWithEqualSign.

@Test
public void testOptionValueWithEqualSign() {
    System.setProperty(CLI_ARGS, "--db-password=my_secret=");
    SmallRyeConfig config = createConfig();
    assertEquals("my_secret=", config.getConfigValue("kc.db-password").getValue());
}
Also used : SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.Test)

Example 8 with SmallRyeConfig

use of io.smallrye.config.SmallRyeConfig in project smallrye-open-api by smallrye.

the class DeploymentProcessor method config.

/**
 * Creates the config from the microprofile-config.properties file in the application. The spec defines that the
 * config file may be present in two locations.
 */
private static OpenApiConfig config(final WebArchive war) {
    Optional<Node> microprofileConfig = Stream.of(ofNullable(war.get("/META-INF/microprofile-config.properties")), ofNullable(war.get("/WEB-INF/classes/META-INF/microprofile-config.properties"))).filter(Optional::isPresent).findFirst().flatMap(node -> node);
    if (!microprofileConfig.isPresent()) {
        return new OpenApiConfigImpl(ConfigProvider.getConfig());
    }
    Properties properties = new Properties();
    try (InputStreamReader reader = new InputStreamReader(microprofileConfig.get().getAsset().openStream(), UTF_8)) {
        properties.load(reader);
    } catch (IOException e) {
        e.printStackTrace();
    }
    SmallRyeConfig config = new SmallRyeConfigBuilder().addDefaultSources().addDefaultInterceptors().withSources(new PropertiesConfigSource(properties, "microprofile-config.properties")).build();
    return new OpenApiConfigImpl(config);
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) OpenApiConfigImpl(io.smallrye.openapi.api.OpenApiConfigImpl) Optional(java.util.Optional) InputStreamReader(java.io.InputStreamReader) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Node(org.jboss.shrinkwrap.api.Node) IOException(java.io.IOException) Properties(java.util.Properties)

Example 9 with SmallRyeConfig

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

the class KafkaConfigMergeTest method testConfigMerge.

@Test
public void testConfigMerge() {
    Map<String, Object> globalMap = new HashMap<>();
    globalMap.put("a", "string");
    globalMap.put("b", 23);
    globalMap.put("c", "some-value");
    Map<String, String> conf = new HashMap<>();
    globalMap.put("d", "string");
    globalMap.put("e", 23);
    globalMap.put("c", "some-value-from-conf");
    SmallRyeConfig config = new SmallRyeConfigBuilder().addDefaultSources().withSources(new ConfigSource() {

        @Override
        public Set<String> getPropertyNames() {
            return conf.keySet();
        }

        @Override
        public String getValue(String propertyName) {
            return conf.get(propertyName);
        }

        @Override
        public String getName() {
            return "internal";
        }
    }).build();
    Config merged = ConfigHelper.merge(config, globalMap);
    assertThat(merged.getValue("a", String.class)).isEqualTo("string");
    assertThat(merged.getOptionalValue("a", String.class)).contains("string");
    assertThat(merged.getValue("b", Integer.class)).isEqualTo(23);
    assertThat(merged.getOptionalValue("b", Integer.class)).contains(23);
    assertThat(merged.getValue("d", String.class)).isEqualTo("string");
    assertThat(merged.getOptionalValue("d", String.class)).contains("string");
    assertThat(merged.getValue("e", Integer.class)).isEqualTo(23);
    assertThat(merged.getOptionalValue("e", Integer.class)).contains(23);
    assertThat(merged.getValue("c", String.class)).isEqualTo("some-value-from-conf");
    assertThat(merged.getOptionalValue("c", String.class)).contains("some-value-from-conf");
    assertThatThrownBy(() -> merged.getValue("missing", String.class)).isInstanceOf(NoSuchElementException.class);
    assertThatThrownBy(() -> merged.getValue("missing", Integer.class)).isInstanceOf(NoSuchElementException.class);
    assertThat(merged.getOptionalValue("missing", String.class)).isEmpty();
    assertThat(merged.getOptionalValue("missing", Integer.class)).isEmpty();
    assertThatThrownBy(() -> merged.getValue("a", Integer.class)).isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> merged.getValue("d", Integer.class)).isInstanceOf(IllegalArgumentException.class);
}
Also used : ConfigSource(org.eclipse.microprofile.config.spi.ConfigSource) SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) HashMap(java.util.HashMap) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Config(org.eclipse.microprofile.config.Config) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) Test(org.junit.jupiter.api.Test)

Example 10 with SmallRyeConfig

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

the class JsonHelperTest method createTestConfig.

private ConnectorConfig createTestConfig(ConfigSource... extraSources) {
    Map<String, String> channelConnector = Collections.singletonMap("mp.messaging.incoming.testChannel.connector", "smallrye-kafka");
    SmallRyeConfig config = new SmallRyeConfigBuilder().addDefaultSources().withSources(getConfigSourceFromMap(channelConnector, 0)).withSources(extraSources).build();
    return new TestConnectorConfig(config);
}
Also used : SmallRyeConfigBuilder(io.smallrye.config.SmallRyeConfigBuilder) SmallRyeConfig(io.smallrye.config.SmallRyeConfig)

Aggregations

SmallRyeConfig (io.smallrye.config.SmallRyeConfig)19 Test (org.junit.Test)12 SmallRyeConfigBuilder (io.smallrye.config.SmallRyeConfigBuilder)4 MariaDBDialect (org.hibernate.dialect.MariaDBDialect)3 QuarkusH2Dialect (io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect)2 ConfigSource (org.eclipse.microprofile.config.spi.ConfigSource)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 BodyEvent (ch.qos.logback.core.joran.event.BodyEvent)1 SaxEvent (ch.qos.logback.core.joran.event.SaxEvent)1 StartEvent (ch.qos.logback.core.joran.event.StartEvent)1 Configuration (com.buschmais.jqassistant.core.configuration.api.Configuration)1 BodySub (io.quarkiverse.logback.runtime.events.BodySub)1 EventSubstitution (io.quarkiverse.logback.runtime.events.EventSubstitution)1 QuarkusPostgreSQL10Dialect (io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect)1 PropertiesConfigSource (io.smallrye.config.PropertiesConfigSource)1 YamlConfigSource (io.smallrye.config.source.yaml.YamlConfigSource)1 OpenApiConfigImpl (io.smallrye.openapi.api.OpenApiConfigImpl)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1