Search in sources :

Example 76 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method dollars.

@Test
public void dollars() {
    StandardEvaluationContext eContext = new StandardEvaluationContext(new XX());
    Expression expr = null;
    expr = new SpelExpressionParser().parseRaw("m['$foo']");
    eContext.setVariable("file_name", "$foo");
    assertEquals("wibble", expr.getValue(eContext, String.class));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 77 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_multiplyFloatWithDouble.

@Test
public void SPR9486_multiplyFloatWithDouble() {
    Number expectedNumber = 10.21f * 10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.21f * 10.2");
    Number result = expression.getValue(context, null, Number.class);
    assertEquals(expectedNumber, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 78 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method dollarPrefixedIdentifier_SPR7100.

/** $ related identifiers */
@Test
public void dollarPrefixedIdentifier_SPR7100() {
    Holder h = new Holder();
    StandardEvaluationContext eContext = new StandardEvaluationContext(h);
    eContext.addPropertyAccessor(new MapAccessor());
    h.map.put("$foo", "wibble");
    h.map.put("foo$bar", "wobble");
    h.map.put("foobar$$", "wabble");
    h.map.put("$", "wubble");
    h.map.put("$$", "webble");
    h.map.put("$_$", "tribble");
    String name = null;
    Expression expr = null;
    expr = new SpelExpressionParser().parseRaw("map.$foo");
    name = expr.getValue(eContext, String.class);
    assertEquals("wibble", name);
    expr = new SpelExpressionParser().parseRaw("map.foo$bar");
    name = expr.getValue(eContext, String.class);
    assertEquals("wobble", name);
    expr = new SpelExpressionParser().parseRaw("map.foobar$$");
    name = expr.getValue(eContext, String.class);
    assertEquals("wabble", name);
    expr = new SpelExpressionParser().parseRaw("map.$");
    name = expr.getValue(eContext, String.class);
    assertEquals("wubble", name);
    expr = new SpelExpressionParser().parseRaw("map.$$");
    name = expr.getValue(eContext, String.class);
    assertEquals("webble", name);
    expr = new SpelExpressionParser().parseRaw("map.$_$");
    name = expr.getValue(eContext, String.class);
    assertEquals("tribble", name);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 79 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class SpelReproTests method SPR9486_floatDivideByDouble.

@Test
public void SPR9486_floatDivideByDouble() {
    Number expectedNumber = -10.21f / -10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("-10.21f / -10.2");
    Number result = expression.getValue(context, null, Number.class);
    assertEquals(expectedNumber, result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 80 with SpelExpressionParser

use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.

the class TemplateExpressionParsingTests method testParsingSimpleTemplateExpression02.

@Test
public void testParsingSimpleTemplateExpression02() throws Exception {
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expr = parser.parseExpression("hello ${'to'} you", DEFAULT_TEMPLATE_PARSER_CONTEXT);
    Object o = expr.getValue();
    assertEquals("hello to you", o.toString());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) CompositeStringExpression(org.springframework.expression.common.CompositeStringExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Aggregations

SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)218 Test (org.junit.Test)190 Expression (org.springframework.expression.Expression)179 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)101 ExpressionParser (org.springframework.expression.ExpressionParser)89 EvaluationContext (org.springframework.expression.EvaluationContext)32 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)16 List (java.util.List)14 EvaluationException (org.springframework.expression.EvaluationException)13 Map (java.util.Map)11 LinkedHashMap (java.util.LinkedHashMap)8 BigInteger (java.math.BigInteger)6 AccessException (org.springframework.expression.AccessException)6 CompositeStringExpression (org.springframework.expression.common.CompositeStringExpression)6 ParseException (org.springframework.expression.ParseException)5 BigDecimal (java.math.BigDecimal)4 TypedValue (org.springframework.expression.TypedValue)4 TreeMap (java.util.TreeMap)3