Package org.springframework.expression

Examples of org.springframework.expression.EvaluationContext


    assertEquals(args[1], keyB);
  }

  @Test
  public void withReturnValue() throws Exception {
    EvaluationContext context = createEvaluationContext("theResult");
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, equalTo((Object) "theResult"));
  }
View Full Code Here


    assertThat(value, equalTo((Object) "theResult"));
  }

  @Test
  public void withNullReturn() throws Exception {
    EvaluationContext context = createEvaluationContext(null);
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, nullValue());
  }
View Full Code Here

    assertThat(value, nullValue());
  }

  @Test
  public void withoutReturnValue() throws Exception {
    EvaluationContext context = createEvaluationContext(ExpressionEvaluator.NO_RESULT);
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, nullValue());
  }
View Full Code Here

    assertThat(value, nullValue());
  }

  @Test
  public void unavailableReturnValue() throws Exception {
    EvaluationContext context = createEvaluationContext(ExpressionEvaluator.RESULT_UNAVAILABLE);
    try {
      new SpelExpressionParser().parseExpression("#result").getValue(context);
      fail("Should have failed to parse expression, result not available");
    }
    catch (VariableNotAvailableException e) {
View Full Code Here

    AnnotatedClass target = new AnnotatedClass();
    Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class,
        Object.class);
    Object[] args = new Object[] { new Object(), new Object() };
    Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
    EvaluationContext context = eval.createEvaluationContext(caches, method, args, target, target.getClass(), result);
    return context;
  }
View Full Code Here

  @Test
  public void testGetValuePerformance() throws Exception {
    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();
View Full Code Here

    checkString("hello world", ex.getValue(String.class));
    checkString("hello world", ex.getValue((Object)null, String.class));
    checkString("hello world", ex.getValue(new Rooty()));
    checkString("hello world", ex.getValue(new Rooty(), String.class));

    EvaluationContext ctx = new StandardEvaluationContext();
    checkString("hello world", ex.getValue(ctx));
    checkString("hello world", ex.getValue(ctx, String.class));
    checkString("hello world", ex.getValue(ctx, null, String.class));
    checkString("hello world", ex.getValue(ctx, new Rooty()));
    checkString("hello world", ex.getValue(ctx, new Rooty(), String.class));
View Full Code Here

  }

  @Test
  public void valueType() throws Exception {
    SpelExpressionParser parser = new SpelExpressionParser();
    EvaluationContext ctx = new StandardEvaluationContext();
    Class<?> c = parser.parseRaw("2").getValueType();
    assertEquals(Integer.class, c);
    c = parser.parseRaw("12").getValueType(ctx);
    assertEquals(Integer.class, c);
    c = parser.parseRaw("null").getValueType();
View Full Code Here

    assertEquals("hey there", expression.getValue(String.class));
  }
  
  @Test
  public void functionReference() throws Exception {
    EvaluationContext ctx = new StandardEvaluationContext();
    Method m = this.getClass().getDeclaredMethod("concat",String.class,String.class);
    ctx.setVariable("concat",m);
   
    expression = parser.parseExpression("#concat('a','b')");
    assertEquals("ab",expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals("ab",expression.getValue(ctx));
   
    expression = parser.parseExpression("#concat(#concat('a','b'),'c').charAt(1)");
    assertEquals('b',expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals('b',expression.getValue(ctx));
   
    expression = parser.parseExpression("#concat(#a,#b)");
    ctx.setVariable("a", "foo");
    ctx.setVariable("b", "bar");
    assertEquals("foobar",expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals("foobar",expression.getValue(ctx));
    ctx.setVariable("b", "boo");
    assertEquals("fooboo",expression.getValue(ctx));
   
    m = Math.class.getDeclaredMethod("pow",Double.TYPE,Double.TYPE);
    ctx.setVariable("kapow",m);
    expression = parser.parseExpression("#kapow(2.0d,2.0d)");
    assertEquals("4.0",expression.getValue(ctx).toString());
    assertCanCompile(expression);
    assertEquals("4.0",expression.getValue(ctx).toString());
  }
View Full Code Here

    assertEquals("a::xyz",expression.getValue(context).toString());
  }
 
  @Test
  public void functionReferenceVarargs() throws Exception {
    EvaluationContext ctx = new StandardEvaluationContext();
    Method m = this.getClass().getDeclaredMethod("join", String[].class);
    ctx.setVariable("join", m);
    expression = parser.parseExpression("#join('a','b','c')");
    assertEquals("abc",expression.getValue(ctx));
    assertCanCompile(expression);
    assertEquals("abc",expression.getValue(ctx));
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.EvaluationContext

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.