use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatPowerFloat.
@Test
public void SPR9486_floatPowerFloat() {
Number expectedResult = Math.pow(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);
assertEquals(expectedResult, result);
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method propertyAccessorOrder_8211.
/**
* 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
public void propertyAccessorOrder_8211() {
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"));
assertEquals("first", expressionParser.parseExpression("shouldBeFirst").getValue(evaluationContext));
assertEquals("second", expressionParser.parseExpression("shouldBeSecond").getValue(evaluationContext));
assertEquals("third", expressionParser.parseExpression("shouldBeThird").getValue(evaluationContext));
assertEquals("fourth", expressionParser.parseExpression("shouldBeFourth").getValue(evaluationContext));
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class MapAccessTests method testGetValuePerformance.
@Test
public void testGetValuePerformance() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
Map<String, String> map = new HashMap<>();
map.put("key", "value");
EvaluationContext context = new StandardEvaluationContext(map);
ExpressionParser spelExpressionParser = new SpelExpressionParser();
Expression expr = spelExpressionParser.parseExpression("#root['key']");
StopWatch s = new StopWatch();
s.start();
for (int i = 0; i < 10000; i++) {
expr.getValue(context);
}
s.stop();
assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method increment04.
@Test
public void increment04() {
Integer i = 42;
StandardEvaluationContext ctx = new StandardEvaluationContext(i);
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
try {
Expression e = parser.parseExpression("++1");
e.getValue(ctx, Integer.class);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode());
}
try {
Expression e = parser.parseExpression("1++");
e.getValue(ctx, Integer.class);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode());
}
}
use of org.springframework.expression.ExpressionParser in project spring-framework by spring-projects.
the class EvaluationTests method testCreateListsOnAttemptToIndexNull01.
@Test
public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression expression = parser.parseExpression("list[0]");
TestClass testClass = new TestClass();
Object o = null;
o = expression.getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
assertEquals(4, testClass.list.size());
try {
o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
fail();
} catch (EvaluationException ee) {
ee.printStackTrace();
// success!
}
o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
assertEquals("", o);
assertEquals(4, testClass.getFoo().size());
}
Aggregations