Author: rich Date: Fri May 13 00:45:39 2005 New Revision: 169968 URL: http://svn.apache.org/viewcvs?rev=169968&view=rev Log: Got StrutsTestCase integrated into the NetUI JUnit tests. This adds a handful of declarative validation tests, but also verifies that StrutsTestCase works against Page Flow.
See http://issues.apache.org/jira/browse/BEEHIVE-615 for more background. tests: bvt in netui, run.tests against the built distributions (WinXP) BB: self (linux) Added: incubator/beehive/trunk/netui/test/external/ incubator/beehive/trunk/netui/test/external/strutstestcase/ incubator/beehive/trunk/netui/test/external/strutstestcase/strutstest-2.1.3.jar (with props) incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/ incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml (with props) incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml (with props) incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java (with props) incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf (with props) incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties (with props) incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java (with props) incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp (with props) Modified: incubator/beehive/trunk/netui/ant/netui.properties incubator/beehive/trunk/netui/test/ant/junitCore.xml incubator/beehive/trunk/netui/test/ant/netui-test-imports.xml incubator/beehive/trunk/netui/test/dist-test/ant/netui-test-imports.xml incubator/beehive/trunk/netui/test/dist-test/build.xml incubator/beehive/trunk/netui/test/src/junitTests/build.xml incubator/beehive/trunk/test/dist-test/build.xml Modified: incubator/beehive/trunk/netui/ant/netui.properties URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/ant/netui.properties?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/ant/netui.properties (original) +++ incubator/beehive/trunk/netui/ant/netui.properties Fri May 13 00:45:39 2005 @@ -72,6 +72,10 @@ # NetUI config file references netuiconfig.xml=${src.dir}/webapp-template/default/WEB-INF/beehive-netui-config.xml +# Validator rules file references +netui-validator-rules.xml=${src.dir}/webapp-template/default/WEB-INF/netui-validator-rules.xml +validator-rules.xml=${src.dir}/webapp-template/default/WEB-INF/validator-rules.xml + #compile options compile.debug=true compile.deprecation=off Modified: incubator/beehive/trunk/netui/test/ant/junitCore.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/ant/junitCore.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/test/ant/junitCore.xml (original) +++ incubator/beehive/trunk/netui/test/ant/junitCore.xml Fri May 13 00:45:39 2005 @@ -8,6 +8,7 @@ <path refid="junit-tests.dependency.path"/> <path refid="webapp.dependency.path"/> <path refid="junit.dependency.path"/> + <path refid="strutstestcase.dependency.path"/> <path refid="servlet.dependency.path"/> </path> @@ -45,6 +46,11 @@ <batchtest fork="yes" todir="${testout.dir}"> <fileset dir="${test.classes.dir}/junitTests"> <include name="org/apache/beehive/netui/test/core/**/*Test.class"/> + </fileset> + </batchtest> + <batchtest fork="yes" todir="${testout.dir}"> + <fileset dir="${test.classes.dir}/junitTests"> + <include name="org/apache/beehive/netui/test/pageflow/**/*Test.class"/> </fileset> </batchtest> <test name="org.apache.beehive.netui.test.databinding.expression.IndexedNameTest" todir="${testout.dir}"/> Modified: incubator/beehive/trunk/netui/test/ant/netui-test-imports.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/ant/netui-test-imports.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/test/ant/netui-test-imports.xml (original) +++ incubator/beehive/trunk/netui/test/ant/netui-test-imports.xml Fri May 13 00:45:39 2005 @@ -16,4 +16,8 @@ <pathelement location="${test.lib.dir}/beehive-netui-junitTests.jar"/> </path> + <path id="strutstestcase.dependency.path"> + <pathelement location="${test.external.dir}/strutstestcase/strutstest-2.1.3.jar"/> + </path> + </project> Modified: incubator/beehive/trunk/netui/test/dist-test/ant/netui-test-imports.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/dist-test/ant/netui-test-imports.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/test/dist-test/ant/netui-test-imports.xml (original) +++ incubator/beehive/trunk/netui/test/dist-test/ant/netui-test-imports.xml Fri May 13 00:45:39 2005 @@ -36,6 +36,10 @@ <pathelement path="${test.dir}/junit/lib/junit.jar"/> </path> + <path id="strutstestcase.dependency.path"> + <pathelement path="${test.dir}/strutstestcase/strutstest-2.1.3.jar"/> + </path> + <path id="log4j.dependency.path"> <pathelement path="${dist.home}/lib/common/log4j-1.2.8.jar"/> </path> Modified: incubator/beehive/trunk/netui/test/dist-test/build.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/dist-test/build.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/test/dist-test/build.xml (original) +++ incubator/beehive/trunk/netui/test/dist-test/build.xml Fri May 13 00:45:39 2005 @@ -17,6 +17,8 @@ </target> <target name="assemble.tests" description="Assemble all netui tests for test distribution"> + <property name="netui.test.dist.dir" value="${test.dist.base.dir}/beehive-test-dist/netui"/> + <!-- Clean coreWeb --> <ant antfile="${app.dir}/drt/build.xml" target="clean"/> @@ -24,83 +26,89 @@ <ant antfile="${app.dir}/jsf/build.xml" target="clean"/> <!-- Moving files to the right place for packaging --> - <mkdir dir="${test.dist.base.dir}/beehive-test-dist"/> - <mkdir dir="${test.dist.base.dir}/beehive-test-dist/netui"/> - <mkdir dir="${test.dist.base.dir}/beehive-test-dist/netui/struts"/> + <mkdir dir="${test.dist.base.dir}/beehive-test-dist"/> + <mkdir dir="${netui.test.dist.dir}"/> + <mkdir dir="${netui.test.dist.dir}/struts"/> - <copy file="${test.dir}/dist-test/ant/build.xml" tofile="${test.dist.base.dir}/beehive-test-dist/netui/build.xml"/> + <copy file="${test.dir}/dist-test/ant/build.xml" tofile="${netui.test.dist.dir}/build.xml"/> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/ant"> + <copy todir="${netui.test.dist.dir}/ant"> <fileset dir="${test.dir}/dist-test/ant" includes="**"/> - </copy> - - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/ant" file="${test.dir}/ant/junitCore.xml"/> + </copy> - <!-- Get test webs --> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/webapps/coreWeb"> + <copy todir="${netui.test.dist.dir}/ant" file="${test.dir}/ant/junitCore.xml"/> + + <!-- Get test webs --> + <copy todir="${netui.test.dist.dir}/webapps/coreWeb"> <fileset dir="${app.dir}/drt/coreWeb"/> - </copy> + </copy> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/webapps/jsfWeb"> + <copy todir="${netui.test.dist.dir}/webapps/jsfWeb"> <fileset dir="${app.dir}/jsf/jsfWeb"/> - </copy> + </copy> - <!-- Get Junit tests --> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/junit/junitTests/org"> - <fileset dir="${test.classes.dir}/junitTests/org"/> - </copy> + <!-- Get Junit tests --> + <copy todir="${netui.test.dist.dir}/junit/junitTests"> + <fileset dir="${test.classes.dir}/junitTests" excludes="build.xml"/> + </copy> - <!-- Get general testRecorder resources --> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder"> + <!-- Get general testRecorder resources --> + <copy todir="${netui.test.dist.dir}/testRecorder"> <fileset dir="${build.dir}/tools/testRecorder"/> </copy> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/conf"> + <copy todir="${netui.test.dist.dir}/conf"> <fileset dir="${test.dir}/conf"/> </copy> - <!-- Get testRecorder tests and config files for coreWeb--> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/coreWeb/config"> + <!-- Get testRecorder tests and config files for coreWeb--> + <copy todir="${netui.test.dist.dir}/testRecorder/coreWeb/config"> <fileset dir="${app.dir}/drt/testRecorder/config" includes="*.xml"/> - </copy> + </copy> - <replace dir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/coreWeb/config" - token="@DOMAIN_DIR@/drt/testRecorder/tests" value="@DOMAIN_DIR@/testRecorder/coreWeb/tests"/> + <replace dir="${netui.test.dist.dir}/testRecorder/coreWeb/config" + token="@DOMAIN_DIR@/drt/testRecorder/tests" value="@DOMAIN_DIR@/testRecorder/coreWeb/tests"/> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/coreWeb/tests"> + <copy todir="${netui.test.dist.dir}/testRecorder/coreWeb/tests"> <fileset dir="${app.dir}/drt/testRecorder/tests"/> - </copy> + </copy> <!-- Get testRecorder tests and config files for jsfWeb--> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/jsfWeb/config"> + <copy todir="${netui.test.dist.dir}/testRecorder/jsfWeb/config"> <fileset dir="${app.dir}/jsf/testRecorder/config" excludes="testRecorder-webapp-*.xml"/> </copy> <copy file="${app.dir}/jsf/testRecorder/config/testRecorder-webapp-myfaces.xml" - tofile="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/jsfWeb/config/testRecorder-webapp.xml"> + tofile="${netui.test.dist.dir}/testRecorder/jsfWeb/config/testRecorder-webapp.xml"> </copy> - <replace dir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/jsfWeb/config" + <replace dir="${netui.test.dist.dir}/testRecorder/jsfWeb/config" token="@DOMAIN_DIR@/jsf/testRecorder/tests-myfaces" value="@DOMAIN_DIR@/testRecorder/jsfWeb/tests"/> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/testRecorder/jsfWeb/tests"> + <copy todir="${netui.test.dist.dir}/testRecorder/jsfWeb/tests"> <fileset dir="${app.dir}/jsf/testRecorder/tests-myfaces"/> </copy> - <!-- Get jsf resources --> - <copy todir="${test.dist.base.dir}/beehive-test-dist/netui/jsf"> + <!-- Get jsf resources --> + <copy todir="${netui.test.dist.dir}/jsf"> <fileset dir="${netui.home}/external/jsf"/> - </copy> + </copy> - <!-- Get Struts resources --> + <!-- Get Struts resources --> <ant antfile="${netui.home}/ant/webappTemplate.xml" target="deploy.struts" inheritAll="false"> <property name="struts.version" value="1.1"/> - <property name="webapp.dir" value="${test.dist.base.dir}/beehive-test-dist/netui/struts/struts1.1"/> + <property name="webapp.dir" value="${netui.test.dist.dir}/struts/struts1.1"/> </ant> <ant antfile="${netui.home}/ant/webappTemplate.xml" target="deploy.struts" inheritAll="false"> <property name="struts.version" value="1.2"/> - <property name="webapp.dir" value="${test.dist.base.dir}/beehive-test-dist/netui/struts/struts1.2"/> + <property name="webapp.dir" value="${netui.test.dist.dir}/struts/struts1.2"/> </ant> + + <!-- Get StrutsTestCase resources --> + <copy todir="${netui.test.dist.dir}/strutstestcase"> + <fileset dir="${netui.home}/test/external/strutstestcase"/> + </copy> + </target> <target name="usage" description="How to use this build file"> Added: incubator/beehive/trunk/netui/test/external/strutstestcase/strutstest-2.1.3.jar URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/external/strutstestcase/strutstest-2.1.3.jar?rev=169968&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/beehive/trunk/netui/test/external/strutstestcase/strutstest-2.1.3.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml Fri May 13 00:45:39 2005 @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> +<struts-config/> Propchange: incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/struts-config.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml Fri May 13 00:45:39 2005 @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<web-app xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" + version="2.4"> + + <display-name>Beehive Web Application</display-name> + + <filter> + <filter-name>PageFlowJspFilter</filter-name> + <filter-class>org.apache.beehive.netui.pageflow.PageFlowJspFilter</filter-class> + </filter> + + <filter> + <filter-name>PageFlowFacesFilter</filter-name> + <filter-class>org.apache.beehive.netui.pageflow.PageFlowFacesFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>PageFlowJspFilter</filter-name> + <url-pattern>*.jsp</url-pattern> + <dispatcher>FORWARD</dispatcher> + <dispatcher>REQUEST</dispatcher> + <dispatcher>INCLUDE</dispatcher> + </filter-mapping> + + <filter-mapping> + <filter-name>PageFlowJspFilter</filter-name> + <url-pattern>*.jspx</url-pattern> + <dispatcher>FORWARD</dispatcher> + <dispatcher>REQUEST</dispatcher> + <dispatcher>INCLUDE</dispatcher> + </filter-mapping> + + <filter-mapping> + <filter-name>PageFlowFacesFilter</filter-name> + <url-pattern>*.faces</url-pattern> + <dispatcher>FORWARD</dispatcher> + <dispatcher>REQUEST</dispatcher> + <dispatcher>INCLUDE</dispatcher> + </filter-mapping> + + <filter-mapping> + <filter-name>PageFlowFacesFilter</filter-name> + <url-pattern>*.jsf</url-pattern> + <dispatcher>FORWARD</dispatcher> + <dispatcher>REQUEST</dispatcher> + <dispatcher>INCLUDE</dispatcher> + </filter-mapping> + + <!-- Action Servlet Configuration (with debugging) --> + <servlet> + <servlet-name>action</servlet-name> + <servlet-class>org.apache.beehive.netui.pageflow.PageFlowActionServlet</servlet-class> + <init-param> + <param-name>config</param-name> + <param-value>/WEB-INF/struts-config.xml</param-value> + </init-param> + <init-param> + <param-name>debug</param-name> + <param-value>2</param-value> + </init-param> + <init-param> + <param-name>detail</param-name> + <param-value>2</param-value> + </init-param> + <load-on-startup>2</load-on-startup> + </servlet> + + <!-- The XmlHttpRequest handler Servlet --> + <servlet> + <servlet-name>XmlHttpRequestServlet</servlet-name> + <servlet-class>org.apache.beehive.netui.pageflow.xmlhttprequest.XmlHttpRequestServlet</servlet-class> + </servlet> + + <!-- Struts Action Servlet Mappings --> + <!-- Note that because Struts takes the *last* mapping here as the extension to add to + actions posted from forms, we must have *.do come after *.jpf (etc.). --> + <servlet-mapping> + <servlet-name>action</servlet-name> + <url-pattern>*.jpf</url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name>action</servlet-name> + <url-pattern>*.jpfs</url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name>action</servlet-name> + <url-pattern>*.jsfb</url-pattern> + </servlet-mapping> + + <servlet-mapping> + <servlet-name>action</servlet-name> + <url-pattern>*.do</url-pattern> + </servlet-mapping> + + <!-- XmlHttpRequest Servlet --> + <servlet-mapping> + <servlet-name>XmlHttpRequestServlet</servlet-name> + <url-pattern>*.xhr</url-pattern> + </servlet-mapping> + + <welcome-file-list> + <welcome-file>index.jsp</welcome-file> + </welcome-file-list> +</web-app> Propchange: incubator/beehive/trunk/netui/test/src/junitTests/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/beehive/trunk/netui/test/src/junitTests/build.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/build.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/build.xml (original) +++ incubator/beehive/trunk/netui/test/src/junitTests/build.xml Fri May 13 00:45:39 2005 @@ -3,6 +3,7 @@ <project name="Beehive/NetUI/JUnitTests" default="build" basedir="."> <import file="../../ant/netui-test-imports.xml"/> + <import file="../../../../ant/beehive-tools.xml"/> <property name="module.name" value="junitTests"/> <property name="module.dir" location="${test.src.dir}/${module.name}"/> @@ -12,6 +13,7 @@ <path id="junit.classpath"> <path refid="webapp.dependency.path"/> <path refid="junit.dependency.path"/> + <path refid="strutstestcase.dependency.path"/> <path refid="servlet.dependency.path"/> </path> @@ -22,16 +24,6 @@ <mkdir dir="${module.classes.dir}"/> - <javac srcdir="${module.dir}" - destdir="${module.classes.dir}" - classpathref="junit.classpath" - debug="${compile.debug}" - deprecation="${compile.deprecation}" - optimize="${compile.optimize}" - source="1.4"> - <include name="**/*.java"/> - </javac> - <copy todir="${module.classes.dir}"> <fileset dir="${module.dir}"> <exclude name="./build.xml"/> @@ -40,6 +32,15 @@ </copy> <copy todir="${module.classes.dir}/WEB-INF/" file="${netuiconfig.xml}"/> + <copy todir="${module.classes.dir}/WEB-INF/" file="${netui-validator-rules.xml}"/> + <copy todir="${module.classes.dir}/WEB-INF/" file="${validator-rules.xml}"/> + + <!-- Build all page flows and other classes. --> + <build-pageflows + srcdir="${module.dir}" + classoutputdir="${module.classes.dir}" + weboutputdir="${module.classes.dir}" + classpathref="junit.classpath"/> <jar jarfile="${module.jar}" basedir="${module.classes.dir}"> <manifest> Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java Fri May 13 00:45:39 2005 @@ -0,0 +1,114 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * 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.pageflow; + +import org.apache.beehive.netui.pageflow.PageFlowActionServlet; +import servletunit.struts.MockStrutsTestCase; +import servletunit.HttpServletRequestSimulator; +import junit.framework.AssertionFailedError; + +/** + * Base class for Page Flow test cases running under StrutsTestCase/JUnit. + */ +public abstract class MockPageFlowTestCase + extends MockStrutsTestCase +{ + protected void setUp() + throws Exception + { + super.setUp(); + setActionServlet( new PageFlowActionServlet() ); + + // The page flow class must be on classpath; if not, assert. + try + { + Class.forName( getPageFlowClassName() ); + } + catch ( ClassNotFoundException e ) + { + throw new AssertionFailedError( "Page flow class " + getPageFlowClassName() + " not found." ); + } + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + } + + /** + * Get the fully-qualified class name for the page flow to be tested. + */ + protected abstract String getPageFlowClassName(); + + /** + * Get the webapp name, to be used in constructing the request URI. It is rarely necessary to specify this; it + * defaults to "mockPageFlowWebapp". + */ + protected String getWebappName() + { + return "mockPageFlowWebapp"; + } + + /** + * Run the given action on the page flow determined by [EMAIL PROTECTED] #getPageFlowClassName}. + */ + protected void runAction( String actionName ) + { + String modulePath = getPageFlowClassName().replace( '.', '/' ); + int lastSlash = modulePath.lastIndexOf( '/' ); + String actionPath = '/' + actionName + ".do"; + HttpServletRequestSimulator mockRequest = getMockRequest(); + + // + // Set up the request path-info and request servlet-path. The logic differs when the page flow is the root + // module (the second case, below. + // + if ( lastSlash != -1 ) + { + modulePath = modulePath.substring( 0, lastSlash ); + setRequestPathInfo( modulePath, actionPath ); + mockRequest.setServletPath( modulePath + actionPath ); + } + else + { + assertTrue( false ); + setRequestPathInfo( actionPath ); + mockRequest.setServletPath( actionPath ); + } + + mockRequest.setRequestURI( '/' + getWebappName() + mockRequest.getServletPath() ); + + actionPerform(); + } + + /** + * Add an update expression and the value to be set. + * @param expression the update expression, e.g., "actionForm.foo". + * @param value the value to be set. + */ + protected void addUpdateExpression( String expression, String value ) + { + addRequestParameter( '{' + expression + '}', new String[]{ value } ); + } + + protected MockPageFlowTestCase( String name ) + { + super( name ); + } +} Propchange: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/MockPageFlowTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf Fri May 13 00:45:39 2005 @@ -0,0 +1,137 @@ +package org.apache.beehive.netui.test.pageflow.validation; + +import org.apache.beehive.netui.pageflow.*; +import org.apache.beehive.netui.pageflow.annotations.*; +import org.apache.struts.action.*; +import javax.servlet.http.HttpServletRequest; +import java.io.Serializable; + [EMAIL PROTECTED]( + simpleActions={ + @Jpf.SimpleAction(name="begin", path="index.jsp") + }, + messageBundles={ + @Jpf.MessageBundle(bundlePath="org.apache.beehive.netui.test.pageflow.validation.Messages") + } +) +public class Controller extends PageFlowController +{ + /** + * Validate a non-FormData-derived bean. + */ + @Jpf.Action( + forwards={ + @Jpf.Forward(name="index", path="index.jsp") + }, + [EMAIL PROTECTED](name="failure", path="index.jsp") + ) + public Forward submitAnyBean( AnyBeanForm form ) + { + return new Forward( "index" ); + } + + + /** + * Validate a FormData-derived bean. + */ + @Jpf.Action( + forwards={ + @Jpf.Forward(name="index", path="index.jsp") + }, + [EMAIL PROTECTED](name="failure", path="index.jsp") + ) + public Forward submitFormData( FormDataForm form ) + { + return new Forward( "index" ); + } + + /** + * Validate a FormData-derived bean. + */ + @Jpf.Action( + forwards={ + @Jpf.Forward(name="index", path="index.jsp") + }, + [EMAIL PROTECTED](name="failure", path="index.jsp") + ) + public Forward submitValidatableFormData( ValidatableFormDataForm form ) + { + return new Forward( "index" ); + } + + public static class AnyBeanForm + implements Serializable, Validatable + { + private String _foo; + + @Jpf.ValidatableProperty( + [EMAIL PROTECTED](chars=10, messageKey="message2") + ) + public String getFoo() + { + return _foo; + } + + public void setFoo( String foo ) + { + _foo = foo; + } + + public void validate( ActionMapping mapping, HttpServletRequest request, ActionMessages errors ) + { + errors.add( "foo", new ActionMessage( "message1" ) ); + } + } + + public static class FormDataForm + extends FormData + { + private String _foo; + + @Jpf.ValidatableProperty( + [EMAIL PROTECTED](chars=10, messageKey="message2") + ) + public String getFoo() + { + return _foo; + } + + public void setFoo( String foo ) + { + _foo = foo; + } + + public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) + { + ActionErrors errors = super.validate( mapping, request ); + if ( errors == null ) errors = new ActionErrors(); + errors.add( "foo", new ActionMessage( "message1" ) ); + return errors; + } + } + + public static class ValidatableFormDataForm + extends FormData + implements Validatable + { + private String _foo; + + @Jpf.ValidatableProperty( + [EMAIL PROTECTED](chars=10, messageKey="message2") + ) + public String getFoo() + { + return _foo; + } + + public void setFoo( String foo ) + { + _foo = foo; + } + + public void validate( ActionMapping mapping, HttpServletRequest request, ActionMessages errors ) + { + errors.add( "foo", new ActionMessage( "message1" ) ); + } + } +} Propchange: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Controller.jpf ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties Fri May 13 00:45:39 2005 @@ -0,0 +1,2 @@ +message1=Message 1 +message2=Message 2 Propchange: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/Messages.properties ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java Fri May 13 00:45:39 2005 @@ -0,0 +1,74 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * 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.pageflow.validation; + +import junit.framework.TestSuite; +import junit.framework.Test; +import org.apache.beehive.netui.test.pageflow.MockPageFlowTestCase; + +public class ValidationTest + extends MockPageFlowTestCase +{ + /** + * Test of declarative validation and method validation on a form bean which does not extend FormData, but which + * implements Validatable. + */ + public void testAnyBean() + { + addUpdateExpression( "actionForm.foo", "too-short" ); + runAction( "submitAnyBean" ); + verifyActionErrors( new String[]{ "message1", "message2" } ); + } + + /** + * Test of declarative validation and method validation on a form bean which extends FormData and which overrides + * the base validate(). + */ + public void testFormData() + { + addUpdateExpression( "actionForm.foo", "too-short" ); + runAction( "submitFormData" ); + verifyActionErrors( new String[]{ "message1", "message2" } ); + } + + /** + * Test of declarative validation and method validation on a form bean which extends FormData and which implements + * Validatable. + */ + public void testValidatableFormData() + { + addUpdateExpression( "actionForm.foo", "too-short" ); + runAction( "submitValidatableFormData" ); + verifyActionErrors( new String[]{ "message1", "message2" } ); + } + + public ValidationTest( String name ) + { + super( name ); + } + + protected String getPageFlowClassName() + { + return "org.apache.beehive.netui.test.pageflow.validation.Controller"; + } + + public static Test suite() + { + return new TestSuite( ValidationTest.class ); + } +} Propchange: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/ValidationTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp?rev=169968&view=auto ============================================================================== --- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp (added) +++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp Fri May 13 00:45:39 2005 @@ -0,0 +1,25 @@ +<%@ page language="java" contentType="text/html;charset=UTF-8"%> +<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%> +<%@ taglib prefix="netui-data" uri="http://beehive.apache.org/netui/tags-databinding-1.0"%> +<%@ taglib prefix="netui-template" uri="http://beehive.apache.org/netui/tags-template-1.0"%> + + +<netui:html> + <head> + <netui:base/> + </head> + <netui:body> + <h3>${pageFlow.URI}</h3> + + <netui:anchor action="begin">begin</netui:anchor> + + <netui:form action="submit"> + foo: <netui:textBox dataSource="actionForm.foo"/><netui:error key="foo"/> + <br/> + <netui:button value="submit"/> + </netui:form> + </netui:body> +</netui:html> + + + Propchange: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/pageflow/validation/index.jsp ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/beehive/trunk/test/dist-test/build.xml URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/test/dist-test/build.xml?rev=169968&r1=169967&r2=169968&view=diff ============================================================================== --- incubator/beehive/trunk/test/dist-test/build.xml (original) +++ incubator/beehive/trunk/test/dist-test/build.xml Fri May 13 00:45:39 2005 @@ -90,7 +90,7 @@ <ant dir="${beehive.home}/netui/test/dist-test" antfile="build.xml" target="build.tests" inheritAll="false"/> </target> - <target name="build.controls.tests" description="Build netui tests"> + <target name="build.controls.tests" description="Build controls tests"> <ant dir="${beehive.home}/controls/test/dist-test" antfile="build.xml" target="build.tests" inheritAll="false"> <property name="test.dist.base.dir" location="${test.dist.base.dir}"/> <property name="beehive.home" location="${beehive.home}"/> @@ -103,7 +103,7 @@ </ant> </target> - <target name="assemble.controls.tests" description="Assemble the netui tests for the distribution"> + <target name="assemble.controls.tests" description="Assemble the controls tests for the distribution"> <ant dir="${beehive.home}/controls/test/dist-test" antfile="build.xml" target="assemble.tests" inheritAll="false"> <property name="test.dist.base.dir" location="${test.dist.base.dir}"/> </ant>
