Package org.springframework.expression

Examples of org.springframework.expression.ExpressionParser


    assertNotNull(valueType);
  }

  @Test
  public void SPR10091_simpleTestValue() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
    Object value = parser.parseExpression("simpleProperty").getValue(evaluationContext);
    assertNotNull(value);
  }
View Full Code Here


    assertNotNull(value);
  }

  @Test
  public void SPR10091_primitiveTestValueType() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
    Class<?> valueType = parser.parseExpression("primitiveProperty").getValueType(evaluationContext);
    assertNotNull(valueType);
  }
View Full Code Here

    assertNotNull(valueType);
  }

  @Test
  public void SPR10091_primitiveTestValue() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new BooleanHolder());
    Object value = parser.parseExpression("primitiveProperty").getValue(evaluationContext);
    assertNotNull(value);
  }
View Full Code Here

  }

  @Test
  public void SPR10452() throws Exception {
    SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
    ExpressionParser parser = new SpelExpressionParser(configuration);

    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression spel = parser.parseExpression("#enumType.values()");

    context.setVariable("enumType", ABC.class);
    Object result = spel.getValue(context);
    assertNotNull(result);
    assertTrue(result.getClass().isArray());
View Full Code Here

  }

  @Test
  public void SPR9495() throws Exception {
    SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
    ExpressionParser parser = new SpelExpressionParser(configuration);

    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression spel = parser.parseExpression("#enumType.values()");

    context.setVariable("enumType", ABC.class);
    Object result = spel.getValue(context);
    assertNotNull(result);
    assertTrue(result.getClass().isArray());
View Full Code Here

    item2.setName("child2");

    item.add(item1);
    item.add(item2);

    ExpressionParser parser = new SpelExpressionParser();
    EvaluationContext context = new StandardEvaluationContext();
    Expression exp = parser.parseExpression("#item[0].name");
    context.setVariable("item", item);

    assertEquals("child1", exp.getValue(context));
  }
View Full Code Here

    Map<String, String> nameMap = new LinkedHashMap<String, String>();
    nameMap.put("givenName", "Arthur");
    map.put("value", nameMap);

    StandardEvaluationContext ctx = new StandardEvaluationContext(map);
    ExpressionParser parser = new SpelExpressionParser();
    String el1 = "#root['value'].get('givenName')";
    Expression exp = parser.parseExpression(el1);
    Object evaluated = exp.getValue(ctx);
    assertEquals("Arthur", evaluated);

    String el2 = "#root['value']['givenName']";
    exp = parser.parseExpression(el2);
    evaluated = exp.getValue(ctx);
    assertEquals("Arthur", evaluated);
  }
View Full Code Here

   * They are not utilized in this order; preventing a priority or order of operations
   * in evaluation of SPEL expressions for a given context.
   */
  @Test
  public void propertyAccessorOrder_8211() {
    ExpressionParser expressionParser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new ContextObject());

    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("firstContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("secondContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("thirdContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("fourthContext"));

    assertEquals("first", expressionParser.parseExpression("shouldBeFirst").getValue(evaluationContext));
    assertEquals("second", expressionParser.parseExpression("shouldBeSecond").getValue(evaluationContext));
    assertEquals("third", expressionParser.parseExpression("shouldBeThird").getValue(evaluationContext));
    assertEquals("fourth", expressionParser.parseExpression("shouldBeFourth").getValue(evaluationContext));
  }
View Full Code Here

   * Test the ability to subclass the ReflectiveMethodResolver and change how it
   * determines the set of methods for a type.
   */
  @Test
  public void customStaticFunctions_SPR9038() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>();
    methodResolvers.add(new ReflectiveMethodResolver() {
      @Override
      protected Method[] getMethods(Class<?> type) {
        try {
          return new Method[] {
              Integer.class.getDeclaredMethod("parseInt", new Class[] { String.class, Integer.TYPE }) };
        }
        catch (NoSuchMethodException ex) {
          return new Method[0];
        }
      }
    });

    context.setMethodResolvers(methodResolvers);
    Expression expression = parser.parseExpression("parseInt('-FF', 16)");

    Integer result = expression.getValue(context, "", Integer.class);
    assertEquals(-255, result.intValue());
  }
View Full Code Here

    assertEquals(-255, result.intValue());
  }

  @Test
  public void array() {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Expression expression = null;
    Object result = null;

    expression = parser.parseExpression("new java.lang.Long[0].class");
    result = expression.getValue(context, "");
    assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

    expression = parser.parseExpression("T(java.lang.Long[])");
    result = expression.getValue(context, "");
    assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

    expression = parser.parseExpression("T(java.lang.String[][][])");
    result = expression.getValue(context, "");
    assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
    assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());

    expression = parser.parseExpression("new int[0].class");
    result = expression.getValue(context, "");
    assertEquals("Equal assertion failed: ", "class [I", result.toString());

    expression = parser.parseExpression("T(int[][])");
    result = expression.getValue(context, "");
    assertEquals("class [[I", result.toString());
  }
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.