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);
}
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"));
}
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));
}
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());
}
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));
}
Aggregations