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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations