Search in sources :

Example 16 with ELContext

use of javax.el.ELContext in project tomcat by apache.

the class TestAstConcatenation method testGetType.

@Test
public void testGetType() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ValueExpression ve = factory.createValueExpression(context, "${'a' += 3}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("a3", ve.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELProcessor(javax.el.ELProcessor) Test(org.junit.Test)

Example 17 with ELContext

use of javax.el.ELContext in project tomee by apache.

the class StatefulConversationScopedTOMEE1138Test method el.

@Test
public void el() {
    final BeanELResolver elResolver = new BeanELResolver();
    assertEquals("John", elResolver.getValue(new ELContext() {

        @Override
        public ELResolver getELResolver() {
            return elResolver;
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return new FunctionMapper() {

                @Override
                public Method resolveFunction(final String prefix, final String localName) {
                    return null;
                }
            };
        }

        @Override
        public VariableMapper getVariableMapper() {
            return new VariableMapper() {

                @Override
                public ValueExpression resolveVariable(final String variable) {
                    return null;
                }

                @Override
                public ValueExpression setVariable(final String variable, final ValueExpression expression) {
                    return null;
                }
            };
        }
    }, conversationByName, "name"));
}
Also used : ELContext(javax.el.ELContext) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) BeanELResolver(javax.el.BeanELResolver) FunctionMapper(javax.el.FunctionMapper) Test(org.junit.Test)

Example 18 with ELContext

use of javax.el.ELContext in project tomcat by apache.

the class TestValueExpressionImpl method testGetValueReferenceVariable.

@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression var2 = factory.createValueExpression(context, "${beanB.name}", String.class);
    context.getVariableMapper().setVariable("foo", var2);
    ValueExpression ve = factory.createValueExpression(context, "${foo}", ValueExpression.class);
    // Now check the value reference
    ValueReference vr = ve.getValueReference(context);
    assertNotNull(vr);
    assertEquals(beanB, vr.getBase());
    assertEquals("name", vr.getProperty());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(javax.el.ValueReference) Test(org.junit.Test)

Example 19 with ELContext

use of javax.el.ELContext in project tomcat by apache.

the class TestValueExpressionImpl method testBug51177ObjectList.

@Test
public void testBug51177ObjectList() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    List<Object> list = new ArrayList<>();
    list.add(0, o1);
    list.add(1, o2);
    ValueExpression var = factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);
    ValueExpression ve1 = factory.createValueExpression(context, "${list[0]}", Object.class);
    ve1.setValue(context, o2);
    assertEquals(o2, ve1.getValue(context));
    ValueExpression ve2 = factory.createValueExpression(context, "${list[1]}", Object.class);
    ve2.setValue(context, o1);
    assertEquals(o1, ve2.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ArrayList(java.util.ArrayList) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 20 with ELContext

use of javax.el.ELContext in project tomcat by apache.

the class TestValueExpressionImpl method testBug56522SetNullValue.

@Test
public void testBug56522SetNullValue() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
    context.getVariableMapper().setVariable("beanB", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanB.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    assertEquals("Tomcat", result);
    // Now set the value to null
    ve.setValue(context, null);
    assertEquals("", beanB.getName());
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Aggregations

ELContext (javax.el.ELContext)28 ValueExpression (javax.el.ValueExpression)27 ExpressionFactory (javax.el.ExpressionFactory)26 Test (org.junit.Test)23 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELProcessor (javax.el.ELProcessor)7 ELException (javax.el.ELException)3 ValueReference (javax.el.ValueReference)3 VariableMapper (javax.el.VariableMapper)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeanELResolver (javax.el.BeanELResolver)1 ELManager (javax.el.ELManager)1 ELResolver (javax.el.ELResolver)1 FunctionMapper (javax.el.FunctionMapper)1 StandardELContext (javax.el.StandardELContext)1 TesterELContext (javax.el.TesterELContext)1 TesterPageContext (javax.servlet.jsp.TesterPageContext)1