use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method elvis_SPR7209_1.
// end bean resolver tests
@Test
public void elvis_SPR7209_1() {
StandardEvaluationContext eContext = new StandardEvaluationContext(new XX());
Expression expr = null;
// Different parts of elvis expression are null
expr = new SpelExpressionParser().parseRaw("(?:'default')");
assertEquals("default", expr.getValue());
expr = new SpelExpressionParser().parseRaw("?:'default'");
assertEquals("default", expr.getValue());
expr = new SpelExpressionParser().parseRaw("?:");
assertEquals(null, expr.getValue());
// Different parts of ternary expression are null
try {
expr = new SpelExpressionParser().parseRaw("(?'abc':'default')");
expr.getValue(eContext);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.TYPE_CONVERSION_ERROR, see.getMessageCode());
}
expr = new SpelExpressionParser().parseRaw("(false?'abc':null)");
assertEquals(null, expr.getValue());
// Assignment
try {
expr = new SpelExpressionParser().parseRaw("(='default')");
expr.getValue(eContext);
fail();
} catch (SpelEvaluationException see) {
assertEquals(SpelMessage.SETVALUE_NOT_SUPPORTED, see.getMessageCode());
}
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method SPR13055.
@Test
@SuppressWarnings("rawtypes")
public void SPR13055() throws Exception {
List<Map<String, Object>> myPayload = new ArrayList<>();
Map<String, Object> v1 = new HashMap<>();
Map<String, Object> v2 = new HashMap<>();
v1.put("test11", "test11");
v1.put("test12", "test12");
v2.put("test21", "test21");
v2.put("test22", "test22");
myPayload.add(v1);
myPayload.add(v2);
EvaluationContext context = new StandardEvaluationContext(myPayload);
ExpressionParser parser = new SpelExpressionParser();
String ex = "#root.![T(org.springframework.util.StringUtils).collectionToCommaDelimitedString(#this.values())]";
List res = parser.parseExpression(ex).getValue(context, List.class);
assertEquals("[test12,test11, test22,test21]", res.toString());
res = parser.parseExpression("#root.![#this.values()]").getValue(context, List.class);
assertEquals("[[test12, test11], [test22, test21]]", res.toString());
res = parser.parseExpression("#root.![values()]").getValue(context, List.class);
assertEquals("[[test12, test11], [test22, test21]]", res.toString());
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method SPR11609.
@Test
public void SPR11609() {
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor());
Expression exp = new SpelExpressionParser().parseExpression("T(org.springframework.expression.spel.SpelReproTests$MapWithConstant).X");
assertEquals(1, exp.getValue(sec));
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method projectionTypeDescriptors_3.
@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());
}
use of org.springframework.expression.spel.support.StandardEvaluationContext in project spring-framework by spring-projects.
the class SpelReproTests method nestedProperties_SPR6923.
@Test
public void nestedProperties_SPR6923() {
StandardEvaluationContext eContext = new StandardEvaluationContext(new Foo());
Expression expr = new SpelExpressionParser().parseRaw("resource.resource.server");
String name = expr.getValue(eContext, String.class);
assertEquals("abc", name);
}
Aggregations