use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR9486_floatDivideByFloat.
@Test
public void SPR9486_floatDivideByFloat() {
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);
assertEquals(expectedNumber, result);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR5899.
@Test
public void SPR5899() throws Exception {
StandardEvaluationContext eContext = new StandardEvaluationContext(new Spr5899Class());
Expression expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(12)");
assertEquals(12, expr.getValue(eContext));
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull(null)");
assertEquals(null, expr.getValue(eContext));
try {
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)");
expr.getValue();
fail("Should have failed to find a method to which it could pass null");
} catch (EvaluationException see) {
// success
}
eContext.setTypeLocator(new MyTypeLocator());
// varargs
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull3(null,'a','b')");
assertEquals("ab", expr.getValue(eContext));
// varargs 2 - null is packed into the varargs
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull3(12,'a',null,'c')");
assertEquals("anullc", expr.getValue(eContext));
// check we can find the ctor ok
expr = new SpelExpressionParser().parseRaw("new Spr5899Class().toString()");
assertEquals("instance", expr.getValue(eContext));
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null).toString()");
assertEquals("instance", expr.getValue(eContext));
// ctor varargs
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null,'a','b').toString()");
assertEquals("instance", expr.getValue(eContext));
// ctor varargs 2
expr = new SpelExpressionParser().parseRaw("new Spr5899Class(null,'a', null, 'b').toString()");
assertEquals("instance", expr.getValue(eContext));
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR10091_primitiveTestValueType.
@Test
public void SPR10091_primitiveTestValueType() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Class<?> valueType = parser.parseExpression("primitiveProperty").getValueType(evaluationContext);
assertNotNull(valueType);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR10091_simpleTestValue.
@Test
public void SPR10091_simpleTestValue() {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
Object value = parser.parseExpression("simpleProperty").getValue(evaluationContext);
assertNotNull(value);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method indexingAsAPropertyAccess_SPR6968_4.
/**
* Should be accessing (setting) Goo.wibble field because 'bar' variable evaluates to
* "wibble"
*/
@Test
public void indexingAsAPropertyAccess_SPR6968_4() {
Goo g = Goo.instance;
StandardEvaluationContext eContext = new StandardEvaluationContext(g);
eContext.setVariable("bar", "wibble");
Expression expr = null;
expr = new SpelExpressionParser().parseRaw("instance[#bar]='world'");
// will access the field 'wibble' and not use a getter
expr.getValue(eContext, String.class);
assertEquals("world", g.wibble);
// will be using the cached accessor this time
expr.getValue(eContext, String.class);
assertEquals("world", g.wibble);
}
Aggregations