Non-idempotency of expandVariables

8 views
Skip to first unread message

Timothy Peierls

unread,
Jan 20, 2012, 3:11:06 PM1/20/12
to roc...@googlegroups.com
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.

--tim

Simone Tripodi

unread,
Jan 21, 2012, 8:04:42 AM1/21/12
to roc...@googlegroups.com
Hi Tim!

can you attach the test, in a form that doesn't need to be copied and
recoded, somewhere - maybe in your GitHub fork - so we can have a look
at it?

Many thanks in advance, have anice weekend!

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

Timothy Peierls

unread,
Jan 21, 2012, 10:27:22 AM1/21/12
to roc...@googlegroups.com
Some day I'll get with the program and learn how to use git and GitHub. Until then, I've placed the test class here:


It should be possible to drop right into any JUnit 4 setup.

--tim

Simone Tripodi

unread,
Jan 22, 2012, 8:23:38 AM1/22/12
to roc...@googlegroups.com
Hi Tim!!

nice, I'm having a look at your test this evening!

Thanks a lot, all the best,
-Simo

Reply all
Reply to author
Forward
0 new messages