8000 [Testsuite PoC] Adding config to provide option to select supplier types by wojnarfilip · Pull Request #31295 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
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,54 +1,40 @@
package org.keycloak.test.framework.config;

import io.smallrye.config.DotEnvConfigSourceProvider;
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;
import java.util.ArrayList;
import java.util.List;

public class Config {

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

private Properties localEnv = new Properties();
private static final String kcTestConfigPath = System.getProperty("kc.test.config");

private Config() {
File envFile = new File(".env");
if (envFile.isFile()) {
try {
localEnv.load(new FileInputStream(envFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
static {
List<ConfigSource> configSources = new ArrayList<>();

public static Config getInstance() {
return instance;
}
if (kcTestConfigPath != null) {
configSources.add(new FileConfigSource());
}

public String getSelectedSupplier(Class valueType) {
return getString("kc-test-" + ValueTypeAlias.getAlias(valueType));
config = new SmallRyeConfigBuilder()
.addDefaultSources()
.addDefaultInterceptors()
.withSources(configSources)
.withSources(new DotEnvConfigSourceProvider())
.build();
}

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

String value = System.getProperty(propKey);
if (value != null) {
return value;
}

value = System.getenv(envKey);
if (value != null) {
return value;
}
public static String getSelectedSupplier(Class valueType) {
String key = "kc.test." + ValueTypeAlias.getAlias(valueType);

value = localEnv.getProperty(envKey);
if (value != null) {
return value;
if (config.isPropertyPresent(key)) {
return config.getValue(key, String.class);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.keycloak.test.framework.config;

import org.eclipse.microprofile.config.spi.ConfigSource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class FileConfigSource implements ConfigSource {

private static final Map<String, String> configuration = new HashMap<>();

static {
Properties p = new Properties();
String configFilePath = System.getProperty("kc.test.config");
File fileConfig = new File(configFilePath);

try(FileInputStream inputStream = new FileInputStream(fileConfig)) {
p.load(inputStream);
p.forEach((k, v) -> configuration.put(k.toString(), v.toString()));
} catch (FileNotFoundException e) {

} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public int getOrdinal() {
return 500;
}

@Override
public Map<String, String> getProperties() {
return configuration;
}

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

@Override
public String getValue(String property) {
return configuration.get(property);
}

@Override
public String getName() {
return FileConfigSource.class.getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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
0