Search in sources :

Example 61 with Expression

use of org.springframework.expression.Expression in project spring-framework by spring-projects.

the class IndexingTests method indexIntoGenericPropertyContainingArray.

@Test
public void indexIntoGenericPropertyContainingArray() {
    String[] property = new String[] { "bar" };
    this.property = property;
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("property");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.String[]", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property, expression.getValue(this));
    expression = parser.parseExpression("property[0]");
    assertEquals("bar", expression.getValue(this));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 62 with Expression

use of org.springframework.expression.Expression in project spring-framework by spring-projects.

the class IndexingTests method indexIntoPropertyContainingList.

@Test
public void indexIntoPropertyContainingList() {
    List<Integer> property = new ArrayList<>();
    property.add(3);
    this.parameterizedList = property;
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("parameterizedList");
    assertEquals("java.util.ArrayList<java.lang.Integer>", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property, expression.getValue(this));
    expression = parser.parseExpression("parameterizedList[0]");
    assertEquals(3, expression.getValue(this));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 63 with Expression

use of org.springframework.expression.Expression in project spring-framework by spring-projects.

the class IndexingTests method resolveCollectionElementType.

@SuppressWarnings("unchecked")
@Test
public void resolveCollectionElementType() {
    listNotGeneric = new ArrayList(2);
    listNotGeneric.add(5);
    listNotGeneric.add(6);
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("listNotGeneric");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals("5,6", expression.getValue(this, String.class));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 64 with Expression

use of org.springframework.expression.Expression in project spring-framework by spring-projects.

the class SpelDocumentationTests method testEqualityCheck.

@Test
public void testEqualityCheck() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(tesla);
    Expression exp = parser.parseExpression("name == 'Nikola Tesla'");
    // evaluates to true
    boolean isEqual = exp.getValue(context, Boolean.class);
    assertTrue(isEqual);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Example 65 with Expression

use of org.springframework.expression.Expression in project spring-framework by spring-projects.

the class SpelReproTests method SPR10486.

@Test
public void SPR10486() throws Exception {
    SpelExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    Spr10486 rootObject = new Spr10486();
    Expression classNameExpression = parser.parseExpression("class.name");
    Expression nameExpression = parser.parseExpression("name");
    assertThat(classNameExpression.getValue(context, rootObject), equalTo((Object) Spr10486.class.getName()));
    assertThat(nameExpression.getValue(context, rootObject), equalTo((Object) "name"));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Aggregations

Expression (org.springframework.expression.Expression)288 Test (org.junit.Test)228 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)172 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)155 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)114 ExpressionParser (org.springframework.expression.ExpressionParser)76 EvaluationContext (org.springframework.expression.EvaluationContext)52 ArrayList (java.util.ArrayList)32 CompoundExpression (org.springframework.expression.spel.ast.CompoundExpression)18 HashMap (java.util.HashMap)17 EvaluationException (org.springframework.expression.EvaluationException)17 Authentication (org.springframework.security.core.Authentication)16 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)14 List (java.util.List)13 Map (java.util.Map)13 ParseException (org.springframework.expression.ParseException)11 LinkedHashMap (java.util.LinkedHashMap)10 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)10 MethodInvocation (org.aopalliance.intercept.MethodInvocation)9 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)9