use of jakarta.el.ExpressionFactory in project tomcat 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(factory);
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);
}
use of jakarta.el.ExpressionFactory 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);
Assert.assertEquals("Tomcat", result);
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
Assert.assertNotNull(vr);
Assert.assertEquals(beanB, vr.getBase());
Assert.assertEquals("name", vr.getProperty());
}
use of jakarta.el.ExpressionFactory 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"));
}
use of jakarta.el.ExpressionFactory 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));
}
use of jakarta.el.ExpressionFactory 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));
}
Aggregations