Package org.springframework.expression

Examples of org.springframework.expression.EvaluationContext


    assertEquals("abc",expression.getValue(ctx));
  }
 
  @Test
  public void variableReference_userDefined() throws Exception {
    EvaluationContext ctx = new StandardEvaluationContext();
    ctx.setVariable("target", "abc");
    expression = parser.parseExpression("#target");
    assertEquals("abc",expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals("abc",expression.getValue(ctx))
    ctx.setVariable("target", "123");
    assertEquals("123",expression.getValue(ctx))
    ctx.setVariable("target", 42);
    try {
      assertEquals(42,expression.getValue(ctx));
      fail();
    } catch (SpelEvaluationException see) {
      assertTrue(see.getCause() instanceof ClassCastException);
    }
 
    ctx.setVariable("target", "abc");
    expression = parser.parseExpression("#target.charAt(0)");
    assertEquals('a',expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals('a',expression.getValue(ctx))
    ctx.setVariable("target", "1");
    assertEquals('1',expression.getValue(ctx))
    ctx.setVariable("target", 42);
    try {
      assertEquals('4',expression.getValue(ctx));
      fail();
    } catch (SpelEvaluationException see) {
      assertTrue(see.getCause() instanceof ClassCastException);
View Full Code Here


public class SelectionAndProjectionTests {

  @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));
View Full Code Here

  }

  @Test
  public void selectFirstItemInList() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(0, value);
  }
View Full Code Here

  }

  @Test
  public void selectLastItemInList() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(4, value);
  }
View Full Code Here

  }

  @Test
  public void selectionWithSet() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof List);
    List<?> list = (List<?>) value;
    assertEquals(5, list.size());
    assertEquals(0, list.get(0));
View Full Code Here

  }

  @Test
  public void selectFirstItemInSet() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(0, value);
  }
View Full Code Here

  }

  @Test
  public void selectLastItemInSet() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.$[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new SetTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(4, value);
  }
View Full Code Here

  }

  @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;
View Full Code Here

  }

  @Test
  public void selectFirstItemInArray() 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(0, value);
  }
View Full Code Here

  }

  @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);
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.EvaluationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.