Author: ekoneil
Date: Wed Aug 25 12:22:13 2004
New Revision: 37040

Added:
   incubator/beehive/trunk/netui/external/commons-el/
   incubator/beehive/trunk/netui/external/commons-el/commons-el.jar   
(contents, props changed)
   
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/simpleaction/
   
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/simpleaction/InternalExpressionUtilsTest.java
   (contents, props changed)
Modified:
   incubator/beehive/trunk/netui/ant/common.properties
   incubator/beehive/trunk/netui/ant/webappTemplate.xml
   incubator/beehive/trunk/netui/src/pageflow/build.xml
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalExpressionUtils.java
   
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AbstractColumn.java
   
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AnchorColumn.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
   incubator/beehive/trunk/netui/test/ant/junitDrt.properties
   incubator/beehive/trunk/netui/test/ant/test.properties
Log:
Add support for simple action and declarative validation expression execution.

This uses the commons-el 1.0 library to implement the expression evaluation.  
The non-page related implicit objects are all available including as in a JSP.  
Because a PageContext and PageScope are not necessarily available, they are 
currently omitted (but could be added for message evaluation).

Include a JUnit test of this InternalExpressionUtils API as part of the DRTs.

Also fix the AnchorColumn data grid tag to report an error when the action and 
href attributes are both set as they should be mutually exclusive.

BB: self
CR: Rich
BVT: NetUI pass



Modified: incubator/beehive/trunk/netui/ant/common.properties
==============================================================================
--- incubator/beehive/trunk/netui/ant/common.properties (original)
+++ incubator/beehive/trunk/netui/ant/common.properties Wed Aug 25 12:22:13 2004
@@ -63,6 +63,8 @@
 commons-fileupload.jar=${struts.dir}/commons-fileupload.jar
 commons-validator.jar=${struts.dir}/commons-validator.jar
 
+commons-el.jar=${build.external.dir}/commons-el/commons-el.jar
+
 #
 # JSF
 #
@@ -163,6 +165,8 @@
 deployed.commons-digester.jar=${webappTemplate.webinf.lib}/commons-digester.jar
 
deployed.commons-fileupload.jar=${webappTemplate.webinf.lib}/commons-fileupload.jar
 
deployed.commons-validator.jar=${webappTemplate.webinf.lib}/commons-validator.jar
+
+deployed.commons-el.jar=${webappTemplate.webinf.lib}/commons-el.jar
 
 deployed.netuiconfig.xml=${webappTemplate.webinf}/netui-config.xml
 deployed.javascript.dir=${webapp.dist.dir}/resources/javascript

Modified: incubator/beehive/trunk/netui/ant/webappTemplate.xml
==============================================================================
--- incubator/beehive/trunk/netui/ant/webappTemplate.xml        (original)
+++ incubator/beehive/trunk/netui/ant/webappTemplate.xml        Wed Aug 25 
12:22:13 2004
@@ -53,6 +53,9 @@
         <copy todir="${webinf.lib}" 
file="${struts.dir}/commons-validator.jar"/>
         <copy todir="${webinf.lib}" 
file="${struts.dir}/commons-fileupload.jar"/>
 
+        <!-- copy commons-el.jar -->
+        <copy todir="${webinf.lib}" file="${commons-el.jar}"/>
+
         <!-- copy the JSTL support JARs -->
         <copy todir="${webinf.lib}" file="${jstl.jar}"/>
         <copy todir="${webinf.lib}" file="${standard.jar}"/>
@@ -159,6 +162,7 @@
         <!-- JSTL support JARs -->
         <include name="WEB-INF/lib/jstl.jar"/>
         <include name="WEB-INF/lib/standard.jar"/>
+        <include name="WEB-INF/lib/commons-el.jar"/>
     </patternset>
 
     <patternset id="struts.runtime">

Added: incubator/beehive/trunk/netui/external/commons-el/commons-el.jar
==============================================================================
Binary file. No diff available.

Modified: incubator/beehive/trunk/netui/src/pageflow/build.xml
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/build.xml        (original)
+++ incubator/beehive/trunk/netui/src/pageflow/build.xml        Wed Aug 25 
12:22:13 2004
@@ -2,7 +2,7 @@
 
 <project name="NetUI/PageFlow" default="compile" basedir=".">
 
-    <property name="module.classpath" 
value="${struts.jar};${servlet24.jar};${jsp20.jar};${util.jar};${commons-beanutils.jar};${commons-logging.jar};${commons-collections.jar};${commons-digester.jar};${commons-validator.jar};${log4j.jar};${scoping.jar};${xbean.jar};${controls.jar};${jsf-api.jar}"/>
+    <property name="module.classpath" 
value="${struts.jar};${servlet24.jar};${jsp20.jar};${util.jar};${commons-beanutils.jar};${commons-logging.jar};${commons-collections.jar};${commons-digester.jar};${commons-validator.jar};${log4j.jar};${scoping.jar};${xbean.jar};${controls.jar};${jsf-api.jar};${commons-el.jar}"/>
 
     <target name="compile">
         <echo>compile module: ${module.name}</echo>

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/FlowController.java
    Wed Aug 25 12:22:13 2004
@@ -43,6 +43,7 @@
 
 import javax.security.auth.login.LoginException;
 import javax.servlet.ServletContext;
+import javax.servlet.jsp.el.ELException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
@@ -1465,16 +1466,25 @@
                 Map.Entry< String, String > entry = i.next();
                 String expression = entry.getKey();
                 String forwardName = entry.getValue();
-                
-                if ( InternalExpressionUtils.evaluateCondition( expression, 
formBean, request, servletContext ) )
+
+                try
                 {
-                    if ( _log.isTraceEnabled() )
+                    if ( InternalExpressionUtils.evaluateCondition( 
expression, formBean, request, servletContext ) )
                     {
-                        _log.trace( "Expression '" + expression + "' evaluated 
to true on simple action "
-                                    + mapping.getPath() + "; using forward " + 
forwardName + '.' );
+                        if ( _log.isTraceEnabled() )
+                        {
+                            _log.trace( "Expression '" + expression + "' 
evaluated to true on simple action "
+                                        + mapping.getPath() + "; using forward 
" + forwardName + '.' );
+                        }
+
+                        return new Forward( forwardName );
                     }
-                    
-                    return new Forward( forwardName );
+                }
+                catch(ELException e)
+                {
+                    // todo: finish this error handling implementation
+                    if( _log.isErrorEnabled() )
+                        _log.error( "Exception occurred evaluating navigation 
expression '" + expression + "'.  Cause: " + e.getCause(), e);
                 }
             }
         }

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalExpressionUtils.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalExpressionUtils.java
  (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalExpressionUtils.java
  Wed Aug 25 12:22:13 2004
@@ -18,41 +18,284 @@
  */
 package org.apache.beehive.netui.pageflow.internal;
 
+import java.util.Map;
+import java.util.Enumeration;
+import java.util.HashMap;
+
 import javax.servlet.ServletContext;
+import javax.servlet.jsp.el.ExpressionEvaluator;
+import javax.servlet.jsp.el.VariableResolver;
+import javax.servlet.jsp.el.ELException;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.Cookie;
 
 import org.apache.beehive.netui.util.logging.Logger;
+import org.apache.commons.el.ExpressionEvaluatorImpl;
+import org.apache.commons.el.EnumeratedMap;
 
 /**
  * Internal class used to evaluate simple action expressions.
  * 
  * todo: need to merge this down into the expression language registration 
infrastructure
+ * todo: need to provdie an ImplicitObjectFactory that will create Maps for 
requestScope, sessionScope, etc.
  */
 public class InternalExpressionUtils
 {
     private static final Logger _logger = 
Logger.getInstance(InternalExpressionUtils.class);
 
-    /* do not construct */
-    private InternalExpressionUtils() {} 
-
-    public static final boolean evaluateCondition(String expression, 
+    public static final boolean evaluateCondition(String expression,
                                                   Object actionForm,
                                                   HttpServletRequest request, 
                                                   ServletContext 
servletContext)
+        throws ELException
     {
-        // todo: implementation
-
-        return expression.equals( "true" );
+        return ((Boolean)evaluate(expression, Boolean.class, actionForm, 
request, servletContext)).booleanValue();
     }
 
     public static final String evaluateMessage(String expression, 
                                                 Object actionForm,
                                                 HttpServletRequest request, 
                                                 ServletContext servletContext)
+        throws ELException
+    {
+        return (String)evaluate(expression, String.class, actionForm, request, 
servletContext);
+    }
+
+    /* do not construct */
+    private InternalExpressionUtils() {}
+
+    private static final Object evaluate(String expression, Class 
expectedType, Object actionForm, HttpServletRequest request, ServletContext 
servletContext)
+        throws ELException
+    {
+        // todo: can this be static / final?
+        ExpressionEvaluator ee = getExpressionEvaluator();
+        return ee.evaluate(expression, expectedType, 
getVariableResolver(actionForm, request, servletContext), null);
+    }
+
+    private static final ExpressionEvaluator getExpressionEvaluator()
     {
-        // todo: implementation
+        return new ExpressionEvaluatorImpl();
+    }
+
+    private static final VariableResolver getVariableResolver(Object 
actionForm, HttpServletRequest request, ServletContext servletContext)
+    {
+        return new SimpleActionVariableResolver(actionForm, request, 
servletContext);
+    }
+
+    private static class SimpleActionVariableResolver
+        implements VariableResolver
+    {
+        private Object _actionForm = null;
+        private HttpServletRequest _request = null;
+        private ServletContext _servletContext = null;
+
+        private SimpleActionVariableResolver(Object actionForm, 
HttpServletRequest request, ServletContext servletContext)
+        {
+            _actionForm = actionForm;
+            _request = request;
+            _servletContext = servletContext;
+        }
+
+        public Object resolveVariable(String name)
+        {
+            // requestScope, sessionScope, applicationScope, param, 
paramValues, header, headerValues, cookie, initParam, <default>
+            if(name.equals("actionForm"))
+                return _actionForm;
+            else if(name.equals("requestScope"))
+                return buildRequestScopeMap(_request);
+            else if(name.equals("sessionScope"))
+                return buildSessionScopeMap(_request);
+            else if(name.equals("applicationScope"))
+                return buildServletContextMap(_servletContext);
+            else if(name.equals("param"))
+                return buildParamMap(_request);
+            else if(name.equals("paramValues"))
+                return buildParamsMap(_request);
+            else if(name.equals("header"))
+                return buildHeaderMap(_request);
+            else if(name.equals("headerValues"))
+                return buildHeadersMap(_request);
+            else if(name.equals("cookie"))
+                return buildCookieMap(_request);
+            else if(name.equals("initParam"))
+                return buildInitParamMap(_servletContext);
+            // chain up the request > session (if exists) > application
+            // note, this should handle pageFlow, globalApp, sharedFlow, and 
bundle if they're in the request
+            // attribute map already
+            else if(_request.getAttribute(name) != null)
+                return _request.getAttribute(name);
+            else if(_request.getSession(false) != null && 
_request.getSession(false).getAttribute(name) != null)
+                return _request.getSession(false).getAttribute(name);
+            else return _servletContext.getAttribute(name);
+        }
+
+        private static final Map buildCookieMap(HttpServletRequest 
httpServletRequest)
+        {
+            HttpServletRequest servletRequest = httpServletRequest;
+            Map<String, Cookie> cookieMap = new HashMap<String, Cookie>();
+            Cookie[] cookies = servletRequest.getCookies();
+            for(int i = 0; i < cookies.length; i++)
+            {
+                if(!cookieMap.containsKey(cookies[i].getName()))
+                    cookieMap.put(cookies[i].getName(), cookies[i]);
+            }
+            return cookieMap;
+        }
+
+        private static final Map buildHeadersMap(HttpServletRequest 
httpServletRequest)
+        {
+            final HttpServletRequest _servletRequest = httpServletRequest;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletRequest.getHeaderNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletRequest.getHeaders((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildHeaderMap(HttpServletRequest 
httpServletRequest)
+        {
+            final HttpServletRequest _servletRequest = httpServletRequest;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletRequest.getHeaderNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletRequest.getHeader((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildInitParamMap(ServletContext 
servletContext)
+        {
+            final ServletContext _servletContext = servletContext;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletContext.getInitParameterNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletContext.getInitParameter((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildParamsMap(HttpServletRequest 
servletRequest)
+        {
+            final HttpServletRequest _servletRequest = servletRequest;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletRequest.getParameterNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletRequest.getParameterValues((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildParamMap(HttpServletRequest 
servletRequest)
+        {
+            final HttpServletRequest _servletRequest = servletRequest;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletRequest.getParameterNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletRequest.getParameter((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildRequestScopeMap(HttpServletRequest 
servletRequest)
+        {
+            final HttpServletRequest _servletRequest = servletRequest;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletRequest.getAttributeNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletRequest.getAttribute((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildSessionScopeMap(HttpServletRequest 
servletRequest)
+        {
+            if(servletRequest.getSession(false) == null)
+                return null;
+
+            final HttpSession _session = servletRequest.getSession(false);
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _session.getAttributeNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_session.getAttribute((String)key) : null);
+                }
+
+                public boolean isMutable() {return false;}
+            };
+        }
+
+        private static final Map buildServletContextMap(ServletContext 
servletContext)
+        {
+            final ServletContext _servletContext = servletContext;
+            return new EnumeratedMap()
+            {
+                public Enumeration enumerateKeys()
+                {
+                    return _servletContext.getAttributeNames();
+                }
+
+                public Object getValue(Object key)
+                {
+                    return (key instanceof String ? 
_servletContext.getAttribute((String)key) : null);
+                }
 
-        return expression;
+                public boolean isMutable() {return false;}
+            };
+        }
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AbstractColumn.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AbstractColumn.java
   (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AbstractColumn.java
   Wed Aug 25 12:22:13 2004
@@ -217,6 +217,7 @@
     protected abstract void setColumnModel(ColumnModel model);
 
     protected void applyAttributes()
+        throws JspException 
     {
     }
 

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AnchorColumn.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AnchorColumn.java
     (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/AnchorColumn.java
     Wed Aug 25 12:22:13 2004
@@ -82,7 +82,11 @@
     }
 
     protected void applyAttributes()
+        throws JspException
     {
+        if(_action != null && _href != null)
+            throw new JspException("Unable to create AnchorColumnModel.  The 
'action' and 'href' attributes can not both be set.");
+
         _column.setAction(_action);
         _column.setHref(_href);
         _column.setScopeId(_scope);        

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ErrorBaseTag.java
    Wed Aug 25 12:22:13 2004
@@ -24,6 +24,7 @@
 import org.apache.beehive.netui.pageflow.internal.InternalExpressionUtils;
 import org.apache.beehive.netui.tags.AbstractSimpleTag;
 import org.apache.beehive.netui.tags.ExpressionHandling;
+import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.struts.Globals;
 import org.apache.struts.taglib.html.Constants;
 import org.apache.struts.action.ActionError;
@@ -34,11 +35,14 @@
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.el.ELException;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Locale;
 
 abstract public class ErrorBaseTag extends AbstractSimpleTag
 {
+    private static final Logger LOGGER = 
Logger.getInstance(ErrorBaseTag.class);
+
     /**
      * The default locale on our server.
      */
@@ -135,8 +139,17 @@
                         String argExpr= strArg.substring( 
InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX_LENGTH );
                         Object formBean = pageContext.getAttribute( 
Constants.BEAN_KEY, PageContext.REQUEST_SCOPE );
                         HttpServletRequest request = ( HttpServletRequest ) 
pageContext.getRequest();
-                        messageArgs[i] = 
InternalExpressionUtils.evaluateMessage( argExpr, formBean, request,
-                                                                               
   pageContext.getServletContext() );
+
+                        try
+                        {
+                            messageArgs[i] = 
InternalExpressionUtils.evaluateMessage( argExpr, formBean, request,
+                                                                               
       pageContext.getServletContext() );
+                        }
+                        catch(ELException e)
+                        {
+                            if(LOGGER.isErrorEnabled())
+                                LOGGER.error("Exception occurred evaluating 
message expression '" + argExpr + "'.  Cause: " + e.getCause(), e);
+                        }
                     }
                 }
             }
@@ -154,7 +167,15 @@
             String expression = 
key.substring(InternalConstants.MESSAGE_IS_EXPRESSION_PREFIX_LENGTH);
             Object formBean = pageContext.getAttribute( Constants.BEAN_KEY, 
PageContext.REQUEST_SCOPE );
             HttpServletRequest request = ( HttpServletRequest ) 
pageContext.getRequest();
-            message = InternalExpressionUtils.evaluateMessage( expression, 
formBean, request, pageContext.getServletContext() );
+            try
+            {
+                message = InternalExpressionUtils.evaluateMessage( expression, 
formBean, request, pageContext.getServletContext() );
+            }
+            catch(ELException e)
+            {
+                if(LOGGER.isErrorEnabled())
+                    LOGGER.error("Exception occurred evaluating message 
expression '" + expression + "'.  Cause: " + e.getCause(), e);
+            }
         }
         else {
             boolean requestedSpecificBundle = (bundle != null);

Modified: incubator/beehive/trunk/netui/test/ant/junitDrt.properties
==============================================================================
--- incubator/beehive/trunk/netui/test/ant/junitDrt.properties  (original)
+++ incubator/beehive/trunk/netui/test/ant/junitDrt.properties  Wed Aug 25 
12:22:13 2004
@@ -27,3 +27,6 @@
 
 # Expression rewriting tests
 org.apache.beehive.netui.test.databinding.expression.IndexedNameTest
+
+# InternalExpressionUtils test
+org.apache.beehive.netui.test.script.simpleaction.InternalExpressionUtilsTest

Modified: incubator/beehive/trunk/netui/test/ant/test.properties
==============================================================================
--- incubator/beehive/trunk/netui/test/ant/test.properties      (original)
+++ incubator/beehive/trunk/netui/test/ant/test.properties      Wed Aug 25 
12:22:13 2004
@@ -60,6 +60,7 @@
 ${deployed.scoping.jar};\
 ${deployed.util.jar};\
 ${deployed.struts.jar};\
+${deployed.commons-el.jar};\
 ${junit.jar};\
 ${log4j.jar};\
 ${testBeans.jar};\

Added: 
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/simpleaction/InternalExpressionUtilsTest.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/simpleaction/InternalExpressionUtilsTest.java
        Wed Aug 25 12:22:13 2004
@@ -0,0 +1,125 @@
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2002-2004  BEA Systems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.test.script.simpleaction;
+
+import org.apache.beehive.netui.util.logging.Logger;
+import org.apache.beehive.netui.pageflow.internal.InternalExpressionUtils;
+import org.apache.beehive.netui.test.servlet.ServletFactory;
+import org.apache.beehive.netui.test.beans.SimpleTypeActionForm;
+import org.apache.beehive.netui.test.beans.FooJavaBean;
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.el.ELException;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+public class InternalExpressionUtilsTest
+    extends TestCase
+{
+    private static final Logger _logger = 
Logger.getInstance(InternalExpressionUtilsTest.class);
+
+    private HttpServletRequest _request = null;
+    private ServletContext _servletContext = null;
+    private SimpleTypeActionForm _actionForm = null;
+    private FooJavaBean _beanActionForm = null;
+
+    public InternalExpressionUtilsTest(String name)
+    {
+        super(name);
+    }
+
+    public void setUp()
+    {
+        PageContext _pageContext = ServletFactory.getPageContext();
+        _request = (HttpServletRequest)_pageContext.getRequest();
+        _servletContext = _pageContext.getServletContext();
+        _actionForm = new SimpleTypeActionForm();
+        _beanActionForm = new FooJavaBean();
+    }
+
+    public void testConditionEvaluation()
+        throws ELException
+    {
+        boolean result = evaluateCondition("${actionForm.boolProperty}");
+        assertFalse(result);
+
+        _actionForm.setBoolProperty(true);
+        result = evaluateCondition("${actionForm.boolProperty}");
+        assertTrue(result);
+
+        result = evaluateCondition("${requestScope.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${sessionScope.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${applicationScope.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${param.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${paramValues.foo}");
+        assertFalse(result);
+/* the faux servlet proxy layer doesn't support these calls right now
+        result = evaluateCondition("${header.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${headerValues.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${cookie.foo}");
+        assertFalse(result);
+        result = evaluateCondition("${initParam.foo}");
+        assertFalse(result);
+*/
+        _beanActionForm.setBooleanProperty(true);
+        result = 
InternalExpressionUtils.evaluateCondition("${actionForm.booleanProperty}", 
_beanActionForm, _request, _servletContext);
+        assertTrue(result);
+    }
+
+    public void testMessageEvaluation()
+        throws ELException
+    {
+        String result = evaluateMessage("${actionForm.stringProperty}");
+        assertEquals(result, _actionForm.getStringProperty());
+    }
+
+    private final boolean evaluateCondition(String expression)
+        throws ELException
+    {
+        return InternalExpressionUtils.evaluateCondition(expression, 
_actionForm, _request, _servletContext);
+    }
+
+    private final String evaluateMessage(String expression)
+        throws ELException
+    {
+        return InternalExpressionUtils.evaluateMessage(expression, 
_actionForm, _request, _servletContext);
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+        suite.addTestSuite(InternalExpressionUtilsTest.class);
+        return suite;
+    }
+
+    public static void main(String[] args)
+    {
+        junit.textui.TestRunner.run(suite());
+    }
+}
\ No newline at end of file

Reply via email to