Search in sources :

Example 26 with ValueExpression

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

the class TestAstAssign method testGetType02.

@Test
public void testGetType02() {
    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'; bean01.text}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("hello", 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 27 with ValueExpression

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

the class TestAstConcatenation 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' += 3}", String.class);
    Assert.assertEquals(String.class, ve.getType(context));
    Assert.assertEquals("a3", 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 28 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testLiteralExpression.

@Test
public void testLiteralExpression() {
    System.out.println("Literal expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new BooleanBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "${1+2}", int.class);
    Object value = expr.getValue(context);
    assertEquals(3, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 29 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testBooleanExpression.

@Test
public void testBooleanExpression() {
    System.out.println("Boolean expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new BooleanBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "${entity.enabled}", boolean.class);
    Object value = expr.getValue(context);
    assertEquals(true, value);
    expr = factory.createValueExpression(context, "${entity.getValue(true)}", boolean.class);
    value = expr.getValue(context);
    assertEquals(true, value);
    expr = factory.createValueExpression(context, "${entity.getValue(false)}", boolean.class);
    value = expr.getValue(context);
    assertEquals(false, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 30 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testExpression.

@Test
public void testExpression() {
    System.out.println("Raw expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new EntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "${entity.id}", String.class);
    Object value = expr.getValue(context);
    assertEquals(ID, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) 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