Search in sources :

Example 76 with StandardEvaluationContext

use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.

the class SpelReproTests method reservedWordProperties_9862.

@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);
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Test(org.junit.Test)

Example 77 with StandardEvaluationContext

use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.

the class OpPlusTests method test_binaryPlusWithLeftStringOperand.

@Test
public void test_binaryPlusWithLeftStringOperand() {
    ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
    StringLiteral n1 = new StringLiteral("\"number is \"", -1, "\"number is \"");
    LongLiteral n2 = new LongLiteral("123", -1, 123);
    OpPlus o = new OpPlus(-1, n1, n2);
    TypedValue value = o.getValueInternal(expressionState);
    assertEquals(String.class, value.getTypeDescriptor().getObjectType());
    assertEquals(String.class, value.getTypeDescriptor().getType());
    assertEquals("number is 123", value.getValue());
}
Also used : ExpressionState(org.springframework.expression.spel.ExpressionState) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TypedValue(org.springframework.expression.TypedValue) Test(org.junit.Test)

Example 78 with StandardEvaluationContext

use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.

the class OpPlusTests method test_unaryPlusWithStringLiteral.

@Test(expected = SpelEvaluationException.class)
public void test_unaryPlusWithStringLiteral() {
    ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
    StringLiteral str = new StringLiteral("word", -1, "word");
    OpPlus o = new OpPlus(-1, str);
    o.getValueInternal(expressionState);
}
Also used : ExpressionState(org.springframework.expression.spel.ExpressionState) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Example 79 with StandardEvaluationContext

use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.

the class OpPlusTests method test_binaryPlusWithTimeConverted.

@Test
public void test_binaryPlusWithTimeConverted() {
    final SimpleDateFormat format = new SimpleDateFormat("hh :--: mm :--: ss", Locale.ENGLISH);
    GenericConversionService conversionService = new GenericConversionService();
    conversionService.addConverter(new Converter<Time, String>() {

        @Override
        public String convert(Time source) {
            return format.format(source);
        }
    });
    StandardEvaluationContext evaluationContextConverter = new StandardEvaluationContext();
    evaluationContextConverter.setTypeConverter(new StandardTypeConverter(conversionService));
    ExpressionState expressionState = new ExpressionState(evaluationContextConverter);
    Time time = new Time(new Date().getTime());
    VariableReference var = new VariableReference("timeVar", -1);
    var.setValue(expressionState, time);
    StringLiteral n2 = new StringLiteral("\" is now\"", -1, "\" is now\"");
    OpPlus o = new OpPlus(-1, var, n2);
    TypedValue value = o.getValueInternal(expressionState);
    assertEquals(String.class, value.getTypeDescriptor().getObjectType());
    assertEquals(String.class, value.getTypeDescriptor().getType());
    assertEquals(format.format(time) + " is now", value.getValue());
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Time(java.sql.Time) Date(java.util.Date) StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) ExpressionState(org.springframework.expression.spel.ExpressionState) SimpleDateFormat(java.text.SimpleDateFormat) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) TypedValue(org.springframework.expression.TypedValue) Test(org.junit.Test)

Example 80 with StandardEvaluationContext

use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.

the class OpPlusTests method test_binaryPlusWithStringOperands.

@Test
public void test_binaryPlusWithStringOperands() {
    ExpressionState expressionState = new ExpressionState(new StandardEvaluationContext());
    StringLiteral n1 = new StringLiteral("\"foo\"", -1, "\"foo\"");
    StringLiteral n2 = new StringLiteral("\"bar\"", -1, "\"bar\"");
    OpPlus o = new OpPlus(-1, n1, n2);
    TypedValue value = o.getValueInternal(expressionState);
    assertEquals(String.class, value.getTypeDescriptor().getObjectType());
    assertEquals(String.class, value.getTypeDescriptor().getType());
    assertEquals("foobar", value.getValue());
}
Also used : ExpressionState(org.springframework.expression.spel.ExpressionState) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TypedValue(org.springframework.expression.TypedValue) Test(org.junit.Test)

Aggregations

StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)251 Test (org.junit.Test)211 Expression (org.springframework.expression.Expression)157 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)104 ExpressionParser (org.springframework.expression.ExpressionParser)81 EvaluationContext (org.springframework.expression.EvaluationContext)43 ArrayList (java.util.ArrayList)27 List (java.util.List)14 HashMap (java.util.HashMap)12 EvaluationException (org.springframework.expression.EvaluationException)12 TypedValue (org.springframework.expression.TypedValue)12 Map (java.util.Map)11 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)8 BigInteger (java.math.BigInteger)7 LinkedHashMap (java.util.LinkedHashMap)7 ExpressionState (org.springframework.expression.spel.ExpressionState)7 AccessException (org.springframework.expression.AccessException)6 Inventor (org.springframework.expression.spel.testresources.Inventor)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5