Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
package org.keycloak.test.framework.config;

import io.smallrye.config.DotEnvConfigSourceProvider;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.keycloak.test.framework.injection.ValueTypeAlias;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Config {

private final static Config instance = new Config();
private static final SmallRyeConfig config = initConfig();

private Properties localEnv = new Properties();

private Config() {
File envFile = new File(".env");
if (envFile.isFile()) {
try {
localEnv.load(new FileInputStream(envFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String getSelectedSupplier(Class<?> valueType) {
return config.getOptionalValue("kc.test." + ValueTypeAlias.getAlias(valueType), String.class).orElse(null);
}

public static Config getInstance() {
return instance;
}

public String getSelectedSupplier(Class valueType) {
return getString("kc-test-" + ValueTypeAlias.getAlias(valueType));
}
private static SmallRyeConfig initConfig() {
SmallRyeConfigBuilder configBuilder = new SmallRyeConfigBuilder()
.addDefaultSources()
.addDefaultInterceptors()
.withSources(new DotEnvConfigSourceProvider());

public String getString(String key) {
String propKey = key.replace('-', '.');
String envKey = key.replace('-', '_').toUpperCase();

String value = System.getProperty(propKey);
if (value != null) {
return value;
ConfigSource testConfigSource = initTestConfigSource();
if (testConfigSource != null) {
configBuilder.withSources(testConfigSource);
}

value = System.getenv(envKey);
if (value != null) {
return value;
}
return configBuilder.build();
}

value = localEnv.getProperty(envKey);
if (value != null) {
return value;
private static ConfigSource initTestConfigSource() {
try {
String testConfigFile = System.getProperty("kc.test.config", System.getenv("KC_TEST_CONFIG"));
return testConfigFile != null ? new PropertiesConfigSource(new File(testConfigFile).toURI().toURL()) : null;
} catch (Exception e) {
throw new RuntimeException(e);
}

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void loadSuppliers() {
Class supplierValueType = supplier.getValueType();

if (!loadedValueTypes.contains(supplierValueType)) {
String requestedSupplier = Config.getInstance().getSelectedSupplier(supplierValueType);
String requestedSupplier = Config.getSelectedSupplier(supplierValueType);
if (requestedSupplier != null) {
if (requestedSupplier.equals(supplier.getAlias())) {
shouldAdd = true;
Expand Down