Package org.springframework.expression.spel.standard

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


    assertEquals("brown", colorsMap.keySet().iterator().next());
  }

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


    assertEquals(7, list.get(2));
  }

  @Test
  public void projectionWithSet() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("#testList.![wrapper.value]");
    EvaluationContext context = new StandardEvaluationContext();
    context.setVariable("testList", IntegerTestBean.createSet());
    Object value = expression.getValue(context);
    assertTrue(value instanceof List);
    List<?> list = (List<?>) value;
View Full Code Here

    assertEquals(7, list.get(2));
  }

  @Test
  public void projectionWithArray() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("#testArray.![wrapper.value]");
    EvaluationContext context = new StandardEvaluationContext();
    context.setVariable("testArray", IntegerTestBean.createArray());
    Object value = expression.getValue(context);
    assertTrue(value.getClass().isArray());
    TypedValue typedValue = new TypedValue(value);
View Full Code Here

    checkConstantList("{1,2,Integer.valueOf(4)}", false);
    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));
    assertEquals("", o);
    assertEquals(4, testClass.list.size());
    try {
      o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
      fail();
    } catch (EvaluationException ee) {
      ee.printStackTrace();
      // success!
    }
    o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass));
    assertEquals("", o);
    assertEquals(4, testClass.getFoo().size());
  }
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 testRogueTrailingDotCausesNPE_SPR6866() {
    try {
      new SpelExpressionParser().parseExpression("placeOfBirth.foo.");
      fail("Should have failed to parse");
    } catch (ParseException e) {
      assertTrue(e instanceof SpelParseException);
      SpelParseException spe = (SpelParseException) e;
      assertEquals(SpelMessage.OOD, spe.getMessageCode());
View Full Code Here

  }

  @Test
  public void testPropertiesNested03() throws ParseException {
    try {
      new SpelExpressionParser().parseRaw("placeOfBirth.23");
      fail();
    } catch (SpelParseException spe) {
      assertEquals(spe.getMessageCode(), SpelMessage.UNEXPECTED_DATA_AFTER_DOT);
      assertEquals("23", spe.getInserts()[0]);
    }
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

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.