use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testSelection.
// 7.5.11
@SuppressWarnings("unchecked")
@Test
public void testSelection() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
List<Inventor> list = (List<Inventor>) parser.parseExpression("Members2.?[nationality == 'Serbian']").getValue(societyContext);
assertEquals(1, list.size());
assertEquals("Nikola Tesla", list.get(0).getName());
}
use of org.springframework.expression.spel.testresources.Inventor in project spring-framework by spring-projects.
the class SpelDocumentationTests method testRootObject.
@Test
public void testRootObject() throws Exception {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
// The constructor arguments are name, birthday, and nationaltiy.
Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian");
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("name");
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
String name = (String) exp.getValue(context);
assertEquals("Nikola Tesla", name);
}
Aggregations