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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations