use of io.smallrye.config.SmallRyeConfigBuilder 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.SmallRyeConfigBuilder 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.SmallRyeConfigBuilder 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);
}
use of io.smallrye.config.SmallRyeConfigBuilder in project jqa-core-framework by buschmais.
the class ConfigurationLoaderImpl method load.
@Override
public Configuration load(File configurationDirectory, ConfigSource... configSources) {
List<ConfigSource> yamlConfigSources = getYamlConfigSources(configurationDirectory);
SmallRyeConfig config = new SmallRyeConfigBuilder().withMapping(Configuration.class).addDefaultSources().withSources(yamlConfigSources).withSources(configSources).withValidateUnknown(false).build();
return config.getConfigMapping(Configuration.class);
}
use of io.smallrye.config.SmallRyeConfigBuilder 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);
}
Aggregations