Search in sources :

Example 91 with Expression

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

the class SetValueTests method setValueExpectError.

/**
	 * Call setValue() but expect it to fail.
	 */
protected void setValueExpectError(String expression, Object value) {
    try {
        Expression e = parser.parseExpression(expression);
        if (e == null) {
            fail("Parser returned null for expression");
        }
        if (DEBUG) {
            SpelUtilities.printAbstractSyntaxTree(System.out, e);
        }
        StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
        e.setValue(lContext, value);
        fail("expected an error");
    } catch (ParseException pe) {
        pe.printStackTrace();
        fail("Unexpected Exception: " + pe.getMessage());
    } catch (EvaluationException ee) {
    // success!
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ParseException(org.springframework.expression.ParseException) EvaluationException(org.springframework.expression.EvaluationException)

Example 92 with Expression

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

the class IndexingTests method setGenericPropertyContainingListAutogrow.

@Test
public void setGenericPropertyContainingListAutogrow() {
    List<Integer> property = new ArrayList<>();
    this.property = property;
    SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Expression expression = parser.parseExpression("property");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property, expression.getValue(this));
    expression = parser.parseExpression("property[0]");
    try {
        expression.setValue(this, "4");
    } catch (EvaluationException ex) {
        assertTrue(ex.getMessage().startsWith("EL1053E"));
    }
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) EvaluationException(org.springframework.expression.EvaluationException) Test(org.junit.Test)

Example 93 with Expression

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

the class IndexingTests method emptyList.

@Test
public void emptyList() {
    listOfScalarNotGeneric = new ArrayList();
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("listOfScalarNotGeneric");
    assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals("", 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 94 with Expression

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

the class IndexingTests method resolveCollectionElementTypeNull.

@Test
public void resolveCollectionElementTypeNull() {
    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expression = parser.parseExpression("listNotGeneric");
    assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.List<?>", expression.getValueTypeDescriptor(this).toString());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Example 95 with Expression

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

the class IndexingTests method indexIntoGenericPropertyContainingGrowingList2.

@Test
public void indexIntoGenericPropertyContainingGrowingList2() {
    List<String> property2 = new ArrayList<>();
    this.property2 = property2;
    SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
    SpelExpressionParser parser = new SpelExpressionParser(configuration);
    Expression expression = parser.parseExpression("property2");
    assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString());
    assertEquals(property2, expression.getValue(this));
    expression = parser.parseExpression("property2[0]");
    try {
        assertEquals("bar", expression.getValue(this));
    } catch (EvaluationException ex) {
        assertTrue(ex.getMessage().startsWith("EL1053E"));
    }
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ArrayList(java.util.ArrayList) EvaluationException(org.springframework.expression.EvaluationException) Test(org.junit.Test)

Aggregations

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