Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of default value for for properties using the Key Expansion mechanism #84

Merged
merged 2 commits into from Jul 24, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -80,6 +80,10 @@ private boolean equals(Method a, Method b) {
private Object resolveProperty(Method method, Object... args) {
String key = expandKey(method);
String value = propertiesManager.getProperty(key);
if (value == null && !isFeatureDisabled(method, VARIABLE_EXPANSION)) {
String unexpandedKey = key(method);
value = propertiesManager.getProperty(unexpandedKey);
}
if (value == null)
return null;
Object result = convert(method, method.getReturnType(), format(method, expandVariables(method, value), args));
Expand Down
Expand Up @@ -131,4 +131,23 @@ public void testKeyExpansionFromAnotherKeyWithImportOverriding() {
assertNull("mypass2", cfg.password()); // expansion is disabled on method level
}

@Sources("classpath:org/aeonbits/owner/variableexpansion/KeyExpansionExample.xml")
public interface UseOfDefaultValueIfNotFound extends Config {

@DefaultValue("dev")
String env();

@Config.Key("servers.${env}.nonDefinedInSourceKey")
@Config.DefaultValue("wantedValue")
String undefinedPropInSource();

}

@Test
public void testKeyExpansionAndDefaultValue() {
UseOfDefaultValueIfNotFound cfg = ConfigFactory.create(UseOfDefaultValueIfNotFound.class);

assertEquals("dev", cfg.env());
assertEquals("wantedValue", cfg.undefinedPropInSource());
}
}