Skip to content

Instantly share code, notes, and snippets.

@rdebusscher
Last active October 7, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdebusscher/f344ec2c6eb777f799ee775425745627 to your computer and use it in GitHub Desktop.
Save rdebusscher/f344ec2c6eb777f799ee775425745627 to your computer and use it in GitHub Desktop.
Testing MicroProfile Config
public class LocalTestContext {
private static final LocalTestContext INSTANCE = new LocalTestContext();
private final ThreadLocal<Map<String, String>> localTestData = ThreadLocal.withInitial(HashMap::new);
private LocalTestContext() {
}
public void addConfigValue(String key, String value) {
localTestData.get().put(key, value);
}
public String getConfigValue(String key) {
return localTestData.get().get(key);
}
public void reset() {
localTestData.remove();
}
public Set<String> keys() {
return localTestData.get().keySet();
}
public static LocalTestContext getInstance() {
return INSTANCE;
}
}
public class TestConfigSource implements ConfigSource {
@Override
public Set<String> getPropertyNames() {
return LocalTestContext.getInstance().keys();
}
@Override
public String getValue(String propertyName) {
return LocalTestContext.getInstance().getConfigValue(propertyName);
}
@Override
public String getName() {
return "LocalTestContext ConfigSource";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment