Search in sources :

Example 11 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR13055.

@Test
@SuppressWarnings("rawtypes")
void SPR13055() {
    List<Map<String, Object>> myPayload = new ArrayList<>();
    Map<String, Object> v1 = new HashMap<>();
    Map<String, Object> v2 = new HashMap<>();
    v1.put("test11", "test11");
    v1.put("test12", "test12");
    v2.put("test21", "test21");
    v2.put("test22", "test22");
    myPayload.add(v1);
    myPayload.add(v2);
    EvaluationContext context = new StandardEvaluationContext(myPayload);
    ExpressionParser parser = new SpelExpressionParser();
    String ex = "#root.![T(cn.taketoday.util.StringUtils).collectionToCommaDelimitedString(#this.values())]";
    List res = parser.parseExpression(ex).getValue(context, List.class);
    assertThat(res.toString()).isEqualTo("[test12,test11, test22,test21]");
    res = parser.parseExpression("#root.![#this.values()]").getValue(context, List.class);
    assertThat(res.toString()).isEqualTo("[[test12, test11], [test22, test21]]");
    res = parser.parseExpression("#root.![values()]").getValue(context, List.class);
    assertThat(res.toString()).isEqualTo("[[test12, test11], [test22, test21]]");
}
Also used : StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationContext(cn.taketoday.expression.EvaluationContext) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 12 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9486_subtractFloatWithFloat.

@Test
void SPR9486_subtractFloatWithFloat() {
    Number expectedNumber = 10.21f - 10.2f;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.21f - 10.2f");
    Number result = expression.getValue(context, null, Number.class);
    assertThat(result).isEqualTo(expectedNumber);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 13 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9486_multiplyFloatWithFloat.

@Test
void SPR9486_multiplyFloatWithFloat() {
    Number expectedNumber = 10.21f * 10.2f;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("10.21f * 10.2f");
    Number result = expression.getValue(context, null, Number.class);
    assertThat(result).isEqualTo(expectedNumber);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 14 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelReproTests method SPR9486_subtractFloatWithDouble.

@Test
void SPR9486_subtractFloatWithDouble() {
    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);
    assertThat(result).isEqualTo(expectedNumber);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) SpelExpression(cn.taketoday.expression.spel.standard.SpelExpression) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 15 with ExpressionParser

use of cn.taketoday.expression.ExpressionParser in project today-infrastructure by TAKETODAY.

the class SpelDocumentationTests method rootObject.

@Test
void rootObject() throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.set(1856, 7, 9);
    // The constructor arguments are name, birthday, and nationaltiy.
    Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression("name");
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(tesla);
    String name = (String) exp.getValue(context);
    assertThat(name).isEqualTo("Nikola Tesla");
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) Expression(cn.taketoday.expression.Expression) GregorianCalendar(java.util.GregorianCalendar) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Inventor(cn.taketoday.expression.spel.testresources.Inventor) Test(org.junit.jupiter.api.Test)

Aggregations

ExpressionParser (cn.taketoday.expression.ExpressionParser)132 SpelExpressionParser (cn.taketoday.expression.spel.standard.SpelExpressionParser)132 Test (org.junit.jupiter.api.Test)132 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)112 Expression (cn.taketoday.expression.Expression)110 SpelExpression (cn.taketoday.expression.spel.standard.SpelExpression)72 EvaluationContext (cn.taketoday.expression.EvaluationContext)16 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 Map (java.util.Map)10 EvaluationException (cn.taketoday.expression.EvaluationException)6 MethodResolver (cn.taketoday.expression.MethodResolver)6 ReflectiveMethodResolver (cn.taketoday.expression.spel.support.ReflectiveMethodResolver)6 Method (java.lang.reflect.Method)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 TreeMap (java.util.TreeMap)6 MethodParameter (cn.taketoday.core.MethodParameter)4 TypeDescriptor (cn.taketoday.core.TypeDescriptor)4 AccessException (cn.taketoday.expression.AccessException)4