Package org.springframework.expression.spel.standard

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


    evaluateAndAskForReturnType("new Integer(37)", (byte) 37, Byte.class); // relying on registered type converters
  }

  @Test
  public void testNotWritable() throws Exception {
    SpelExpression expr = (SpelExpression)parser.parseExpression("37");
    assertFalse(expr.isWritable(new StandardEvaluationContext()));
    expr = (SpelExpression)parser.parseExpression("37L");
    assertFalse(expr.isWritable(new StandardEvaluationContext()));
    expr = (SpelExpression)parser.parseExpression("true");
    assertFalse(expr.isWritable(new StandardEvaluationContext()));
  }
View Full Code Here


    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

  }

  @Test
  public void testConstructorInvocation06() throws Exception {
    // repeated evaluation to drive use of cached executor
    SpelExpression expr = (SpelExpression) parser.parseExpression("new String('wibble')");
    String newString = expr.getValue(String.class);
    assertEquals("wibble", newString);
    newString = expr.getValue(String.class);
    assertEquals("wibble", newString);

    // not writable
    assertFalse(expr.isWritable(new StandardEvaluationContext()));

    // ast
    assertEquals("new String('wibble')", expr.toStringAST());
  }
View Full Code Here

    evaluate("T(java.lang.String)", "class java.lang.String", Class.class);
  }

  @Test
  public void testTypeReferencesAndQualifiedIdentifierCaching() throws Exception {
    SpelExpression expr = (SpelExpression) parser.parseExpression("T(java.lang.String)");
    assertFalse(expr.isWritable(new StandardEvaluationContext()));
    assertEquals("T(java.lang.String)", expr.toStringAST());
    assertEquals(String.class, expr.getValue(Class.class));
    // use cached QualifiedIdentifier:
    assertEquals("T(java.lang.String)", expr.toStringAST());
    assertEquals(String.class, expr.getValue(Class.class));
  }
View Full Code Here

    assertEquals(String.class, expr.getValue(Class.class));
  }
 
  @Test
  public void operatorVariants() throws Exception {
    SpelExpression expr = (SpelExpression)parser.parseExpression("#a < #b");
    EvaluationContext ctx = new StandardEvaluationContext();
    ctx.setVariable("a", (short)3);
    ctx.setVariable("b", (short)6);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("b", (byte)6);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)9);
    ctx.setVariable("b", (byte)6);
    assertFalse(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", 10L);
    ctx.setVariable("b", (short)30);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", (short)30);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", 30L);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", (byte)3);
    ctx.setVariable("b", 30f);
    assertTrue(expr.getValue(ctx, Boolean.class));
    ctx.setVariable("a", new BigInteger("10"));
    ctx.setVariable("b", new BigInteger("20"));
    assertTrue(expr.getValue(ctx, Boolean.class));
  }
View Full Code Here

  @Test
  public void projectionTypeDescriptors_1() throws Exception {
    StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
    SpelExpressionParser parser = new SpelExpressionParser();
    String el1 = "ls.![#this.equals('abc')]";
    SpelExpression exp = parser.parseRaw(el1);
    List<?> value = (List<?>) exp.getValue(ctx);
    // value is list containing [true,false]
    assertEquals(Boolean.class, value.get(0).getClass());
    TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
    assertEquals(null, evaluated.getElementTypeDescriptor());
  }
View Full Code Here

  @Test
  public void projectionTypeDescriptors_2() throws Exception {
    StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
    SpelExpressionParser parser = new SpelExpressionParser();
    String el1 = "as.![#this.equals('abc')]";
    SpelExpression exp = parser.parseRaw(el1);
    Object[] value = (Object[]) exp.getValue(ctx);
    // value is array containing [true,false]
    assertEquals(Boolean.class, value[0].getClass());
    TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
    assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
  }
View Full Code Here

  @Test
  public void projectionTypeDescriptors_3() throws Exception {
    StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
    SpelExpressionParser parser = new SpelExpressionParser();
    String el1 = "ms.![key.equals('abc')]";
    SpelExpression exp = parser.parseRaw(el1);
    List<?> value = (List<?>) exp.getValue(ctx);
    // value is list containing [true,false]
    assertEquals(Boolean.class, value.get(0).getClass());
    TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
    assertEquals(null, evaluated.getElementTypeDescriptor());
  }
View Full Code Here

    StandardEvaluationContext ctx = new StandardEvaluationContext(list);
    SpelExpressionParser parser = new SpelExpressionParser();

    String el1 = "#root.?[a < 'hhh']";
    SpelExpression exp = parser.parseRaw(el1);
    Object value = exp.getValue(ctx);
    assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());

    String el2 = "#root.?[a > 'hhh']";
    SpelExpression exp2 = parser.parseRaw(el2);
    Object value2 = exp2.getValue(ctx);
    assertEquals("[D(zzz)]", value2.toString());

    // trim out the nulls first
    String el3 = "#root.?[a!=null].?[a < 'hhh']";
    SpelExpression exp3 = parser.parseRaw(el3);
    Object value3 = exp3.getValue(ctx);
    assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
  }
View Full Code Here

    }

    StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver());
    SpelExpressionParser parser = new SpelExpressionParser();
    String ex = "getReserver().NE";
    SpelExpression exp = parser.parseRaw(ex);
    String value = (String) exp.getValue(ctx);
    assertEquals("abc", value);

    ex = "getReserver().ne";
    exp = parser.parseRaw(ex);
    value = (String) exp.getValue(ctx);
    assertEquals("def", value);

    ex = "getReserver().m[NE]";
    exp = parser.parseRaw(ex);
    value = (String) exp.getValue(ctx);
    assertEquals("xyz", value);

    ex = "getReserver().DIV";
    exp = parser.parseRaw(ex);
    assertEquals(1, exp.getValue(ctx));

    ex = "getReserver().div";
    exp = parser.parseRaw(ex);
    assertEquals(3, exp.getValue(ctx));

    exp = parser.parseRaw("NE");
    assertEquals("abc", exp.getValue(ctx));
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.standard.SpelExpression

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.