Search in sources :

Example 21 with ELContext

use of javax.el.ELContext in project tomcat 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(factory);
    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);
    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 22 with ELContext

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

the class TesterVariableMapperImpl method testSetVariable01.

@Test
public void testSetVariable01() {
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ELContext context = new TesterELContext();
    ValueExpression ve1 = factory.createValueExpression(context, "${1}", int.class);
    ValueExpression ve2 = factory.createValueExpression(context, "${2}", int.class);
    ValueExpression ve3 = factory.createValueExpression(context, "${3}", int.class);
    VariableMapper mapper = new VariableMapperImpl();
    mapper.setVariable("var1", ve1);
    mapper.setVariable("var2", ve2);
    mapper.setVariable("var3", ve3);
    mapper.setVariable("var2", null);
    Assert.assertEquals(ve1, mapper.resolveVariable("var1"));
    Assert.assertNull(mapper.resolveVariable("var2"));
    Assert.assertEquals(ve3, mapper.resolveVariable("var3"));
}
Also used : ELContext(javax.el.ELContext) TesterELContext(javax.el.TesterELContext) ExpressionFactory(javax.el.ExpressionFactory) VariableMapper(javax.el.VariableMapper) ValueExpression(javax.el.ValueExpression) TesterELContext(javax.el.TesterELContext) Test(org.junit.Test)

Example 23 with ELContext

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

the class TestAstAssign method testGetType01.

@Test
public void testGetType01() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    processor.defineBean("bean01", new TesterBeanB());
    ValueExpression ve = factory.createValueExpression(context, "${bean01.text = 'hello'}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("hello", 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 24 with ELContext

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

the class TestELParser method doTestParser.

private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
    ELException elException = null;
    String elResult = null;
    // Don't try and evaluate expressions that depend on variables or functions
    if (expectedResult != null) {
        try {
            ELManager manager = new ELManager();
            ELContext context = manager.getELContext();
            ExpressionFactory factory = ELManager.getExpressionFactory();
            ValueExpression ve = factory.createValueExpression(context, input, String.class);
            elResult = ve.getValue(context).toString();
            Assert.assertEquals(expectedResult, elResult);
        } catch (ELException ele) {
            elException = ele;
        }
    }
    Nodes nodes = null;
    try {
        nodes = ELParser.parse(input, false);
        Assert.assertNull(elException);
    } catch (IllegalArgumentException iae) {
        Assert.assertNotNull(elResult, elException);
        // Not strictly true but enables us to report both
        iae.initCause(elException);
        throw iae;
    }
    TextBuilder textBuilder = new TextBuilder(false);
    nodes.visit(textBuilder);
    Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
}
Also used : ELContext(javax.el.ELContext) TextBuilder(org.apache.jasper.compiler.ELParser.TextBuilder) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELManager(javax.el.ELManager) ELException(javax.el.ELException) Nodes(org.apache.jasper.compiler.ELNode.Nodes)

Example 25 with ELContext

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

the class TestAstSetData 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','b','c'}}", Set.class);
    Assert.assertEquals(Set.class, ve.getType(context));
    Assert.assertEquals(simpleSet, 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)

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