Search in sources :

Example 31 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug50105.

@Test
public void testBug50105() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterEnum testEnum = TesterEnum.APPLE;
    ValueExpression var = factory.createValueExpression(testEnum, TesterEnum.class);
    context.getVariableMapper().setVariable("testEnum", var);
    // When coercing an Enum to a String, name() should always be used.
    ValueExpression ve1 = factory.createValueExpression(context, "${testEnum}", String.class);
    String result1 = (String) ve1.getValue(context);
    Assert.assertEquals("APPLE", result1);
    ValueExpression ve2 = factory.createValueExpression(context, "foo${testEnum}bar", String.class);
    String result2 = (String) ve2.getValue(context);
    Assert.assertEquals("fooAPPLEbar", result2);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 32 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug51544Direct.

/**
 * Test using list directly as variable.
 */
@Test
public void testBug51544Direct() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    List<?> list = Collections.emptyList();
    ValueExpression var = factory.createValueExpression(list, List.class);
    context.getVariableMapper().setVariable("list", var);
    ValueExpression ve = factory.createValueExpression(context, "${list.size()}", Integer.class);
    Integer result = (Integer) ve.getValue(context);
    Assert.assertEquals(Integer.valueOf(0), result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 33 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug51544Bean.

/**
 * Test returning an empty list as a bean property.
 */
@Test
public void testBug51544Bean() throws Exception {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanA beanA = new TesterBeanA();
    beanA.setValList(Collections.emptyList());
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.valList.size()}", Integer.class);
    Integer result = (Integer) ve.getValue(context);
    Assert.assertEquals(Integer.valueOf(0), result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 34 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug51177ObjectMap.

@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("key1", o1);
    map.put("key2", o2);
    ValueExpression var = factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);
    ValueExpression ve1 = factory.createValueExpression(context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));
    ValueExpression ve2 = factory.createValueExpression(context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) HashMap(java.util.HashMap) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 35 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestELEvaluation method evaluateExpression.

// ************************************************************************
private String evaluateExpression(String expression) {
    ELContextImpl ctx = new ELContextImpl();
    ctx.setFunctionMapper(new TesterFunctions.FMapper());
    ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
    ValueExpression ve = exprFactory.createValueExpression(ctx, expression, String.class);
    return (String) ve.getValue(ctx);
}
Also used : ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Aggregations

ELContextImpl (org.apache.jasper.el.ELContextImpl)49 Test (org.junit.Test)34 ValueExpression (jakarta.el.ValueExpression)17 ValueExpression (javax.el.ValueExpression)17 ELContext (jakarta.el.ELContext)16 ExpressionFactory (jakarta.el.ExpressionFactory)16 ELContext (javax.el.ELContext)15 ExpressionFactory (javax.el.ExpressionFactory)15 ListResourceBundle (java.util.ListResourceBundle)8 ResourceBundle (java.util.ResourceBundle)8 ValueReference (jakarta.el.ValueReference)3 FeatureDescriptor (java.beans.FeatureDescriptor)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3 ELException (javax.el.ELException)3 ValueReference (javax.el.ValueReference)3 ELException (jakarta.el.ELException)2 PrivilegedAction (java.security.PrivilegedAction)2 ArrayList (java.util.ArrayList)2 ExpressionFactoryImpl (org.apache.el.ExpressionFactoryImpl)2