Search in sources :

Example 1 with Reserver

use of org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver in project spring-framework by spring-projects.

the class SpelReproTests method reservedWords_8228.

@Test
public void reservedWords_8228() throws Exception {
    // "DIV","EQ","GE","GT","LE","LT","MOD","NE","NOT"
    @SuppressWarnings("unused")
    class Reserver {

        public Reserver getReserver() {
            return this;
        }

        public String NE = "abc";

        public String ne = "def";

        public int DIV = 1;

        public int div = 3;

        public Map<String, String> m = new HashMap<>();

        Reserver() {
            m.put("NE", "xyz");
        }
    }
    StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver());
    SpelExpressionParser parser = new SpelExpressionParser();
    String ex = "getReserver().NE";
    SpelExpression exp = parser.parseRaw(ex);
    String value = (String) exp.getValue(ctx);
    assertEquals("abc", value);
    ex = "getReserver().ne";
    exp = parser.parseRaw(ex);
    value = (String) exp.getValue(ctx);
    assertEquals("def", value);
    ex = "getReserver().m[NE]";
    exp = parser.parseRaw(ex);
    value = (String) exp.getValue(ctx);
    assertEquals("xyz", value);
    ex = "getReserver().DIV";
    exp = parser.parseRaw(ex);
    assertEquals(1, exp.getValue(ctx));
    ex = "getReserver().div";
    exp = parser.parseRaw(ex);
    assertEquals(3, exp.getValue(ctx));
    exp = parser.parseRaw("NE");
    assertEquals("abc", exp.getValue(ctx));
}
Also used : Reserver(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1 Reserver (org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver)1