Search in sources :

Example 61 with EvaluationContext

use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.

the class SelectionAndProjectionTests method selectionWithIterable.

@Test
public void selectionWithIterable() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new IterableTestBean());
    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));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Example 62 with EvaluationContext

use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.

the class SelectionAndProjectionTests method selectLastItemInPrimitiveArray.

@Test
public void selectLastItemInPrimitiveArray() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("ints.$[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(4, value);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Example 63 with EvaluationContext

use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.

the class SelectionAndProjectionTests method selectLastItemInArray.

@Test
public void selectLastItemInArray() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(4, value);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Example 64 with EvaluationContext

use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.

the class SelectionAndProjectionTests method selectionWithArray.

@Test
public void selectionWithArray() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ArrayTestBean());
    Object value = expression.getValue(context);
    assertTrue(value.getClass().isArray());
    TypedValue typedValue = new TypedValue(value);
    assertEquals(Integer.class, typedValue.getTypeDescriptor().getElementTypeDescriptor().getType());
    Integer[] array = (Integer[]) value;
    assertEquals(5, array.length);
    assertEquals(new Integer(0), array[0]);
    assertEquals(new Integer(1), array[1]);
    assertEquals(new Integer(2), array[2]);
    assertEquals(new Integer(3), array[3]);
    assertEquals(new Integer(4), array[4]);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TypedValue(org.springframework.expression.TypedValue) Test(org.junit.Test)

Example 65 with EvaluationContext

use of org.springframework.expression.EvaluationContext in project spring-framework by spring-projects.

the class SelectionAndProjectionTests method projectionWithList.

@Test
public void projectionWithList() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
    EvaluationContext context = new StandardEvaluationContext();
    context.setVariable("testList", IntegerTestBean.createList());
    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));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Aggregations

EvaluationContext (org.springframework.expression.EvaluationContext)85 Test (org.junit.Test)72 Expression (org.springframework.expression.Expression)52 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)52 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)32 ArrayList (java.util.ArrayList)12 Authentication (org.springframework.security.core.Authentication)11 ExpressionParser (org.springframework.expression.ExpressionParser)10 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)10 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)10 MethodInvocation (org.aopalliance.intercept.MethodInvocation)9 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)9 List (java.util.List)8 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)8 TypedValue (org.springframework.expression.TypedValue)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Map (java.util.Map)5 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)5 AccessException (org.springframework.expression.AccessException)5 Method (java.lang.reflect.Method)4