assertEquals("aName", ScriptVariableParser.getVariableFromMaps("a.name", transients, ps)); assertEquals(a, ScriptVariableParser.getVariableFromMaps("a", transients, ps)); assertEquals("blah", ScriptVariableParser.getVariableFromMaps("blah", transients, ps)); assertEquals("jack", ScriptVariableParser.getVariableFromMaps("a2.b.name", transients, ps)); assertEquals(new Integer(-1), ScriptVariableParser.getVariableFromMaps("a2.b.age", transients, ps)); assertEquals("bar", ScriptVariableParser.getVariableFromMaps("foo", transients, ps));
DefaultVariableResolver resolver = new DefaultVariableResolver(); assertEquals("aName", resolver.getVariableFromMaps("a.name", transients, ps)); assertEquals(a, resolver.getVariableFromMaps("a", transients, ps)); assertEquals("blah", resolver.getVariableFromMaps("blah", transients, ps)); assertEquals("jack", resolver.getVariableFromMaps("a2.b.name", transients, ps)); assertEquals(new Integer(-1), resolver.getVariableFromMaps("a2.b.age", transients, ps)); assertEquals("bar", resolver.getVariableFromMaps("foo", transients, ps));
    public void testVariableTranslation() {        HashMap transients = new HashMap();        MemoryPropertySet ps = new MemoryPropertySet();        ps.init(null, null);        A a = new A("aName", new B(100, "bName"));        A a2 = new A("biff", new B(-1, "jack"));        transients.put("a", a);        transients.put("blah", "blah");        ps.setString("blah", "NOT BLAH");        ps.setObject("a2", a2);        ps.setString("foo", "bar");        assertEquals("aName", ScriptVariableParser.getVariableFromMaps("a.name", transients, ps));        assertEquals(a, ScriptVariableParser.getVariableFromMaps("a", transients, ps));        assertEquals("blah", ScriptVariableParser.getVariableFromMaps("blah", transients, ps));        assertEquals("jack", ScriptVariableParser.getVariableFromMaps("a2.b.name", transients, ps));        assertEquals(new Integer(-1), ScriptVariableParser.getVariableFromMaps("a2.b.age", transients, ps));        assertEquals("bar", ScriptVariableParser.getVariableFromMaps("foo", transients, ps));        assertEquals("hello, jack, what is your age? -1", ScriptVariableParser.translateVariables("hello, ${a2.b.name}, what is your age? ${a2.b.age}", transients, ps));        assertEquals("hello, , what is your age? -1", ScriptVariableParser.translateVariables("hello, ${I.Don't.EXIST}, what is your age? ${a2.b.age}", transients, ps));    }