Currently Rocoto.expandVariables is not idempotent. For example, the following tests pass:
public class RocotoTest {
static class AModule extends ConfigurationModule {
@Override protected void bindConfigurations() {
bindProperty("aprop").toValue("avalue");
}
}
static class CModule extends ConfigurationModule {
@Override protected void bindConfigurations() {
bindProperty("cprop").toValue("${nodef|${aprop}}");
}
}
static class Injected {
@Inject @Named("aprop") String avalue;
@Inject @Named("cprop") String cvalue;
}
@Test public void testSingleExpansion() throws Exception {
Injected injected = Guice.createInjector(Rocoto.expandVariables(
new AModule(),
new CModule()
)).getInstance(Injected.class);
assertEquals("${aprop}", injected.cvalue);
}
@Test public void testDoubleExpansion() throws Exception {
Injected injected = Guice.createInjector(Rocoto.expandVariables(
new AModule(),
Rocoto.expandVariables(new CModule())
)).getInstance(Injected.class);
assertEquals("avalue", injected.cvalue);
}
}
In testSingleExpansion, the value ${nodef|${aprop}} is expanded to ${aprop}, while in testDoubleExpansion, the ${aprop} is further resolved to avalue. This makes sense, but is it really desirable? Is it ever the case that one wants unexpanded ${} expressions in default values?
Not sure myself, which is why I'm posting.