Search in sources :

Example 71 with EvaluationContext

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

the class ExpressionEvaluatorTests method withoutReturnValue.

@Test
public void withoutReturnValue() throws Exception {
    EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, nullValue());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) Test(org.junit.Test)

Example 72 with EvaluationContext

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

the class ExpressionEvaluatorTests method withNullReturn.

@Test
public void withNullReturn() throws Exception {
    EvaluationContext context = createEvaluationContext(null);
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, nullValue());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) Test(org.junit.Test)

Example 73 with EvaluationContext

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

the class ExpressionEvaluatorTests method withReturnValue.

@Test
public void withReturnValue() throws Exception {
    EvaluationContext context = createEvaluationContext("theResult");
    Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
    assertThat(value, equalTo("theResult"));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) Test(org.junit.Test)

Example 74 with EvaluationContext

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

the class ExpressionEvaluatorTests method resolveBeanReference.

@Test
public void resolveBeanReference() throws Exception {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
    applicationContext.registerBeanDefinition("myBean", beanDefinition);
    applicationContext.refresh();
    EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT, applicationContext);
    Object value = new SpelExpressionParser().parseExpression("@myBean.class.getName()").getValue(context);
    assertThat(value, is(String.class.getName()));
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) EvaluationContext(org.springframework.expression.EvaluationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 75 with EvaluationContext

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

the class EvaluationTests method initializingCollectionElementsOnWrite.

/**
	 * SPR-6984: attempting to index a collection on write using an index that
	 * doesn't currently exist in the collection (address.crossStreets[0] below)
	 */
@Test
public void initializingCollectionElementsOnWrite() throws Exception {
    TestPerson person = new TestPerson();
    EvaluationContext context = new StandardEvaluationContext(person);
    SpelParserConfiguration config = new SpelParserConfiguration(true, true);
    ExpressionParser parser = new SpelExpressionParser(config);
    Expression expression = parser.parseExpression("name");
    expression.setValue(context, "Oleg");
    assertEquals("Oleg", person.getName());
    expression = parser.parseExpression("address.street");
    expression.setValue(context, "123 High St");
    assertEquals("123 High St", person.getAddress().getStreet());
    expression = parser.parseExpression("address.crossStreets[0]");
    expression.setValue(context, "Blah");
    assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
    expression = parser.parseExpression("address.crossStreets[3]");
    expression.setValue(context, "Wibble");
    assertEquals("Blah", person.getAddress().getCrossStreets().get(0));
    assertEquals("Wibble", person.getAddress().getCrossStreets().get(3));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) TestPerson(org.springframework.expression.spel.testresources.TestPerson) Test(org.junit.Test)

Aggregations

EvaluationContext (org.springframework.expression.EvaluationContext)85 Test (org.junit.Test)72 Expression (org.springframework.expression.Expression)52 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)52 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)32 ArrayList (java.util.ArrayList)12 Authentication (org.springframework.security.core.Authentication)11 ExpressionParser (org.springframework.expression.ExpressionParser)10 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)10 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)10 MethodInvocation (org.aopalliance.intercept.MethodInvocation)9 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)9 List (java.util.List)8 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)8 TypedValue (org.springframework.expression.TypedValue)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Map (java.util.Map)5 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)5 AccessException (org.springframework.expression.AccessException)5 Method (java.lang.reflect.Method)4