use of javax.el.ELContext in project tomcat70 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();
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);
Assert.assertEquals(Integer.valueOf(0), result);
}
use of javax.el.ELContext in project tomcat70 by apache.
the class TestValueExpressionImpl method testBug51177ObjectMap.
@Test
public void testBug51177ObjectMap() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
Object o1 = "String value";
Object o2 = Integer.valueOf(32);
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("key1", o1);
map.put("key2", o2);
ValueExpression var = factory.createValueExpression(map, Map.class);
context.getVariableMapper().setVariable("map", var);
ValueExpression ve1 = factory.createValueExpression(context, "${map.key1}", Object.class);
ve1.setValue(context, o2);
Assert.assertEquals(o2, ve1.getValue(context));
ValueExpression ve2 = factory.createValueExpression(context, "${map.key2}", Object.class);
ve2.setValue(context, o1);
Assert.assertEquals(o1, ve2.getValue(context));
}
use of javax.el.ELContext in project tomcat70 by apache.
the class TestELParser method testJavaKeyWordSuffix.
@Test
public void testJavaKeyWordSuffix() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
TesterBeanA beanA = new TesterBeanA();
beanA.setInt("five");
ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
context.getVariableMapper().setVariable("beanA", var);
// Should fail
Exception e = null;
try {
factory.createValueExpression(context, "${beanA.int}", String.class);
} catch (ELException ele) {
e = ele;
}
Assert.assertNotNull(e);
}
use of javax.el.ELContext in project tomcat70 by apache.
the class TestELParser method testExpression.
private void testExpression(String expression, String expected) {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
ValueExpression ve = factory.createValueExpression(context, expression, String.class);
String result = (String) ve.getValue(context);
Assert.assertEquals(expected, result);
}
use of javax.el.ELContext in project ysoserial by frohoff.
the class Myfaces1 method makeExpressionPayload.
public static Object makeExpressionPayload(String expr) throws IllegalArgumentException, IllegalAccessException, Exception {
FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
ExpressionFactory expressionFactory = ExpressionFactory.newInstance();
ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class);
ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2);
return Gadgets.makeMap(e2, e);
}
Aggregations