Search in sources :

Example 21 with ValueExpression

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

the class TestValueExpressionImpl method testGetValueReference.

@Test
public void testGetValueReference() {
    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 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 22 with ValueExpression

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

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

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

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

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