Last active
October 7, 2022 17:00
-
-
Save rdebusscher/f344ec2c6eb777f799ee775425745627 to your computer and use it in GitHub Desktop.
Testing MicroProfile Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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