Search in sources :

Example 1 with ELContext

use of javax.el.ELContext in project camel by apache.

the class JuelTest method testJuel.

@Test
public void testJuel() throws Exception {
    ExpressionFactory factory = new ExpressionFactoryImpl();
    ELContext context = new SimpleContext();
    ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
    Object value = valueExpression.getValue(context);
    assertEquals("Result is a Long object", 246L, value);
}
Also used : ELContext(javax.el.ELContext) SimpleContext(de.odysseus.el.util.SimpleContext) ExpressionFactory(javax.el.ExpressionFactory) ExpressionFactoryImpl(de.odysseus.el.ExpressionFactoryImpl) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 2 with ELContext

use of javax.el.ELContext in project ART-TIME by Artezio.

the class CustomOutputLabelRendererTest method testDetermineRequireness_ifGetterNotFound.

@Test
public void testDetermineRequireness_ifGetterNotFound() throws Exception {
    TestObject testObject = new TestObject();
    ELContext elContext = createMock(ELContext.class);
    setField(renderer, "elContext", elContext);
    UIComponent component = createMock(UIComponent.class);
    ValueExpression valueExpression = createMock(ValueExpression.class);
    ValueReference valueReference = createMock(ValueReference.class);
    PowerMock.mockStatic(ValueExpressionAnalyzer.class);
    expect(component.getValueExpression("value")).andReturn(valueExpression);
    expect(ValueExpressionAnalyzer.getReference(elContext, valueExpression)).andReturn(valueReference);
    expect(valueReference.getBase()).andReturn(testObject);
    expect(valueReference.getProperty()).andReturn("attr_2");
    PowerMock.replayAll(ValueExpressionAnalyzer.class, component, valueReference);
    boolean actual = renderer.determineRequireness(component);
    PowerMock.verifyAll();
    assertFalse(actual);
}
Also used : ELContext(javax.el.ELContext) ValueExpression(javax.el.ValueExpression) UIComponent(javax.faces.component.UIComponent) ValueReference(javax.el.ValueReference) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ELContext

use of javax.el.ELContext in project ART-TIME by Artezio.

the class CustomOutputLabelRendererTest method testDetermineRequireness_ifValueExpressionIsNull.

@Test
public void testDetermineRequireness_ifValueExpressionIsNull() throws Exception {
    ELContext elContext = createMock(ELContext.class);
    setField(renderer, "elContext", elContext);
    UIComponent component = createMock(UIComponent.class);
    expect(component.getValueExpression("value")).andReturn(null);
    replay(component);
    boolean actual = renderer.determineRequireness(component);
    verify(component);
    assertFalse(actual);
}
Also used : ELContext(javax.el.ELContext) UIComponent(javax.faces.component.UIComponent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ELContext

use of javax.el.ELContext in project ART-TIME by Artezio.

the class ContextUtilTest method testGetELContext.

@Test
public void testGetELContext() {
    PowerMock.mockStatic(FacesContext.class);
    FacesContext facesContext = createMock(FacesContext.class);
    ELContext elContext = createMock(ELContext.class);
    expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
    expect(facesContext.getELContext()).andReturn(elContext);
    PowerMock.replayAll(FacesContext.class);
    ELContext actual = ContextUtil.getELContext();
    PowerMock.verifyAll();
}
Also used : FacesContext(javax.faces.context.FacesContext) ELContext(javax.el.ELContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ELContext

use of javax.el.ELContext in project ART-TIME by Artezio.

the class Sheet method updateModel.

/**
 * Override to update model with local values. Note that this is where
 * things can be fragile in that we can successfully update some values and
 * fail on others. There is no clean way to roll back the updates, but we
 * also need to fail processing.
 * <p>
 * TODO consider keeping old values as we update (need for event anyhow) and
 * if there is a failure attempt to roll back by updating successful model
 * updates with the old value. This may not all be necessary.
 */
@Override
public void updateModel(FacesContext context) {
    HashSet<Object> dirtyRows = new HashSet<Object>();
    Iterator<Entry<RowColIndex, String>> commentsEntries = comments.entrySet().iterator();
    while (commentsEntries.hasNext()) {
        final Entry<RowColIndex, String> entry = commentsEntries.next();
        final String newValue = entry.getValue();
        final Object rowKey = entry.getKey().getRowKey();
        final int col = entry.getKey().getColIndex();
        final Column column = getColumns().get(col);
        final RowMap map = rowMap.get(rowKey);
        this.setRowIndex(context, map.sortedIndex);
        String oldValue = null;
        ValueExpression valueExpression = column.getValueExpression("comment");
        if (valueExpression != null) {
            oldValue = (String) valueExpression.getValue(context.getELContext());
            valueExpression.setValue(context.getELContext(), newValue);
        }
        commentsEntries.remove();
        appendUpdateEvent(map.sortedIndex, col, map.value, oldValue, newValue);
        dirtyRows.add(rowKey);
    }
    Iterator<Entry<RowColIndex, Object>> entries = localValues.entrySet().iterator();
    // updates on what was touched
    while (entries.hasNext()) {
        final Entry<RowColIndex, Object> entry = entries.next();
        final Object newValue = entry.getValue();
        final Object rowKey = entry.getKey().getRowKey();
        final int col = entry.getKey().getColIndex();
        final Column column = getColumns().get(col);
        final RowMap map = rowMap.get(rowKey);
        this.setRowIndex(context, map.sortedIndex);
        // System.out.println("Local key=" + rowKey + " and sortedRow is " + map.sortedIndex);
        ValueExpression ve = column.getValueExpression(PropertyKeys.value.name());
        ELContext elContext = context.getELContext();
        Object oldValue = ve.getValue(elContext);
        if (!column.isReadonlyCell()) {
            ve.setValue(elContext, newValue);
        }
        entries.remove();
        appendUpdateEvent(map.sortedIndex, col, map.value, oldValue, newValue);
        dirtyRows.add(rowKey);
    }
    setLocalValueSet(false);
    setRowIndex(context, -1);
    this.sortAndFilter();
    if (context.getPartialViewContext().isPartialRequest())
        this.renderRowUpdateScript(context, dirtyRows);
}
Also used : Entry(java.util.Map.Entry) ELContext(javax.el.ELContext) ValueExpression(javax.el.ValueExpression) HashSet(java.util.HashSet)

Aggregations

ELContext (javax.el.ELContext)47 ValueExpression (javax.el.ValueExpression)31 Test (org.junit.Test)29 ExpressionFactory (javax.el.ExpressionFactory)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ValueReference (javax.el.ValueReference)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 UIComponent (javax.faces.component.UIComponent)7 ELException (javax.el.ELException)4 ELResolver (javax.el.ELResolver)4 BeanELResolver (javax.el.BeanELResolver)3 ArrayELResolver (javax.el.ArrayELResolver)2 CompositeELResolver (javax.el.CompositeELResolver)2 FunctionMapper (javax.el.FunctionMapper)2 ListELResolver (javax.el.ListELResolver)2 MapELResolver (javax.el.MapELResolver)2 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)2 VariableMapper (javax.el.VariableMapper)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1