Package org.springframework.expression.spel.standard

Examples of org.springframework.expression.spel.standard.SpelExpressionParser.parseExpression()


  @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


  @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

    checkConstantList("{1,2,{#a}}", false);
  }

  private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
    SpelExpressionParser parser = new SpelExpressionParser();
    SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
    SpelNode node = expression.getAST();
    assertTrue(node instanceof InlineList);
    InlineList inlineList = (InlineList) node;
    if (expectedToBeConstant) {
      assertTrue(inlineList.isConstant());
View Full Code Here

public class EvaluationTests extends AbstractExpressionTests {

  @Test
  public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException {
    ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Expression expression = parser.parseExpression("list[0]");
    TestClass testClass = new TestClass();
    Object o = null;
    o = expression.getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
View Full Code Here

    Expression expression = parser.parseExpression("list[0]");
    TestClass testClass = new TestClass();
    Object o = null;
    o = expression.getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    assertEquals(4, testClass.list.size());
    try {
      o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
      fail();
View Full Code Here

    assertEquals("", o);
    o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    assertEquals(4, testClass.list.size());
    try {
      o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
      fail();
    } catch (EvaluationException ee) {
      ee.printStackTrace();
      // success!
    }
View Full Code Here

      fail();
    } catch (EvaluationException ee) {
      ee.printStackTrace();
      // success!
    }
    o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    assertEquals(4, testClass.getFoo().size());
  }

  @Test(expected = SpelEvaluationException.class)
View Full Code Here

  public void testCreateMapsOnAttemptToIndexNull01() throws Exception {
    TestClass testClass = new TestClass();
    StandardEvaluationContext ctx = new StandardEvaluationContext(testClass);
    ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Object o = null;
    o = parser.parseExpression("map['a']").getValue(ctx);
    assertNull(o);
    o = parser.parseExpression("map").getValue(ctx);
    assertNotNull(o);

    o = parser.parseExpression("map2['a']").getValue(ctx);
View Full Code Here

    StandardEvaluationContext ctx = new StandardEvaluationContext(testClass);
    ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Object o = null;
    o = parser.parseExpression("map['a']").getValue(ctx);
    assertNull(o);
    o = parser.parseExpression("map").getValue(ctx);
    assertNotNull(o);

    o = parser.parseExpression("map2['a']").getValue(ctx);
    // map2 should be null, there is no setter
  }
View Full Code Here

    o = parser.parseExpression("map['a']").getValue(ctx);
    assertNull(o);
    o = parser.parseExpression("map").getValue(ctx);
    assertNotNull(o);

    o = parser.parseExpression("map2['a']").getValue(ctx);
    // map2 should be null, there is no setter
  }

  // wibble2 should be null (cannot be initialized dynamically), there is no setter
  @Test(expected = SpelEvaluationException.class)
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.