Search in sources :

Example 1 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project jqa-core-framework by jQAssistant.

the class PropertiesConfigBuilderTest method properties.

@Test
void properties() {
    propertiesConfigBuilder.with(PREFIX, "boolean-value", true);
    Map<String, Object> map = MapBuilder.<String, Object>builder().entry("key.1", "value1").entry("key.2", "value2").build();
    propertiesConfigBuilder.with(PREFIX, "map-value", map);
    propertiesConfigBuilder.with(PREFIX, "list-value", asList("element0", "element1"));
    PropertiesConfigSource propertiesConfigSource = propertiesConfigBuilder.build();
    assertThat(propertiesConfigSource.getValue("jqassistant.test.boolean-value")).isEqualTo("true");
    assertThat(propertiesConfigSource.getValue("jqassistant.test.map-value.\"key.1\"")).isEqualTo("value1");
    assertThat(propertiesConfigSource.getValue("jqassistant.test.map-value.\"key.2\"")).isEqualTo("value2");
    assertThat(propertiesConfigSource.getValue("jqassistant.test.list-value[0]")).isEqualTo("element0");
    assertThat(propertiesConfigSource.getValue("jqassistant.test.list-value[1]")).isEqualTo("element1");
}
Also used : PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) Test(org.junit.jupiter.api.Test)

Example 2 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project jqa-core-framework by jQAssistant.

the class AbstractPluginIT method createConfiguration.

/**
 * Load configuration for ITs.
 *
 * @return The  configuration.
 */
private Configuration createConfiguration(PropertiesConfigBuilder propertiesConfigBuilder) {
    ConfigurationLoader configurationLoader = new ConfigurationLoaderImpl(ConfigurationLoader.getDefaultConfigurationDirectory(getClassesDirectory(this.getClass())));
    PropertiesConfigSource propertiesConfigSource = propertiesConfigBuilder.build();
    return configurationLoader.load(Configuration.class, propertiesConfigSource);
}
Also used : PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) ConfigurationLoaderImpl(com.buschmais.jqassistant.core.configuration.impl.ConfigurationLoaderImpl) ConfigurationLoader(com.buschmais.jqassistant.core.configuration.api.ConfigurationLoader)

Example 3 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project jqa-commandline-tool by jQAssistant.

the class CliPluginResolverIT method resolve.

@Test
void resolve() {
    Map<String, String> configurationProperties = new HashMap<>();
    configurationProperties.put("jqassistant.plugins[0].group-id", "org.jqassistant.contrib.plugin");
    configurationProperties.put("jqassistant.plugins[0].artifact-id", "jqassistant-docker-plugin");
    configurationProperties.put("jqassistant.plugins[0].version", "1.11.0");
    PropertiesConfigSource testConfigSource = new PropertiesConfigSource(configurationProperties, "TestConfigSource", 110);
    ConfigurationLoaderImpl configurationLoader = new ConfigurationLoaderImpl(new File("src/test/resources"));
    CliConfiguration cliConfiguration = configurationLoader.load(CliConfiguration.class, testConfigSource);
    PluginResolverFactory pluginResolverFactory = new PluginResolverFactory();
    PluginResolver pluginResolver = pluginResolverFactory.create(cliConfiguration);
    PluginClassLoader pluginClassLoader = pluginResolver.createClassLoader(PluginResolverFactory.class.getClassLoader(), cliConfiguration.plugins());
    assertThat(pluginClassLoader).isNotNull();
}
Also used : PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource) HashMap(java.util.HashMap) PluginResolverFactory(com.buschmais.jqassistant.commandline.plugin.PluginResolverFactory) ConfigurationLoaderImpl(com.buschmais.jqassistant.core.configuration.impl.ConfigurationLoaderImpl) PluginResolver(com.buschmais.jqassistant.core.plugin.api.PluginResolver) File(java.io.File) CliConfiguration(com.buschmais.jqassistant.commandline.configuration.CliConfiguration) PluginClassLoader(com.buschmais.jqassistant.core.plugin.api.PluginClassLoader) Test(org.junit.jupiter.api.Test)

Example 4 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource 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 5 with PropertiesConfigSource

use of io.smallrye.config.PropertiesConfigSource in project camel-k-runtime by apache.

the class ApplicationConfigSourceProvider method getConfigSources.

@Override
public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
    final Map<String, String> appProperties = RuntimeSupport.loadApplicationProperties();
    final Map<String, String> usrProperties = RuntimeSupport.loadUserProperties();
    return List.of(new PropertiesConfigSource(appProperties, "camel-k-app", ConfigSource.DEFAULT_ORDINAL), new PropertiesConfigSource(usrProperties, "camel-k-usr", ConfigSource.DEFAULT_ORDINAL + 1));
}
Also used : PropertiesConfigSource(io.smallrye.config.PropertiesConfigSource)

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