Package org.springframework.expression.spel.standard

Examples of org.springframework.expression.spel.standard.SpelExpressionParser


    assertEquals(0, value);
  }

  @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


    assertEquals(4, value);
  }

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

    assertEquals(new Integer(4), array[4]);
  }

  @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

    assertEquals(0, value);
  }

  @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

    assertEquals(4, value);
  }

  @Test
  public void selectionWithPrimitiveArray() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("ints.?[#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());
View Full Code Here

    assertEquals(new Integer(4), array[4]);
  }

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

    assertEquals(0, value);
  }

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

  @Test
  @SuppressWarnings("unchecked")
  public void selectionWithMap() {
    EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression("colors.?[key.startsWith('b')]");

    Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
    assertEquals(3, colorsMap.size());
    assertTrue(colorsMap.containsKey("beige"));
    assertTrue(colorsMap.containsKey("blue"));
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void selectFirstItemInMap() {
    EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
    ExpressionParser parser = new SpelExpressionParser();

    Expression exp = parser.parseExpression("colors.^[key.startsWith('b')]");
    Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
    assertEquals(1, colorsMap.size());
    assertEquals("beige", colorsMap.keySet().iterator().next());
  }
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void selectLastItemInMap() {
    EvaluationContext context = new StandardEvaluationContext(new MapTestBean());
    ExpressionParser parser = new SpelExpressionParser();

    Expression exp = parser.parseExpression("colors.$[key.startsWith('b')]");
    Map<String, String> colorsMap = (Map<String, String>) exp.getValue(context);
    assertEquals(1, colorsMap.size());
    assertEquals("brown", colorsMap.keySet().iterator().next());
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.standard.SpelExpressionParser

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.