use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.
the class TestValueExpressionImpl method testGetValueReferenceVariable.
@Test
public void testGetValueReferenceVariable() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
TesterBeanB beanB = new TesterBeanB();
beanB.setName("Tomcat");
ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class);
context.getVariableMapper().setVariable("beanB", var);
ValueExpression var2 = factory.createValueExpression(context, "${beanB.name}", String.class);
context.getVariableMapper().setVariable("foo", var2);
ValueExpression ve = factory.createValueExpression(context, "${foo}", ValueExpression.class);
// 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 org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.
the class TestValueExpressionImpl method testBug51177ObjectList.
@Test
public void testBug51177ObjectList() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
Object o1 = "String value";
Object o2 = Integer.valueOf(32);
List<Object> list = new ArrayList<Object>();
list.add(0, o1);
list.add(1, o2);
ValueExpression var = factory.createValueExpression(list, List.class);
context.getVariableMapper().setVariable("list", var);
ValueExpression ve1 = factory.createValueExpression(context, "${list[0]}", Object.class);
ve1.setValue(context, o2);
Assert.assertEquals(o2, ve1.getValue(context));
ValueExpression ve2 = factory.createValueExpression(context, "${list[1]}", Object.class);
ve2.setValue(context, o1);
Assert.assertEquals(o1, ve2.getValue(context));
}
use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.
the class TestValueExpressionImpl method testGetValueReference.
@Test
public void testGetValueReference() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
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);
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 org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.
the class TestAttributeParser method evalAttr.
private String evalAttr(String expression, char quote) {
ELContextImpl ctx = new ELContextImpl();
ctx.setFunctionMapper(new TesterFunctions.FMapper());
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
ValueExpression ve = exprFactory.createValueExpression(ctx, AttributeParser.getUnquoted(expression, quote, false, false, false, false), String.class);
return (String) ve.getValue(ctx);
}
use of org.apache.jasper.el.ELContextImpl in project tomcat70 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 {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
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());
}
Aggregations