Package org.springframework.expression

Examples of org.springframework.expression.ExpressionParser


    props1.put("key2", "value2");
    props1.put("key3", "value3");

    Object bean = new TestBean("name1", new TestBean("name2", null, "Description 2", 15, props1), "description 1", 6, props1);

    ExpressionParser parser = new SpelExpressionParser();
    Expression expr = parser.parseExpression("testBean.properties['key2']");
    assertEquals("value2", expr.getValue(bean));
  }
View Full Code Here


  @Test
  public void testGetValueFromRootMap() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "value");

    ExpressionParser spelExpressionParser = new SpelExpressionParser();
    Expression expr = spelExpressionParser.parseExpression("#root['key']");
    assertEquals("value", expr.getValue(map));
  }
View Full Code Here

    Assume.group(TestGroup.PERFORMANCE);
    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "value");
    EvaluationContext context = new StandardEvaluationContext(map);

    ExpressionParser spelExpressionParser = new SpelExpressionParser();
    Expression expr = spelExpressionParser.parseExpression("#root['key']");

    StopWatch s = new StopWatch();
    s.start();
    for (int i = 0; i < 10000; i++) {
      expr.getValue(context);
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

  @Test(expected = SpelEvaluationException.class)
  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);
    // map2 should be null, there is no setter
  }
View Full Code Here

  // wibble2 should be null (cannot be initialized dynamically), there is no setter
  @Test(expected = SpelEvaluationException.class)
  public void testCreateObjectsOnAttemptToReferenceNull() 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("wibble.bar").getValue(ctx);
    assertEquals("hello", o);
    o = parser.parseExpression("wibble").getValue(ctx);
    assertNotNull(o);

    o = parser.parseExpression("wibble2.bar").getValue(ctx);
  }
View Full Code Here

  @Test
  public void initializingCollectionElementsOnWrite() throws Exception {
    TestPerson person = new TestPerson();
    EvaluationContext context = new StandardEvaluationContext(person);
    SpelParserConfiguration config = new SpelParserConfiguration(true, true);
    ExpressionParser parser = new SpelExpressionParser(config);
    Expression expression = parser.parseExpression("name");
    expression.setValue(context, "Oleg");
    assertEquals("Oleg", person.getName());

    expression = parser.parseExpression("address.street");
    expression.setValue(context, "123 High St");
    assertEquals("123 High St", person.getAddress().getStreet());

    expression = parser.parseExpression("address.crossStreets[0]");
    expression.setValue(context, "Blah");
    assertEquals("Blah", person.getAddress().getCrossStreets().get(0));

    expression = parser.parseExpression("address.crossStreets[3]");
    expression.setValue(context, "Wibble");
    assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
    assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
  }
View Full Code Here

  /**
   * Verifies behavior requested in SPR-9613.
   */
  @Test
  public void caseInsensitiveNullLiterals() {
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp;

    exp = parser.parseExpression("null");
    assertNull(exp.getValue());

    exp = parser.parseExpression("NULL");
    assertNull(exp.getValue());

    exp = parser.parseExpression("NuLl");
    assertNull(exp.getValue());
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.ExpressionParser

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.