Search in sources :

Example 16 with ExpressionParser

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

the class SpelReproTests method SPR10452.

@Test
void SPR10452() {
    SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
    ExpressionParser parser = new SpelExpressionParser(configuration);
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression spel = parser.parseExpression("#enumType.values()");
    context.setVariable("enumType", ABC.class);
    Object result = spel.getValue(context);
    assertThat(result).isNotNull();
    assertThat(result.getClass().isArray()).isTrue();
    assertThat(Array.get(result, 0)).isEqualTo(ABC.A);
    assertThat(Array.get(result, 1)).isEqualTo(ABC.B);
    assertThat(Array.get(result, 2)).isEqualTo(ABC.C);
    context.setVariable("enumType", XYZ.class);
    result = spel.getValue(context);
    assertThat(result).isNotNull();
    assertThat(result.getClass().isArray()).isTrue();
    assertThat(Array.get(result, 0)).isEqualTo(XYZ.X);
    assertThat(Array.get(result, 1)).isEqualTo(XYZ.Y);
    assertThat(Array.get(result, 2)).isEqualTo(XYZ.Z);
}
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 17 with ExpressionParser

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

the class SpelReproTests method SPR10091_simpleTestValue.

@Test
void SPR10091_simpleTestValue() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
    Object value = parser.parseExpression("simpleProperty").getValue(evaluationContext);
    assertThat(value).isInstanceOf(Boolean.class);
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) Test(org.junit.jupiter.api.Test)

Example 18 with ExpressionParser

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

the class SpelReproTests method SPR9486_floatModulusFloat.

@Test
void SPR9486_floatModulusFloat() {
    Number expectedResult = 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(expectedResult);
}
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 19 with ExpressionParser

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

the class SpelReproTests method SPR9486_floatLessThanOrEqualDouble.

@Test
void SPR9486_floatLessThanOrEqualDouble() {
    Boolean expectedNumber = -10.21f <= -10.2;
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = parser.parseExpression("-10.21f <= -10.2");
    Boolean result = expression.getValue(context, null, Boolean.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 20 with ExpressionParser

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

the class SpelReproTests method propertyAccessorOrder_SPR8211.

/**
 * We add property accessors in the order:
 * First, Second, Third, Fourth.
 * They are not utilized in this order; preventing a priority or order of operations
 * in evaluation of SPEL expressions for a given context.
 */
@Test
void propertyAccessorOrder_SPR8211() {
    ExpressionParser expressionParser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new ContextObject());
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("firstContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("secondContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("thirdContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("fourthContext"));
    assertThat(expressionParser.parseExpression("shouldBeFirst").getValue(evaluationContext)).isEqualTo("first");
    assertThat(expressionParser.parseExpression("shouldBeSecond").getValue(evaluationContext)).isEqualTo("second");
    assertThat(expressionParser.parseExpression("shouldBeThird").getValue(evaluationContext)).isEqualTo("third");
    assertThat(expressionParser.parseExpression("shouldBeFourth").getValue(evaluationContext)).isEqualTo("fourth");
}
Also used : SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) ExpressionParser(cn.taketoday.expression.ExpressionParser) SpelExpressionParser(cn.taketoday.expression.spel.standard.SpelExpressionParser) 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