Package org.springframework.expression.spel.support

Examples of org.springframework.expression.spel.support.StandardEvaluationContext


    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


  }

  @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

  @Test
  public void testScenario_DefiningVariablesThatWillBeAccessibleInExpressions() throws Exception {
    // Create a parser
    SpelExpressionParser parser = new SpelExpressionParser();
    // Use the standard evaluation context
    StandardEvaluationContext ctx = new StandardEvaluationContext();
    ctx.setVariable("favouriteColour","blue");
    List<Integer> primes = new ArrayList<Integer>();
    primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
    ctx.setVariable("primes",primes);

    Expression expr = parser.parseRaw("#favouriteColour");
    Object value = expr.getValue(ctx);
    assertEquals("blue", value);
View Full Code Here

  @Test
  public void testScenario_UsingADifferentRootContextObject() throws Exception {
    // Create a parser
    SpelExpressionParser parser = new SpelExpressionParser();
    // Use the standard evaluation context
    StandardEvaluationContext ctx = new StandardEvaluationContext();

    TestClass tc = new TestClass();
    tc.setProperty(42);
    tc.str = "wibble";
    ctx.setRootObject(tc);

    // read it, set it, read it again
    Expression expr = parser.parseRaw("str");
    Object value = expr.getValue(ctx);
    assertEquals("wibble", value);
View Full Code Here

  public void testScenario_RegisteringJavaMethodsAsFunctionsAndCallingThem() throws SecurityException, NoSuchMethodException {
    try {
      // Create a parser
      SpelExpressionParser parser = new SpelExpressionParser();
      // Use the standard evaluation context
      StandardEvaluationContext ctx = new StandardEvaluationContext();
      ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));

      Expression expr = parser.parseRaw("#repeat('hello')");
      Object value = expr.getValue(ctx);
      assertEquals("hellohello", value);
View Full Code Here

  @Test
  public void testScenario_AddingYourOwnPropertyResolvers_1() throws Exception {
    // Create a parser
    SpelExpressionParser parser = new SpelExpressionParser();
    // Use the standard evaluation context
    StandardEvaluationContext ctx = new StandardEvaluationContext();

    ctx.addPropertyAccessor(new FruitColourAccessor());
    Expression expr = parser.parseRaw("orange");
    Object value = expr.getValue(ctx);
    assertEquals(Color.orange, value);

    try {
View Full Code Here

  @Test
  public void testScenario_AddingYourOwnPropertyResolvers_2() throws Exception {
    // Create a parser
    SpelExpressionParser parser = new SpelExpressionParser();
    // Use the standard evaluation context
    StandardEvaluationContext ctx = new StandardEvaluationContext();

    ctx.addPropertyAccessor(new VegetableColourAccessor());
    Expression expr = parser.parseRaw("pea");
    Object value = expr.getValue(ctx);
    assertEquals(Color.green, value);

    try {
View Full Code Here

  private StandardEvaluationContext context;


  @Before
  public void setUp() throws Exception {
    this.context = new StandardEvaluationContext(new RootObject());
  }
View Full Code Here

public class SelectionAndProjectionTests {

  @Test
  public void selectionWithList() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.?[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof List);
    List<?> list = (List<?>) value;
    assertEquals(5, list.size());
    assertEquals(0, list.get(0));
View Full Code Here

  }

  @Test
  public void selectFirstItemInList() throws Exception {
    Expression expression = new SpelExpressionParser().parseRaw("integers.^[#this<5]");
    EvaluationContext context = new StandardEvaluationContext(new ListTestBean());
    Object value = expression.getValue(context);
    assertTrue(value instanceof Integer);
    assertEquals(0, value);
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.support.StandardEvaluationContext

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.