use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method projectionWithSet.
@Test
public void projectionWithSet() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("testList", IntegerTestBean.createSet());
Object value = expression.getValue(context);
assertTrue(value instanceof List);
List<?> list = (List<?>) value;
assertEquals(3, list.size());
assertEquals(5, list.get(0));
assertEquals(6, list.get(1));
assertEquals(7, list.get(2));
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SelectionAndProjectionTests method selectionWithList.
@Test
public void selectionWithList() throws Exception {
Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
Object value = expression.getValue(context);
assertTrue(value instanceof List);
List<?> list = (List<?>) value;
assertEquals(5, list.size());
assertEquals(0, list.get(0));
assertEquals(1, list.get(1));
assertEquals(2, list.get(2));
assertEquals(3, list.get(3));
assertEquals(4, list.get(4));
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class ExpressionStateTests method testRootObjectConstructor.
@Test
public void testRootObjectConstructor() {
EvaluationContext ctx = getContext();
// TypedValue root = ctx.getRootObject();
// supplied should override root on context
ExpressionState state = new ExpressionState(ctx, new TypedValue("i am a string"));
TypedValue stateRoot = state.getRootContextObject();
assertEquals(String.class, stateRoot.getTypeDescriptor().getType());
assertEquals("i am a string", stateRoot.getValue());
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class MethodInvocationTests method invokeMethodWithoutConversion.
@Test
public void invokeMethodWithoutConversion() throws Exception {
final BytesService service = new BytesService();
byte[] bytes = new byte[100];
StandardEvaluationContext context = new StandardEvaluationContext(bytes);
context.setBeanResolver(new BeanResolver() {
@Override
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
if ("service".equals(beanName)) {
return service;
}
return null;
}
});
Expression expression = parser.parseExpression("@service.handleBytes(#root)");
byte[] outBytes = expression.getValue(context, byte[].class);
assertSame(bytes, outBytes);
}
use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.
the class SpelCompilationCoverageTests method functionReferenceVarargs.
@Test
public void functionReferenceVarargs() throws Exception {
EvaluationContext ctx = new StandardEvaluationContext();
Method m = getClass().getDeclaredMethod("join", String[].class);
ctx.setVariable("join", m);
expression = parser.parseExpression("#join('a','b','c')");
assertEquals("abc", expression.getValue(ctx));
assertCanCompile(expression);
assertEquals("abc", expression.getValue(ctx));
}
Aggregations