Search in sources :

Example 11 with ELContext

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

the class TestValueExpressionImpl method testBug49345.

@Test
public void testBug49345() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    TesterBeanA beanA = new TesterBeanA();
    TesterBeanB beanB = new TesterBeanB();
    beanB.setName("Tomcat");
    beanA.setBean(beanB);
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    ValueExpression ve = factory.createValueExpression(context, "${beanA.bean.name}", String.class);
    // First check the basics work
    String result = (String) ve.getValue(context);
    assertEquals("Tomcat", result);
    // 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 12 with ELContext

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

the class TestAstListData 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','b','c']}", List.class);
    Assert.assertEquals(List.class, ve.getType(context));
    Assert.assertEquals(simpleList, 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 13 with ELContext

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

the class TestAstMapData 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':'1','b':'2','c':'3'}}", Map.class);
    Assert.assertEquals(Map.class, ve.getType(context));
    Assert.assertEquals(simpleMap, 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 14 with ELContext

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

the class TestAstSemicolon method testGetType.

@Test
public void testGetType() {
    ELProcessor processor = new ELProcessor();
    ELContext context = processor.getELManager().getELContext();
    ExpressionFactory factory = ELManager.getExpressionFactory();
    ValueExpression ve = factory.createValueExpression(context, "${1+1;2+2}", Integer.class);
    Assert.assertEquals(Number.class, ve.getType(context));
    Assert.assertEquals(Integer.valueOf(4), 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 15 with ELContext

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

the class TestAstAssign method testGetType02.

@Test
public void testGetType02() {
    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'; bean01.text}", 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)

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