Search in sources :

Example 36 with ValueExpression

use of javax.el.ValueExpression 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 37 with ValueExpression

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

the class TestMethodExpressionImpl method testBug50790a.

@Test
public void testBug50790a() throws Exception {
    ValueExpression ve = factory.createValueExpression(context, "#{beanAA.name.contains(beanA.name)}", java.lang.Boolean.class);
    Boolean actual = (Boolean) ve.getValue(context);
    assertEquals(Boolean.TRUE, actual);
}
Also used : ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 38 with ValueExpression

use of javax.el.ValueExpression 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 39 with ValueExpression

use of javax.el.ValueExpression 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 40 with ValueExpression

use of javax.el.ValueExpression 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

ValueExpression (javax.el.ValueExpression)59 Test (org.junit.Test)36 ExpressionFactory (javax.el.ExpressionFactory)33 ELContext (javax.el.ELContext)27 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (javax.el.VariableMapper)9 ELException (javax.el.ELException)7 ELProcessor (javax.el.ELProcessor)7 MethodExpression (javax.el.MethodExpression)7 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 ValueReference (javax.el.ValueReference)4 SimpleContext (de.odysseus.el.util.SimpleContext)2 HashMap (java.util.HashMap)2 ELClass (javax.el.ELClass)2 FunctionMapper (javax.el.FunctionMapper)2 ELParseException (javax.servlet.jsp.el.ELParseException)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1