Skip to content

Commit 085c614

Browse files
author
mccabd
committed
Update as detailed in the PR
Rather than substituting at get() we only substitute before put
1 parent dfc4070 commit 085c614

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/com/github/bordertech/config/DefaultConfiguration.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,15 +1315,14 @@ protected String get(final String key, final String defolt) {
13151315
* @return the property value or null
13161316
*/
13171317
protected String get(final String key) {
1318-
// Check environment property
1318+
// Check profile property
13191319
if (useProfileKey(key)) {
13201320
String result = backing.get(getProfileKey(key));
13211321
if (result != null) {
1322-
return StringSubstitutor.replace(result, backing);
1322+
return result;
13231323
}
13241324
}
1325-
//Final substitution check
1326-
return StringSubstitutor.replace(backing.get(key), backing);
1325+
return backing.get(key);
13271326
}
13281327

13291328
/**
@@ -1345,9 +1344,12 @@ protected void addOrModifyProperty(final String name, final String value) {
13451344
throw new IllegalArgumentException("value parameter can not be null.");
13461345
}
13471346

1348-
recordMessage("modifyProperties() - Adding property '" + name + "' with the value '" + value + "'.");
1347+
//Check for substitution variables
1348+
final String updatedValue = StringSubstitutor.replace(value, backing);
13491349

1350-
runtimeProperties.put(name, value);
1350+
recordMessage("modifyProperties() - Adding property '" + name + "' with the value '" + updatedValue + "'.");
1351+
1352+
runtimeProperties.put(name, updatedValue);
13511353

13521354
handlePropertiesChanged();
13531355
}

src/test/java/com/github/bordertech/config/DefaultConfigurationTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,6 @@ public void testSubstitution() {
102102
assertPropertyEquals("substitute.part1And2And3Key", "part1Value+part2Value+part3Value");
103103
assertPropertyEquals("substitute.combinedKey", "multiPart1ValuemultiPart2Value");
104104
assertPropertyEquals("substitute.reurse", "${substitute.recurse}");
105-
assertPropertyEquals("substitute.key.not.defined.in.value", "${this.key.is.not.defined.initially}");
106-
assertPropertyEquals("substitute.key.with.profile.in.value", "prefix_${bordertech.config.profile}_suffix");
107-
108-
config.setProperty("this.key.is.not.defined.initially", "isNowDefined");
109-
110-
assertPropertyEquals("substitute.key.not.defined.in.value", "isNowDefined");
111-
112-
config.setProperty(PROFILE_PROPERTY, "a_profile");
113-
114-
assertPropertyEquals("substitute.key.with.profile.in.value", "prefix_a_profile_suffix");
115-
116-
config.clearProperty(PROFILE_PROPERTY);
117105
}
118106

119107
@Test
@@ -167,6 +155,14 @@ public void testSetProperty() {
167155
assertPropertyEquals(STRING_PROPERTY_KEY, "simplePropertyValue");
168156
config.setProperty(STRING_PROPERTY_KEY, "changedValue");
169157
assertPropertyEquals(STRING_PROPERTY_KEY, "changedValue");
158+
159+
final String key = "aNewPropertyKey";
160+
161+
config.setProperty(key, "${" + STRING_PROPERTY_KEY + "} with other details");
162+
assertPropertyEquals(key, "changedValue with other details");
163+
164+
config.setProperty(key, "${keyDoesNotExist} with other details");
165+
assertPropertyEquals(key, "${keyDoesNotExist} with other details");
170166
}
171167

172168
@Test

0 commit comments

Comments
 (0)