Search in sources :

Example 6 with Inventor

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());
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ArrayList(java.util.ArrayList) List(java.util.List) Inventor(org.springframework.expression.spel.testresources.Inventor) Test(org.junit.Test)

Example 7 with Inventor

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);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) GregorianCalendar(java.util.GregorianCalendar) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Inventor(org.springframework.expression.spel.testresources.Inventor) Test(org.junit.Test)

Aggregations

Inventor (org.springframework.expression.spel.testresources.Inventor)7 Test (org.junit.Test)6 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)6 GregorianCalendar (java.util.GregorianCalendar)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Expression (org.springframework.expression.Expression)1 ExpressionParser (org.springframework.expression.ExpressionParser)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 PlaceOfBirth (org.springframework.expression.spel.testresources.PlaceOfBirth)1