Examples of SpELExpression


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

  @Test
  public void failsWhenSettingContextForExpression_SPR12326() {
      SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this
              .getClass().getClassLoader()));
      Person3 person = new Person3("foo", 1);
      SpelExpression expression = parser.parseRaw("#it?.age?.equals([0])");
      StandardEvaluationContext context = new StandardEvaluationContext(new Object[] { 1 });
      context.setVariable("it", person);
      expression.setEvaluationContext(context);
      assertTrue(expression.getValue(Boolean.class));
      assertTrue(expression.getValue(Boolean.class));      
      assertCanCompile(expression);
      assertTrue(expression.getValue(Boolean.class));
  }
View Full Code Here

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

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

    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

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

  }

  @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

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

    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

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

    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

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

  @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

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

  @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

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

  @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

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

    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
TOP
Copyright © 2018 www.massapi.com. 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.