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