Package org.springframework.expression.spel.standard

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


  @Test
  public void reservedWordProperties_9862() throws Exception {
    StandardEvaluationContext ctx = new StandardEvaluationContext();
    SpelExpressionParser parser = new SpelExpressionParser();
    SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
    Object value = expression.getValue(ctx);
    assertEquals(value, Reserver.CONST);
  }
View Full Code Here


  }
  */

  @Test
  public void testUtilities() throws ParseException {
    SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    SpelUtilities.printAbstractSyntaxTree(ps, expr);
    ps.flush();
    String s = baos.toString();
View Full Code Here

    context.setRootObject(new TestObject());
    LocalFilter filter = new LocalFilter();
    context.registerMethodFilter(TestObject.class,filter);

    // Filter will be called but not do anything, so first doit() will be invoked
    SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
    String result = expr.getValue(context,String.class);
    assertEquals("1", result);
    assertTrue(filter.filterCalled);

    // Filter will now remove non @Anno annotated methods
    filter.removeIfNotAnnotated = true;
    filter.filterCalled = false;
    expr = (SpelExpression) parser.parseExpression("doit(1)");
    result = expr.getValue(context,String.class);
    assertEquals("double 1.0", result);
    assertTrue(filter.filterCalled);

    // check not called for other types
    filter.filterCalled=false;
    context.setRootObject(new String("abc"));
    expr = (SpelExpression) parser.parseExpression("charAt(0)");
    result = expr.getValue(context,String.class);
    assertEquals("a", result);
    assertFalse(filter.filterCalled);

    // check de-registration works
    filter.filterCalled = false;
    context.registerMethodFilter(TestObject.class,null);//clear filter
    context.setRootObject(new TestObject());
    expr = (SpelExpression) parser.parseExpression("doit(1)");
    result = expr.getValue(context,String.class);
    assertEquals("1", result);
    assertFalse(filter.filterCalled);
  }
View Full Code Here

    evaluateAndCheckError("'abc'-true",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);

    StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
    eContext.setOperatorOverloader(new StringAndBooleanAddition());

    SpelExpression expr = (SpelExpression)parser.parseExpression("'abc'+true");
    assertEquals("abctrue",expr.getValue(eContext));

    expr = (SpelExpression)parser.parseExpression("'abc'-true");
    assertEquals("abc",expr.getValue(eContext));

    expr = (SpelExpression)parser.parseExpression("'abc'+null");
    assertEquals("abcnull",expr.getValue(eContext));
  }
View Full Code Here

   * The standard reflection resolver cannot find properties on null objects but some
   * supplied resolver might be able to - so null shouldn't crash the reflection resolver.
   */
  @Test
  public void testAccessingOnNullObject() throws Exception {
    SpelExpression expr = (SpelExpression)parser.parseExpression("madeup");
    EvaluationContext context = new StandardEvaluationContext(null);
    try {
      expr.getValue(context);
      fail("Should have failed - default property resolver cannot resolve on null");
    } catch (Exception e) {
      checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
    }
    assertFalse(expr.isWritable(context));
    try {
      expr.setValue(context,"abc");
      fail("Should have failed - default property resolver cannot resolve on null");
    } catch (Exception e) {
      checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
    }
  }
View Full Code Here

    checkConstantMap("{a:1,b:2,c:{d:{1,2,3},e:{4,5,6},f:{'a','b','c'}}}", true);
  }

  private void checkConstantMap(String expressionText, boolean expectedToBeConstant) {
    SpelExpressionParser parser = new SpelExpressionParser();
    SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
    SpelNode node = expression.getAST();
    assertTrue(node instanceof InlineMap);
    InlineMap inlineMap = (InlineMap) node;
    if (expectedToBeConstant) {
      assertTrue(inlineMap.isConstant());
    }
View Full Code Here

    evaluate("null?.![true]", null, null);
  }

  @Test
  public void testProjection06() throws Exception {
    SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.![true]");
    assertEquals("'abc'.![true]", expr.toStringAST());
  }
View Full Code Here

    evaluate("mapOfNumbersUpToTen.$[key>5].size()", "1", Integer.class);
  }

  @Test
  public void testSelectionAST() throws Exception {
    SpelExpression expr = (SpelExpression) parser.parseExpression("'abc'.^[true]");
    assertEquals("'abc'.^[true]", expr.toStringAST());
    expr = (SpelExpression) parser.parseExpression("'abc'.?[true]");
    assertEquals("'abc'.?[true]", expr.toStringAST());
    expr = (SpelExpression) parser.parseExpression("'abc'.$[true]");
    assertEquals("'abc'.$[true]", expr.toStringAST());
  }
View Full Code Here

   * @param expression the expression to parse
   * @param expectedStringFormOfAST the expected string form of the AST
   */
  public void parseCheck(String expression, String expectedStringFormOfAST) {
    try {
      SpelExpression e = parser.parseRaw(expression);
      if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
        SpelUtilities.printAbstractSyntaxTree(System.err, e);
      }
      if (e == null) {
        fail("Parsed exception was null");
      }
      assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
    } catch (ParseException ee) {
      ee.printStackTrace();
      fail("Unexpected Exception: " + ee.getMessage());
    }
  }
View Full Code Here

    Assert.notNull(expression, "Expression must not be null!");
    Assert.notNull(context, "AggregationOperationContext must not be null!");
    Assert.notNull(params, "Parameters must not be null!");

    SpelExpression spelExpression = (SpelExpression) PARSER.parseExpression(expression);
    ExpressionState state = new ExpressionState(new StandardEvaluationContext(params), CONFIG);
    ExpressionNode node = ExpressionNode.from(spelExpression.getAST(), state);

    return transform(new AggregationExpressionTransformationContext<ExpressionNode>(node, null, null, context));
  }
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.