Search in sources :

Example 41 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat70 by apache.

the class TestResourceBundleELResolver method testGetFeatureDescriptors02.

/**
 * Tests that a valid FeatureDescriptors are returned.
 */
@Test
public void testGetFeatureDescriptors02() {
    ResourceBundleELResolver resolver = new ResourceBundleELResolver();
    ELContext context = new ELContextImpl();
    ResourceBundle resourceBundle = new TesterResourceBundle(new Object[][] { { "key", "value" } });
    @SuppressWarnings("unchecked") Iterator<FeatureDescriptor> result = resolver.getFeatureDescriptors(context, resourceBundle);
    while (result.hasNext()) {
        FeatureDescriptor featureDescriptor = result.next();
        Assert.assertEquals("key", featureDescriptor.getDisplayName());
        Assert.assertEquals("key", featureDescriptor.getName());
        Assert.assertEquals("", featureDescriptor.getShortDescription());
        Assert.assertFalse(featureDescriptor.isExpert());
        Assert.assertFalse(featureDescriptor.isHidden());
        Assert.assertTrue(featureDescriptor.isPreferred());
        Assert.assertEquals(String.class, featureDescriptor.getValue(ELResolver.TYPE));
        Assert.assertEquals(Boolean.TRUE, featureDescriptor.getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME));
    }
}
Also used : FeatureDescriptor(java.beans.FeatureDescriptor) ELContextImpl(org.apache.jasper.el.ELContextImpl) ResourceBundle(java.util.ResourceBundle) ListResourceBundle(java.util.ListResourceBundle) Test(org.junit.Test)

Example 42 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.

the class TestMethodExpressionImpl method setUp.

@Before
public void setUp() {
    factory = ExpressionFactory.newInstance();
    context = new ELContextImpl(factory);
    TesterBeanA beanA = new TesterBeanA();
    beanA.setName("A");
    context.getVariableMapper().setVariable("beanA", factory.createValueExpression(beanA, TesterBeanA.class));
    TesterBeanAA beanAA = new TesterBeanAA();
    beanAA.setName("AA");
    context.getVariableMapper().setVariable("beanAA", factory.createValueExpression(beanAA, TesterBeanAA.class));
    TesterBeanAAA beanAAA = new TesterBeanAAA();
    beanAAA.setName("AAA");
    context.getVariableMapper().setVariable("beanAAA", factory.createValueExpression(beanAAA, TesterBeanAAA.class));
    beanB = new TesterBeanB();
    beanB.setName("B");
    context.getVariableMapper().setVariable("beanB", factory.createValueExpression(beanB, TesterBeanB.class));
    TesterBeanBB beanBB = new TesterBeanBB();
    beanBB.setName("BB");
    context.getVariableMapper().setVariable("beanBB", factory.createValueExpression(beanBB, TesterBeanBB.class));
    TesterBeanBBB beanBBB = new TesterBeanBBB();
    beanBBB.setName("BBB");
    context.getVariableMapper().setVariable("beanBBB", factory.createValueExpression(beanBBB, TesterBeanBBB.class));
    TesterBeanC beanC = new TesterBeanC();
    context.getVariableMapper().setVariable("beanC", factory.createValueExpression(beanC, TesterBeanC.class));
    TesterBeanEnum beanEnum = new TesterBeanEnum();
    context.getVariableMapper().setVariable("beanEnum", factory.createValueExpression(beanEnum, TesterBeanEnum.class));
}
Also used : ELContextImpl(org.apache.jasper.el.ELContextImpl) Before(org.junit.Before)

Example 43 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.

the class TestValueExpressionImpl method testBug56522SetNullValue.

@Test
public void testBug56522SetNullValue() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    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 set the value to null
    ve.setValue(context, null);
    Assert.assertEquals("", beanB.getName());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 44 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl 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);
    Assert.assertEquals(Integer.valueOf(0), result);
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 45 with ELContextImpl

use of org.apache.jasper.el.ELContextImpl in project tomcat by apache.

the class TestValueExpressionImpl method testGetValueReferenceVariable.

@Test
public void testGetValueReferenceVariable() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl(factory);
    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());
}
Also used : ELContext(jakarta.el.ELContext) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ValueReference(jakarta.el.ValueReference) Test(org.junit.Test)

Aggregations

ELContextImpl (org.apache.jasper.el.ELContextImpl)49 Test (org.junit.Test)34 ValueExpression (jakarta.el.ValueExpression)17 ValueExpression (javax.el.ValueExpression)17 ELContext (jakarta.el.ELContext)16 ExpressionFactory (jakarta.el.ExpressionFactory)16 ELContext (javax.el.ELContext)15 ExpressionFactory (javax.el.ExpressionFactory)15 ListResourceBundle (java.util.ListResourceBundle)8 ResourceBundle (java.util.ResourceBundle)8 ValueReference (jakarta.el.ValueReference)3 FeatureDescriptor (java.beans.FeatureDescriptor)3 Enumeration (java.util.Enumeration)3 HashMap (java.util.HashMap)3 ELException (javax.el.ELException)3 ValueReference (javax.el.ValueReference)3 ELException (jakarta.el.ELException)2 PrivilegedAction (java.security.PrivilegedAction)2 ArrayList (java.util.ArrayList)2 ExpressionFactoryImpl (org.apache.el.ExpressionFactoryImpl)2