Search in sources :

Example 1 with BeanResolver

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

the class MethodInvocationTests method invokeMethodWithoutConversion.

@Test
public void invokeMethodWithoutConversion() throws Exception {
    final BytesService service = new BytesService();
    byte[] bytes = new byte[100];
    StandardEvaluationContext context = new StandardEvaluationContext(bytes);
    context.setBeanResolver(new BeanResolver() {

        @Override
        public Object resolve(EvaluationContext context, String beanName) throws AccessException {
            if ("service".equals(beanName)) {
                return service;
            }
            return null;
        }
    });
    Expression expression = parser.parseExpression("@service.handleBytes(#root)");
    byte[] outBytes = expression.getValue(context, byte[].class);
    assertSame(bytes, outBytes);
}
Also used : BeanResolver(org.springframework.expression.BeanResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) AccessException(org.springframework.expression.AccessException) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Test(org.junit.Test)

Example 2 with BeanResolver

use of org.springframework.expression.BeanResolver in project spring-security by spring-projects.

the class DelegatingEvaluationContextTests method getBeanResolver.

@Test
public void getBeanResolver() {
    BeanResolver expected = mock(BeanResolver.class);
    when(this.delegate.getBeanResolver()).thenReturn(expected);
    assertThat(this.context.getBeanResolver()).isEqualTo(expected);
}
Also used : BeanResolver(org.springframework.expression.BeanResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 BeanResolver (org.springframework.expression.BeanResolver)2 AccessException (org.springframework.expression.AccessException)1 EvaluationContext (org.springframework.expression.EvaluationContext)1 Expression (org.springframework.expression.Expression)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1