use of org.springframework.expression.spel.standard.SpelExpressionParser 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.standard.SpelExpressionParser 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.standard.SpelExpressionParser 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);
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method SPR10452.
@Test
public void SPR10452() throws Exception {
SpelParserConfiguration configuration = new SpelParserConfiguration(false, false);
ExpressionParser parser = new SpelExpressionParser(configuration);
StandardEvaluationContext context = new StandardEvaluationContext();
Expression spel = parser.parseExpression("#enumType.values()");
context.setVariable("enumType", ABC.class);
Object result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(ABC.A, Array.get(result, 0));
assertEquals(ABC.B, Array.get(result, 1));
assertEquals(ABC.C, Array.get(result, 2));
context.setVariable("enumType", XYZ.class);
result = spel.getValue(context);
assertNotNull(result);
assertTrue(result.getClass().isArray());
assertEquals(XYZ.X, Array.get(result, 0));
assertEquals(XYZ.Y, Array.get(result, 1));
assertEquals(XYZ.Z, Array.get(result, 2));
}
use of org.springframework.expression.spel.standard.SpelExpressionParser in project spring-framework by spring-projects.
the class SpelReproTests method indexingAsAPropertyAccess_SPR6968_3.
/** Should be accessing Goo.wibble field because 'bar' variable evaluates to "wibble" */
@Test
public void indexingAsAPropertyAccess_SPR6968_3() {
StandardEvaluationContext eContext = new StandardEvaluationContext(new Goo());
eContext.setVariable("bar", "wibble");
String name = null;
Expression expr = null;
expr = new SpelExpressionParser().parseRaw("instance[#bar]");
// will access the field 'wibble' and not use a getter
name = expr.getValue(eContext, String.class);
assertEquals("wobble", name);
// will be using the cached accessor this time
name = expr.getValue(eContext, String.class);
assertEquals("wobble", name);
}
Aggregations