vmassol 01/04/09 04:52:40 Added: cactus README cactus/build build-servletapi.xml build.properties.sample build.properties.tests build.xml cactus/conf manifest manifest-ant version.txt cactus/conf/sample/build build.xml cactus/conf/sample/build/servlet22 build-tests.xml build.properties.sample cactus/conf/sample/build/servlet23 build-tests.xml build.properties.sample cactus/conf/sample/conf manifest web.xml cactus/conf/sample/conf/test cactus.properties web.xml cactus/conf/sample/conf/test/orion14 application.xml default-web-site.xml principals.xml rmi.xml server.xml cactus/conf/sample/conf/test/resin12 resin.conf cactus/conf/sample/conf/test/resin13 resin.conf cactus/conf/sample/conf/test/tomcat32 server.xml cactus/conf/sample/conf/test/tomcat40 server.xml cactus/conf/sample/conf/test/weblogic51 weblogic.policy weblogic.properties cactus/docs/framework/skins/jakarta.apache.org loader.xml cactus/docs/framework/skins/jakarta.apache.org/resources add.jpg fix.jpg jakarta-logo.gif logocactus.gif note.gif remove.jpg update.jpg cactus/docs/framework/skins/jakarta.apache.org/stylesheets book2project.xsl changes2document.xsl copyover.xsl document2html.xsl todo2document.xsl cactus/docs/framework/xdocs ant.xml architecture.xml changes.xml configuration.xml contributors.xml doc-book.xml downloads.xml faq.xml features.xml index.xml installation.xml installation_ant.xml installation_sample.xml javadoc.xml sample_servlet.xml servlets.xml site-book.xml todo.xml using.xml cactus/docs/framework/xdocs/dtd changes-v10.dtd characters.ent document-v10.dtd todo-v10.dtd cactus/docs/framework/xdocs/images add.jpg archi.jpg archi_jsp.jpg archi_servlet.jpg fix.jpg remove.jpg update.jpg cactus/docs/framework/xdocs/misc archi.ppt archi_jsp.ppt archi_servlet.ppt cactus/docs/sample README cactus/src/ant/org/apache/commons/cactus/ant ResinRun.java RunServerTestsTask.java StartServerHelper.java StartServerTask.java StopServerHelper.java StopServerTask.java cactus/src/framework/servlet22/org/apache/commons/cactus/server HttpServletRequestWrapper.java RequestDispatcherWrapper.java ServletConfigWrapper.java ServletContextWrapper.java cactus/src/framework/servlet23/org/apache/commons/cactus/server HttpServletRequestWrapper.java RequestDispatcherWrapper.java ServletConfigWrapper.java ServletContextWrapper.java cactus/src/framework/share/org/apache/commons/cactus JspTestCase.java ServiceDefinition.java ServiceEnumeration.java ServletTestCase.java ServletTestRequest.java ServletTestResult.java ServletURL.java overview.html package.html cactus/src/framework/share/org/apache/commons/cactus/client AbstractHttpClient.java AssertionFailedErrorWrapper.java HttpClientHelper.java JspHttpClient.java ServletExceptionWrapper.java ServletHttpClient.java cactus/src/framework/share/org/apache/commons/cactus/server CallerHelper.java JspImplicitObjects.java JspTestCaller.java ServletImplicitObjects.java ServletTestCaller.java ServletTestRedirector.java cactus/src/framework/share/org/apache/commons/cactus/util AssertUtils.java ClientCookie.java cactus/src/sample/servlet22/org/apache/commons/cactus/sample/unit TestServletTestCaseSpecific.java cactus/src/sample/servlet23/org/apache/commons/cactus/sample/unit TestServletTestCaseSpecific.java cactus/src/sample/share/org/apache/commons/cactus/sample SampleServlet.java SampleServletConfig.java TestSampleServlet.java TestSampleServletConfig.java cactus/src/sample/share/org/apache/commons/cactus/sample/unit TestJspTestCase.java TestServletTestCase1.java TestServletTestCase1_ExceptionNotSerializable.java TestServletTestCase1_ExceptionSerializable.java TestServletTestCase1_InterceptorServletTestCase.java TestServletTestCase2.java TestServletTestCase3.java TestServletTestCase4.java cactus/src/test/share/org/apache/commons/cactus TestAll.java cactus/src/test/share/org/apache/commons/cactus/util TestAssertUtils.java cactus/web redirector.jsp cactus/web/sample/test test.jsp Log: initial import of version 1.0 beta 1 (import from jakarta-commons-sandbox) Revision Changes Path 1.1 jakarta-commons/cactus/README Index: README =================================================================== Instructions for building/using Cactus -------------------------------------- See the online web site which has all the information for using Cactus and understanding how it works : http://jakarta.apache.org/commons/cactus Thanks. Vincent Massol 1.1 jakarta-commons/cactus/build/build-servletapi.xml Index: build-servletapi.xml =================================================================== <?xml version="1.0"?> <!-- ============================================================================= Build file for the Cactus project, for a given Servlet API. All targets that depend upon the Servlet API are found here. The following properties need to be set prior to calling this build file : servlet.api [REQUIRED] The Servlet API against which Cactus is built. Valid values are {22, 23} servlet.jar [REQUIRED] The path to the Servlet API jar for the chosen Servlet API junit.jar [REQUIRED] The path to the JUnit jar file dist.dir [REQUIRED] The directories where distributable files will be copied with version number postfixed. Additionally and depending on the servlet engines whith which you wish to run your tests, you'll need to set the following properties : resin.home.12 [OPTIONAL] Resin 1.2 home directory (required for the tests_resin_12 target only) resin.home.13 [OPTIONAL] Resin 1.3 home directory (required for the tests_resin_13 target only) tomcat.home.32 [OPTIONAL] Tomcat 3.2 home directory (required for the tests_tomcat_32 target only) tomcat.home.40 [OPTIONAL] Tomcat 4.0 home directory (required for the tests_tomcat_40 target only) weblogic.home.51 [OPTIONAL] WebLogic 5.1 home directory (required for the tests_weblogic_51 target only) This script must not be called directly. It must be called by the build.xml script in the same directory. It will inherit numerous properties from that build file. ============================================================================= --> <project name="Cactus build for a Servlet API" default="jar" basedir=".."> <!-- ======================================================================== Set the properties related to the source tree ======================================================================== --> <property name="src.java.servlet.dir" value="${src.dir}/framework/servlet${servlet.api}"/> <!-- ======================================================================== Set the properties related to the build area ======================================================================== --> <!-- Destination locations for the build (relative to the basedir as specified in the basedir attribute of the project tag) --> <property name="out.dir" value="${out.root.dir}/servlet${servlet.api}"/> <property name="out.dist.dir" value="${out.dir}/dist"/> <property name="out.lib.dir" value="${out.dist.dir}/lib"/> <property name="out.src.dir" value="${out.dir}/src"/> <property name="out.classes.dir" value="${out.dir}/classes"/> <property name="out.doc.dir" value="${out.dist.dir}/doc"/> <property name="out.javadoc.dir" value="${out.doc.dir}/javadoc"/> <property name="out.conf.dir" value="${out.dir}/conf"/> <!-- Destination locations for the Cactus sample application (also used as functional tests for Cactus) --> <property name="out.sample.dir" value="${out.dist.dir}/sample"/> <property name="out.sample.build.dir" value="${out.sample.dir}/build"/> <property name="out.sample.etc.dir" value="${out.sample.build.dir}/etc"/> <property name="out.sample.conf.dir" value="${out.sample.dir}/conf"/> <property name="out.sample.doc.dir" value="${out.sample.dir}/docs"/> <property name="out.sample.src.dir" value="${out.sample.dir}/src"/> <property name="out.sample.web.dir" value="${out.sample.dir}/web"/> <!-- ======================================================================== Short names of deliverables ======================================================================== --> <!-- The full distribution name --> <property name="full.name" value="${project.name}-${servlet.api}"/> <!-- The Cactus jar file. This is the file that should be used at runtime by end users --> <property name="jar.name" value="${project.name}"/> <!-- The Cactus javadocs for Servlet API 2.2 and 2.3. These files do not need to be redistributed to end-users. It is only needed to put the javadoc online to the Cactus web site. --> <property name="javadoc.name" value="${project.name}-javadoc-${servlet.api}"/> <!-- ======================================================================== Full names of deliverables ======================================================================== --> <!-- The full distribution name --> <property name="final.full.name" value="${out.dist.dir}/${full.name}"/> <!-- The Cactus jar file. This is the file that should be used at runtime by end users --> <property name="final.jar.name" value="${out.lib.dir}/${jar.name}.jar"/> <!-- ======================================================================== Useful file patterns for targets ======================================================================== --> <!-- All source files of the projet. These source files will be copied to the destination source directory in the prepare task --> <patternset id="all.src.files"> <!-- All java files --> <include name="**/*.java"/> <!-- All doc files --> <include name="**/package.html"/> <include name="**/overview.html"/> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- All non java files in the src directory --> <patternset id="all.nonjava.files"> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- ======================================================================== Initialize the build. Must be called by all targets ======================================================================== --> <target name="init"> <echo message="--------- ${project.fullname} ${project.version} for Servlet API ${servlet.api} ---------"/> <echo message=""/> <echo message="servlet.api = ${servlet.api}"/> <!-- Filters --> <filter token="version" value="${project.version}"/> <filter token="year" value="${year}"/> <filter token="jar.name" value="${jar.name}"/> <filter token="jar.ant.name" value="${jar.ant.name}"/> <filter token="servlet.jar" value="${servlet.jar}"/> <filter token="junit.jar" value="${junit.jar}"/> <filter token="servlet.api" value="${servlet.api}"/> <filter token="today" value="${TODAY}"/> <!-- Full names of distributables. They are defined here because the properties need to have a valid ${DSTAMP} property set and the tstamp task need to be located in a target --> <!-- The full distribution name --> <property name="dist.full.name" value="${dist.dir}/${full.name}-${DSTAMP}"/> <!-- The Cactus javadocs for Servlet API 2.2 and 2.3. These files do not need to be redistributed to end-users. It is only needed to put the javadoc online to the Cactus web site. --> <property name="dist.javadoc.name" value="${out.root.dir}/${javadoc.name}-${DSTAMP}"/> </target> <!-- ======================================================================== Help on usage. List available targets ======================================================================== --> <target name="usage" depends="init"> <echo message=""/> <echo message="${project.fullname} build file for Servlet API ${servlet.api}"/> <echo message="------------------------------------------------------"/> <echo message=""/> <echo message=" Available targets are :"/> <echo message=""/> <echo message=" jar --> generates the jar file (default)"/> <echo message=" doc --> generates the docs (javadoc, ...)"/> <echo message=" tests-unit --> run the unit tests"/> <echo message=" tests-functional --> run the functional tests"/> <echo message=" sample --> generate the sample application"/> <echo message=" dist --> generate the distributables"/> <echo message=""/> </target> <!-- ======================================================================== Prepare the output directory by copying the source files into it ======================================================================== --> <target name="prepare" depends="init"> <mkdir dir="${out.src.dir}"/> <!-- Copy all source files to destination dir. Apply the filters in order to replace the tokens for the copyright year and the version --> <copy todir="${out.src.dir}" filtering="on"> <fileset dir="${src.java.share.dir}"> <patternset refid="all.src.files"/> </fileset> <fileset dir="${src.java.servlet.dir}"> <patternset refid="all.src.files"/> </fileset> <fileset dir="${src.java.test.share.dir}"> <patternset refid="all.src.files"/> </fileset> </copy> </target> <!-- ======================================================================== Compiles the source directory ======================================================================== --> <!-- Preparation target for the compile target --> <target name="prepare-compile" depends="prepare"> <mkdir dir="${out.classes.dir}"/> </target> <!-- Run the java compilation --> <target name="compile" depends="prepare-compile"> <javac srcdir="${out.src.dir}" destdir="${out.classes.dir}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> <!-- Exclude all files that are not .java source files --> <!-- All doc files --> <exclude name="**/package.html"/> <exclude name="**/overview.html"/> <!-- All conf files (including test files) --> <exclude name="**/*.txt"/> <exclude name="**/*.xml"/> <exclude name="**/*.properties"/> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> </classpath> </javac> <!-- Copies non java files that need to be in the classes directory --> <copy todir="${out.classes.dir}"> <fileset dir="${src.java.share.dir}"> <patternset refid="all.nonjava.files"/> </fileset> <fileset dir="${src.java.servlet.dir}"> <patternset refid="all.nonjava.files"/> </fileset> </copy> </target> <!-- ======================================================================== Create the runtime jar file ======================================================================== --> <!-- Preparation target for the jar target --> <target name="prepare-jar" depends="compile"> <mkdir dir="${out.conf.dir}"/> <mkdir dir="${out.lib.dir}"/> <!-- Copy the manifest in order to replace the version token filter --> <copy todir="${out.conf.dir}" filtering="on"> <fileset dir="${conf.dir}" > <include name="manifest"/> </fileset> </copy> </target> <!-- Generate the jar file --> <target name="jar" depends="prepare-jar"> <jar jarfile="${final.jar.name}" basedir="${out.classes.dir}" manifest="${out.conf.dir}/manifest"> <!-- Do not include test files in the runtime jar --> <exclude name="**/Test*.*"/> <exclude name="**/test*.*"/> </jar> </target> <!-- ======================================================================== Generate the javadoc ======================================================================== --> <!-- Preparation target for the javadoc target --> <target name="prepare-javadoc" depends="prepare"> <mkdir dir="${out.javadoc.dir}"/> </target> <!-- Generate the javadoc for the current Servlet API --> <target name="javadoc" depends="prepare-javadoc"> <javadoc sourcepath="${out.src.dir}" packagenames="org.apache.commons.cactus.*" destdir="${out.javadoc.dir}" author="true" public="true" version="true" use="true" overview="${out.src.dir}/org/apache/commons/cactus/overview.html" windowtitle="${project.fullname} ${project.version} for Servlet ${servlet.api} API" doctitle="${project.fullname} ${project.version} for Servlet ${servlet.api} API" bottom="Copyright &copy; ${year} Apache Software Foundation. All Rights Reserved."> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> </classpath> </javadoc> <!-- Create a gzip file of the javadoc. This is for putting to the Cactus web site. It needs to be unzipped in the root document of the web site. This needs to be done for each Servlet API javadoc. This file is not intended to be redistributed as part of the end-user redistributable. It is simply to help create the web site --> <tar tarfile="${dist.javadoc.name}.tar" basedir="${out.javadoc.dir}"/> <gzip zipfile="${dist.javadoc.name}.tar.gz" src="${dist.javadoc.name}.tar"/> <delete file="${dist.javadoc.name}.tar"/> </target> <!-- ======================================================================== Generate the full documentation for a given Servlet API, i.e. web site + javadoc ======================================================================== --> <!-- Preparation target for the doc target --> <target name="prepare-doc" depends="javadoc"> <mkdir dir="${out.doc.dir}"/> <mkdir dir="${out.doc.dir}/images"/> <!-- Copy doc-book.xml to book.xml for defining the documentation web site and replacing token filters (year) --> <delete file="${xdoc.dir}/book.xml"/> <copy file="${xdoc.dir}/doc-book.xml" tofile="${xdoc.dir}/book.xml" filtering="on"/> <!-- Copy the images --> <copy todir="${out.site.dir}/images"> <fileset dir="${xdoc.dir}/images"/> </copy> </target> <!-- Generate the documentation --> <target name="doc" depends="prepare-doc"> <!-- Generate the documentation web site --> <stylebook book="${xdoc.dir}/book.xml" skinDirectory="${skin.dir}/jakarta.apache.org" targetDirectory="${out.doc.dir}"> <classpath> <pathelement path="${java.class.path}"/> </classpath> </stylebook> </target> <!-- ======================================================================== Generate the sample application directory structure and zip file. This sample application will be used to exercise Cactus functional tests. And of course, it serves as a sample on how to use Cactus ======================================================================== --> <patternset id="all.sample.conf.servlet22.files"> <include name="orion14/**"/> <include name="resin12/**"/> <include name="tomcat32/**"/> <include name="weblogic51/**"/> </patternset> <patternset id="all.sample.conf.servlet23.files"> <include name="tomcat40/**"/> <include name="resin13/**"/> </patternset> <target name="prepare-sample" depends="jar"> <!-- Create output directory structure and sample files in it --> <mkdir dir="${out.sample.dir}"/> <mkdir dir="${out.sample.doc.dir}"/> <mkdir dir="${out.sample.build.dir}"/> <mkdir dir="${out.sample.conf.dir}"/> <mkdir dir="${out.sample.src.dir}"/> <mkdir dir="${out.sample.web.dir}"/> <!-- Copy build files --> <copy todir="${out.sample.build.dir}" filtering="on"> <fileset dir="${sample.build.dir}" excludes="servlet22,servlet23"/> <fileset dir="${sample.build.dir}/servlet${servlet.api}"/> </copy> <!-- Copy src files --> <copy todir="${out.sample.src.dir}/share"> <fileset dir="${sample.src.dir}/share"/> </copy> <copy todir="${out.sample.src.dir}/servlet${servlet.api}"> <fileset dir="${sample.src.dir}/servlet${servlet.api}"/> </copy> <!-- Copy conf files --> <copy todir="${out.sample.conf.dir}/test"> <fileset dir="${sample.conf.dir}/test"> <patternset refid="all.sample.conf.servlet${servlet.api}.files"/> </fileset> </copy> <copy tofile="${out.sample.conf.dir}/test/web.xml" file="${sample.conf.dir}/test/web.xml"/> <copy tofile="${out.sample.conf.dir}/test/cactus.properties" file="${sample.conf.dir}/test/cactus.properties"/> <copy todir="${out.sample.conf.dir}"> <fileset dir="${sample.conf.dir}"/> </copy> <!-- Copy web files --> <copy file="${web.dir}/redirector.jsp" tofile="${out.sample.web.dir}/test/redirector.jsp"/> <copy todir="${out.sample.web.dir}"> <fileset dir="${sample.web.dir}"/> </copy> <!-- Copy license file --> <copy file="LICENSE" tofile="${out.sample.dir}"/> <!-- Copy doc files --> <copy todir="${out.sample.doc.dir}"> <fileset dir="${sample.doc.dir}"> <exclude name="README"/> </fileset> </copy> <copy file="${sample.doc.dir}/README" tofile="${out.sample.dir}/README"/> </target> <target name="sample" depends="prepare-sample"> </target> <!-- ======================================================================== Run the unit tests. Only run the tests that do not need a servlet engine. For the other tests needing a servlet engine, they are part of the sample application and will be exercised there ======================================================================== --> <target name="tests-unit" depends="compile"> <junit printsummary="yes" haltonfailure="yes" fork="yes"> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${out.classes.dir}"/> </classpath> <formatter type="plain" usefile="false"/> <test name="org.apache.commons.cactus.TestAll"/> </junit> </target> <!-- ======================================================================== Run the functional tests ======================================================================== --> <target name="tests-functional22-resin12-if" if="resin.home.12"> <property name="resin.flag.12" value="-Dresin.home.12=${resin.home.12}"/> </target> <target name="tests-functional22-resin12-else" unless="resin.home.12"> <property name="resin.flag.12" value=""/> </target> <target name="tests-functional22-tomcat32-if" if="tomcat.home.32"> <property name="tomcat.flag.32" value="-Dtomcat.home.32=${tomcat.home.32}"/> </target> <target name="tests-functional22-tomcat32-else" unless="tomcat.home.32"> <property name="tomcat.flag.32" value=""/> </target> <target name="tests-functional22-orion14-if" if="orion.home.14"> <property name="orion.flag.14" value="-Dorion.home.14=${orion.home.14}"/> </target> <target name="tests-functional22-orion14-else" unless="orion.home.14"> <property name="orion.flag.14" value=""/> </target> <target name="tests-functional22-weblogic51-if" if="weblogic.home.51"> <property name="weblogic.flag.51" value="-Dweblogic.home.51=${weblogic.home.51}"/> </target> <target name="tests-functional22-weblogic51-else" unless="weblogic.home.51"> <property name="weblogic.flag.51" value=""/> </target> <target name="tests-functional22-checks" depends="tests-functional22-resin12-if, tests-functional22-resin12-else, tests-functional22-tomcat32-if, tests-functional22-tomcat32-else, tests-functional22-orion14-if, tests-functional22-orion14-else, tests-functional22-weblogic51-if, tests-functional22-weblogic51-else"> </target> <target name="tests-functional22" depends="sample,tests-functional22-checks"> <copy tofile="${out.sample.build.dir}/build.properties" file="${build.dir}/build.properties.tests" filtering="on"/> <java classname="org.apache.tools.ant.Main" dir="${out.sample.build.dir}" fork="yes" failonerror="yes"> <arg value="${resin.flag.12}"/> <arg value="${tomcat.flag.32}"/> <arg value="${orion.flag.14}"/> <arg value="${weblogic.flag.51}"/> <arg value="tests_all"/> <classpath> <pathelement path="${java.class.path}"/> </classpath> </java> </target> <target name="tests-functional23-resin13-if" if="resin.home.13"> <property name="resin.flag.13" value="-Dresin.home.13=${resin.home.13}"/> </target> <target name="tests-functional23-resin13-else" unless="resin.home.13"> <property name="resin.flag.13" value=""/> </target> <target name="tests-functional23-tomcat40-if" if="tomcat.home.40"> <property name="tomcat.flag.40" value="-Dtomcat.home.40=${tomcat.home.40}"/> </target> <target name="tests-functional23-tomcat40-else" unless="tomcat.home.40"> <property name="tomcat.flag.40" value=""/> </target> <target name="tests-functional23-checks" depends="tests-functional23-resin13-if, tests-functional23-resin13-else, tests-functional23-tomcat40-if, tests-functional23-tomcat40-else"> </target> <target name="tests-functional23" depends="sample,tests-functional23-checks"> <copy tofile="${out.sample.build.dir}/build.properties" file="${build.dir}/build.properties.tests" filtering="on"/> <java classname="org.apache.tools.ant.Main" dir="${out.sample.build.dir}" fork="yes" failonerror="yes"> <arg value="${resin.flag.13}"/> <arg value="${tomcat.flag.40}"/> <arg value="tests_all"/> <classpath> <pathelement path="${java.class.path}"/> </classpath> </java> </target> <!-- ======================================================================== Build all distributables and copies them to the dist.dir directory ======================================================================== --> <target name="prepare-dist" depends="jar,doc,sample"> <mkdir dir="${dist.dir}"/> <!-- Copy the custom Ant tasks jar to the servlet API dist directory --> <copy file="${final.jar.ant.name}" todir="${out.lib.dir}"/> <!-- Copy the license file --> <copy file="LICENSE" todir="${out.dist.dir}"/> <!-- Copy the README file --> <copy file="README" todir="${out.dist.dir}"/> <!-- Copy the version.txt file --> <copy file="${conf.dir}/version.txt" todir="${out.dist.dir}" filtering="on"/> </target> <target name="dist" depends="prepare-dist"> <zip zipfile="${dist.full.name}.zip"> <zipfileset dir="${out.dist.dir}" prefix="${project.name}-${servlet.api}-${DSTAMP}"/> </zip> </target> </project> 1.1 jakarta-commons/cactus/build/build.properties.sample Index: build.properties.sample =================================================================== # Properties related to the user's environment. This file should be provided # for building Cactus or the properties need to be specified on the command # line when starting Ant with the -D switch or from a higher level build file junit.jar = f:/applis/jakarta-ant-1.4alpha/lib/junit.jar # Note: If you want to build only for a given servlet API, just comment the # properties for the servlet jar that you don't want to build for. For # example if you don't want to build the Servlet 2.2 API, just comment # the "servlet22.jar" property. servlet22.jar = f:/applis/apache-dev/jakarta-servletapi/lib/servlet.jar servlet23.jar = f:/applis/apache-dev/jakarta-servletapi-4/lib/servlet.jar # The following jars are only needed for the 'dependencies' target, used to # generate a zip file containing all dependent jars stylebook.jar = f:/applis/jakarta-ant-1.4alpha/lib/stylebook-1.0-b3_xalan-2.jar xerces.jar = f:/applis/jakarta-ant-1.4alpha/lib/xerces.jar xalan.jar = f:/applis/jakarta-ant-1.4alpha/lib/xalan.jar crimson.jar = f:/applis/jakarta-ant-1.4alpha/lib/crimson.jar # Distribution directory (if none is specified here, it will default to # out/dist #dist.dir = e:/tmp/cactus-dist # Servlet engine locations for the tests # Note: If you don't want to run the test on a given servlet engine, just # comment it's home property. For example, if you don't want to run the # tests on the Resin 1.2, comment the "resin.home.12" property. resin.home.12 = f:/applis/resin-1.2.s010208 tomcat.home.32 = f:/applis/jakarta-tomcat-3.2.1 orion.home.14 = f:/applis/orion-1.4.5 weblogic.home.51 = e:/weblogic resin.home.13 = f:/applis/resin-1.3.s010125 tomcat.home.40 = f:/applis/jakarta-tomcat-4.0-b1 1.1 jakarta-commons/cactus/build/build.properties.tests Index: build.properties.tests =================================================================== # This property file will be used by build.xml when running the functional # tests. This is the property file that will be hold the required properties # for running the sample build file. # Properties related to the user's environment. This file should be provided # for building the Cactus Sample or the properties need to be specified on # the command line when starting Ant with the -D switch servlet.jar = @servlet.jar@ cactus.jar = [EMAIL PROTECTED]@.jar cactus.ant.jar = [EMAIL PROTECTED]@.jar [EMAIL PROTECTED]@ # Servlet engine locations for the tests # None should be defined here. They will be defined using '-D' flag in the # build-servletapi.xml build file 1.1 jakarta-commons/cactus/build/build.xml Index: build.xml =================================================================== <?xml version="1.0"?> <!-- ============================================================================= Build file for the Cactus project. This build file will call the build-servletapi.xml build file for several Servlet API (2.2 and 2.3). The following properties need to be set in a ./build.properties or or ${user.home}/build.properties file : servlet22.jar [OPTIONAL] The path to the Servlet API 2.2 jar. Required only if you want to build against this API servlet23.jar [OPTIONAL] The path to the Servlet API 2.3 jar. Required only if you want to build against this API junit.jar [REQUIRED] The path to the JUnit jar file stylebook.jar [OPTIONAL] The path to the Stylebook jar file. Required only for the dependencies target xerces.jar [OPTIONAL] The path to the Xerces jar file. Required only for the dependencies target xalan.jar [OPTIONAL] The path to the Xalan jar file. Required only for the dependencies target crimson.jar [OPTIONAL] The path to the Crimson jar file. Required only for the dependencies target dist.dir [OPTIONAL] The directories where distributable files will be copied with version number postfixed. Required for the dist target only. Default is out/dist Additionally and depending on the servlet engines whith which you wish to run your tests, you'll need to set the following properties : resin.home.12 [OPTIONAL] Resin 1.2 home directory (required for the tests_resin_12 target only) resin.home.13 [OPTIONAL] Resin 1.3 home directory (required for the tests_resin_13 target only) tomcat.home.32 [OPTIONAL] Tomcat 3.2 home directory (required for the tests_tomcat_32 target only) tomcat.home.40 [OPTIONAL] Tomcat 4.0 home directory (required for the tests_tomcat_40 target only) weblogic.home.51 [OPTIONAL] WebLogic 5.1 home directory (required for the tests_weblogic_51 target only) This script should be started with the following command line : ant <target> Run "ant usage" to get a list of available targets. The default target is "jar" ============================================================================= --> <project name="Cactus" default="jar" basedir=".."> <!-- Give user a chance to override without editing this file (and without typing -D each time it compiles it) --> <property file="build/build.properties" /> <property file="${user.home}/build.properties" /> <!-- Generic project properties --> <property name="project.fullname" value="Cactus"/> <property name="project.version" value="1.0-b1"/> <property name="project.name" value="commons-cactus"/> <!-- Miscellaneous settings --> <property name="year" value="2000-2001"/> <property name="debug" value="on"/> <property name="optimize" value="off"/> <property name="deprecation" value="off"/> <!-- ======================================================================== Set the properties related to the source tree ======================================================================== --> <!-- Source locations for the build --> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="etc.dir" value="${build.dir}/etc"/> <property name="src.java.share.dir" value="${src.dir}/framework/share"/> <property name="src.java.test.share.dir" value="${src.dir}/test/share"/> <property name="src.java.ant.dir" value="${src.dir}/ant"/> <property name="conf.dir" value="conf"/> <property name="doc.root.dir" value="docs"/> <property name="doc.dir" value="${doc.root.dir}/framework"/> <property name="xdoc.dir" value="${doc.dir}/xdocs"/> <property name="skin.dir" value="${doc.dir}/skins"/> <property name="web.dir" value="web"/> <!-- Source locations for the Cactus sample application --> <property name="sample.src.dir" value="${src.dir}/sample"/> <property name="sample.build.dir" value="${conf.dir}/sample/build"/> <property name="sample.etc.dir" value="${sample.build.dir}/etc"/> <property name="sample.conf.dir" value="${conf.dir}/sample/conf"/> <property name="sample.web.dir" value="${web.dir}/sample"/> <property name="sample.doc.dir" value="${doc.root.dir}/sample"/> <!-- ======================================================================== Set the properties related to the build area ======================================================================== --> <!-- Destination locations for the build (relative to the basedir as specified in the basedir attribute of the project tag) --> <property name="out.root.dir" value="out"/> <property name="out.site.dir" value="${out.root.dir}/doc"/> <property name="out.classes.ant.dir" value="${out.root.dir}/classes"/> <property name="out.src.ant.dir" value="${out.root.dir}/src"/> <property name="out.conf.ant.dir" value="${out.root.dir}/conf"/> <!-- ======================================================================== Default values for properties not defined in build.properties ======================================================================== --> <property name="dist.dir" value="${out.root.dir}/dist"/> <!-- ======================================================================== Short names of deliverables ======================================================================== --> <!-- The Cactus jar containing custom Ant tasks and helper classes --> <property name="jar.ant.name" value="${project.name}-ant"/> <!-- The full sources of Cactus in a zip file --> <property name="src.name" value="${project.name}-src"/> <!-- The Cactus web site in a gzip file (without the Javadoc but with a link pointing to javadoc : <htdocs>/servletXX/index.html --> <property name="site.name" value="${project.name}-website"/> <!-- ======================================================================== Full names of deliverables ======================================================================== --> <!-- The Cactus jar containing custom Ant tasks and helper classes --> <property name="final.jar.ant.name" value="${out.root.dir}/${jar.ant.name}.jar"/> <!-- The Cactus web site in a gzip file (without the Javadoc but with a link pointing to javadoc : <htdocs>/servletXX/index.html --> <property name="final.site.name" value="${out.root.dir}/${site.name}"/> <!-- ======================================================================== Useful file patterns for targets ======================================================================== --> <!-- All source files of the projet. These source files will be copied to the destination source directory in the prepare task --> <patternset id="all.src.files"> <!-- All java files --> <include name="**/*.java"/> <!-- All doc files --> <include name="**/package.html"/> <include name="**/overview.html"/> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- ======================================================================== Initialize the build. Must be called by all targets ======================================================================== --> <target name="check_servlet22" unless="servlet22.jar.present"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'servlet22.jar' property has not been set."/> <echo message=" No output will be generated for Servlet API 2.2"/> <echo message="*********************************************************"/> <echo message=""/> </target> <target name="check_servlet23" unless="servlet23.jar.present"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'servlet23.jar' property has not been set."/> <echo message=" No output will be generated for Servlet API 2.3"/> <echo message="*********************************************************"/> <echo message=""/> </target> <target name="init"> <tstamp/> <echo message="--------- ${project.fullname} ${project.version} ---------"/> <echo message=""/> <echo message="java.class.path = ${java.class.path}"/> <echo message=""/> <echo message="java.home = ${java.home}"/> <echo message="user.home = ${user.home}"/> <echo message="ant.home = ${ant.home}"/> <echo message=""/> <!-- Full names of distributables. They are defined here because the properties need to have a valid ${DSTAMP} property set and the tstamp task need to be located in a target --> <!-- The Cactus jar containing custom Ant tasks and helper classes --> <property name="dist.jar.ant.name" value="${dist.dir}/${jar.ant.name}-${DSTAMP}.jar"/> <!-- The full sources of Cactus in a zip file --> <property name="dist.src.name" value="${dist.dir}/${src.name}-${DSTAMP}.zip"/> <!-- The Cactus web site in a gzip file (without the Javadoc but with a link pointing to javadoc : <htdocs>/servletXX/index.html --> <property name="dist.site.name" value="${dist.dir}/${site.name}"/> <!-- Filters --> <filter token="version" value="${project.version}"/> <filter token="year" value="${year}"/> <filter token="today" value="${TODAY}"/> <!-- Check availabilities --> <available file="${servlet22.jar}" property="servlet22.jar.present"/> <available file="${servlet23.jar}" property="servlet23.jar.present"/> <!-- Emit warning if need properties have not been set --> <antcall target="check_servlet22"/> <antcall target="check_servlet23"/> </target> <!-- ======================================================================== Help on usage. List available targets ======================================================================== --> <target name="usage" depends="init"> <echo message=""/> <echo message="${project.fullname} build file"/> <echo message="------------------------------------------------------"/> <echo message=""/> <echo message=" Available targets are :"/> <echo message=""/> <echo message=" jar --> generates the jar file (default)"/> <echo message=" doc --> generates the docs (javadoc, ...)"/> <echo message=" site --> generate the web site"/> <echo message=" sample --> generate the sample application"/> <echo message=" tests-unit --> run the unit tests"/> <echo message=" tests-functional --> run the functional tests"/> <echo message=" tests --> run both the unit and functional tests"/> <echo message=" clean --> cleans up the build directory"/> <echo message=" all --> do it all at once (clean, jar, sample"/> <echo message=" source, doc, site, tests, dist)"/> <echo message=" dist --> version all distributables and copies"/> <echo message=" them to the dist.dir directory"/> <echo message=""/> </target> <!-- ======================================================================== Create the runtime jar file ======================================================================== --> <target name="jar.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="jar"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="jar.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="jar"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="jar" depends="jar.22,jar.23"> <!-- Copy source files to apply tokens --> <mkdir dir="${out.src.ant.dir}"/> <mkdir dir="${out.classes.ant.dir}"/> <mkdir dir="${out.conf.ant.dir}"/> <copy todir="${out.src.ant.dir}" filtering="on"> <fileset dir="${src.java.ant.dir}"> <patternset refid="all.src.files"/> </fileset> </copy> <!-- Compile the files --> <javac srcdir="${out.src.ant.dir}" destdir="${out.classes.ant.dir}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> <classpath> <pathelement path="${java.class.path}"/> </classpath> </javac> <!-- Copy the manifest in order to replace the version token filter --> <copy tofile="${out.conf.ant.dir}/manifest" file="${conf.dir}/manifest-ant"/> <jar jarfile="${final.jar.ant.name}" basedir="${out.classes.ant.dir}" manifest="${out.conf.ant.dir}/manifest"/> </target> <!-- ======================================================================== Generate the full documentation for a given Servlet API, i.e. web site + javadoc + README ======================================================================== --> <target name="doc.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="doc"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="doc.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="doc"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="doc" depends="doc.22,doc.23"> </target> <!-- ======================================================================== Generate the web site ======================================================================== --> <target name="prepare-site" depends="init"> <mkdir dir="${out.site.dir}"/> <mkdir dir="${out.site.dir}/images"/> <!-- Copy site-book.xml to book.xml for defining the web site content and replacing token filters (year) --> <delete file="${xdoc.dir}/book.xml"/> <copy file="${xdoc.dir}/site-book.xml" tofile="${xdoc.dir}/book.xml" filtering="on"/> <!-- Copy the version.txt file --> <copy file="${conf.dir}/version.txt" tofile="${out.site.dir}/version.txt" filtering="on"/> <!-- Copy the images --> <copy todir="${out.site.dir}/images"> <fileset dir="${xdoc.dir}/images"/> </copy> <!-- Note that we do not copy the javadoc to the web site. This is because the web site need to evolve independently of the javadoc for a given version of Cactus. In other words, the javadoc on the web site must not change until a new release of Cactus is out --> </target> <!-- Generate the web site --> <target name="site" depends="prepare-site"> <stylebook book="${xdoc.dir}/book.xml" skinDirectory="${skin.dir}/jakarta.apache.org" targetDirectory="${out.site.dir}"> <classpath> <pathelement path="${java.class.path}"/> </classpath> </stylebook> <!-- Create the gzipped web site --> <tar tarfile="${final.site.name}-${DSTAMP}.tar" basedir="${out.site.dir}"/> <gzip zipfile="${final.site.name}-${DSTAMP}.tar.gz" src="${final.site.name}-${DSTAMP}.tar"/> <delete file="${final.site.name}-${DSTAMP}.tar"/> </target> <!-- ======================================================================== Generate the sample application directory structure and zip file. This sample application will be used to exercise Cactus functional tests. And of course, it serves as a sample on how to use Cactus ======================================================================== --> <target name="sample.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="sample"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="sample.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="sample"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="sample" depends="jar,sample.22,sample.23"> </target> <!-- ======================================================================== Remove all build generated files ======================================================================== --> <target name="clean" depends="init"> <delete> <fileset dir="."> <include name="**/*.bak"/> <include name="${xdoc.dir}/book.xml"/> </fileset> </delete> <!-- Deletes all files ending with '~' --> <delete> <fileset dir="." includes="**/*~" defaultexcludes="no"/> </delete> <!-- Remove the out directory --> <delete dir="${out.root.dir}"/> <!-- Delete log files and version.txt --> <delete> <fileset dir="."> <include name="**/*.log"/> <include name="version.txt"/> </fileset> </delete> </target> <!-- ======================================================================== Run the unit tests. Only run the tests that do not need a servlet engine. For the other tests needing a servlet engine, they are part of the sample application and will be exercised there ======================================================================== --> <target name="tests-unit.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="tests-unit"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="tests-unit.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="tests-unit"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="tests-unit" depends="tests-unit.22,tests-unit.23"> </target> <!-- ======================================================================== Run the functional tests ======================================================================== --> <target name="tests-functional.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="tests-functional22"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="tests-functional.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="tests-functional23"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="tests-functional" depends="sample,tests-functional.22,tests-functional.23"> </target> <!-- ======================================================================== Run both the unit and functional tests ======================================================================== --> <target name="tests" depends="tests-unit,tests-functional"> </target> <!-- ======================================================================== Build all distributables and copies them to the dist.dir directory ======================================================================== --> <target name="dist.22" depends="init" if="servlet22.jar.present"> <ant antfile="build/build-servletapi.xml" target="dist"> <property name="servlet.api" value="22"/> <property name="servlet.jar" value="${servlet22.jar}"/> </ant> </target> <target name="dist.23" depends="init" if="servlet23.jar.present"> <ant antfile="build/build-servletapi.xml" target="dist"> <property name="servlet.api" value="23"/> <property name="servlet.jar" value="${servlet23.jar}"/> </ant> </target> <target name="dist" depends="clean,jar,sample,doc,site,dist.22,dist.23"> <mkdir dir="${dist.dir}"/> <!-- Package the sources in the distribution --> <zip zipfile="${dist.src.name}"> <zipfileset dir="." prefix="${project.name}-${DSTAMP}"> <exclude name="${out.root.dir}/**"/> <exclude name="**/build.properties"/> <exclude name="**/*.log"/> <exclude name="**/*.bak"/> <exclude name="**/*.class"/> </zipfileset> </zip> </target> <!-- ======================================================================== Do it all ======================================================================== --> <target name="all" depends="clean,jar,sample,doc,site,tests,dist"> </target> </project> 1.1 jakarta-commons/cactus/conf/manifest Index: manifest =================================================================== Manifest-Version: 1.0 Created-By: Ant Name: cactus/ Specification-Title: Cactus Specification-Vendor: Apache Software Foundation Implementation-Vendor: Apache Software Foundation Specification-Version: @version@ Implementation-Version: @version@ Implementation-Title: cactus 1.1 jakarta-commons/cactus/conf/manifest-ant Index: manifest-ant =================================================================== Manifest-Version: 1.0 Created-By: Ant Name: cactus/ant/ Specification-Title: Custom Cactus tasks for Ant Specification-Vendor: Apache Software Foundation Implementation-Vendor: Apache Software Foundation Specification-Version: @version@ Implementation-Version: @version@ Implementation-Title: cactus-ant 1.1 jakarta-commons/cactus/conf/version.txt Index: version.txt =================================================================== Version @version@ generated on @today@ 1.1 jakarta-commons/cactus/conf/sample/build/build.xml Index: build.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE project [ <!ENTITY build-tests SYSTEM "file:./build-tests.xml"> ]> <!-- ============================================================================= Build file for the Cactus Sample application. This is a sample build file that demonstrates how to integrate Cactus unit testing with Ant in order to automate the running of tests. The following properties need to be set in a ./build.properties, ${user.home}/build.properties, a higher level build file, on the command line, ... : servlet.jar [REQUIRED] The path to the Servlet API jar cactus.jar [REQUIRED] The path to the Cactus jar file junit.jar [REQUIRED] The path to the JUnit jar file cactus.ant.jar [REQUIRED] The path to the Cactus custom Ant tasks jar file Additionally and depending on the servlet engines whith which you wish to run your tests, you'll need to set the following properties : resin.home.12 [OPTIONAL] Resin 1.2 home directory (required for the tests_resin_12 target only) resin.home.13 [OPTIONAL] Resin 1.3 home directory (required for the tests_resin_13 target only) tomcat.home.32 [OPTIONAL] Tomcat 3.2 home directory (required for the tests_tomcat_32 target only) tomcat.home.40 [OPTIONAL] Tomcat 4.0 home directory (required for the tests_tomcat_40 target only) weblogic.home.51 [OPTIONAL] WebLogic 5.1 home directory (required for the tests_weblogic_51 target only) This script should be started with the following command line : ant <target> Run "ant usage" to get a list of available targets. The default target is "war" ============================================================================= --> <project name="Cactus Sample" default="war" basedir=".."> <!-- Give user a chance to override without editing this file (and without typing -D each time it compiles it) --> <property file="build/build.properties" /> <property file="${user.home}/build.properties" /> <!-- Generic project properties --> <property name="project.fullname" value="Cactus Sample"/> <property name="project.version" value="@version@"/> <property name="project.name" value="commons-cactus-sample"/> <!-- Miscellaneous settings --> <property name="year" value="@year@"/> <property name="debug" value="on"/> <property name="optimize" value="off"/> <property name="deprecation" value="off"/> <!-- ======================================================================== Set the properties related to the source tree ======================================================================== --> <!-- Source locations for the build --> <property name="src.dir" value="src"/> <property name="src.java.dir" value="${src.dir}/share"/> <property name="src.java.servlet.dir" value="${src.dir}[EMAIL PROTECTED]@"/> <property name="build.dir" value="build"/> <property name="etc.dir" value="${build.dir}/etc"/> <property name="lib.dir" value="lib"/> <property name="conf.dir" value="conf"/> <property name="conf.test.dir" value="conf/test"/> <property name="web.dir" value="web"/> <!-- ======================================================================== Set the properties related to the build area ======================================================================== --> <!-- Destination locations for the build (relative to the basedir as --> <!-- specified in the basedir attribute of the project tag) --> <property name="out.dir" value="out"/> <property name="out.dist.dir" value="${out.dir}/dist"/> <property name="out.lib.dir" value="${out.dir}/lib"/> <property name="out.test.dir" value="${out.dir}/test"/> <property name="out.src.dir" value="${out.dir}/src"/> <property name="out.classes.dir" value="${out.dir}/classes"/> <property name="out.doc.dir" value="${out.dir}/doc"/> <property name="out.javadoc.dir" value="${out.doc.dir}/javadoc"/> <property name="out.conf.dir" value="${out.dir}/conf"/> <!-- Names of deliverables --> <!-- The Cactus Sample war file. This is the file that should be used at runtime by end users (it excludes the test classes) --> <property name="final.war.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.war"/> <!-- The full sources of Cactus Sample in a zip file --> <property name="final.src.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.zip"/> <!-- The Cactus Sample documentation in a zip : javadoc --> <property name="final.doc.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.zip"/> <!-- ======================================================================== Useful file patterns for targets ======================================================================== --> <!-- All source files of the projet. These source files will be copied to the destination source directory in the prepare task --> <patternset id="all.src.files"> <!-- All java files --> <include name="**/*.java"/> <!-- All doc files --> <include name="**/package.html"/> <include name="**/overview.html"/> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- All non java files in the src directory --> <patternset id="all.nonjava.files"> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- ======================================================================== Initialize the build. Must be called by all targets ======================================================================== --> <target name="init"> <!-- So that we can use the ${TSTAMP}, ${DSTAMP}, ... time stamps in targets, if need be --> <tstamp/> <echo message="--------- ${project.fullname} ${project.version} ---------"/> <echo message=""/> <echo message="java.class.path = ${java.class.path}"/> <echo message=""/> <echo message="java.home = ${java.home}"/> <echo message="user.home = ${user.home}"/> <echo message=""/> <echo message="basedir = ${basedir}"/> <echo message=""/> <echo message="servlet.jar = ${servlet.jar}"/> <echo message="cactus.jar = ${cactus.jar}"/> <echo message="junit.jar = ${junit.jar}"/> <echo message="cactus.ant.jar = ${cactus.ant.jar}"/> <!-- Filters --> <filter token="version" value="${project.version}"/> <filter token="year" value="${year}"/> <!-- Initialize custom Ant task needed for running the server tests --> <taskdef name="runservertests" classname="org.apache.commons.cactus.ant.RunServerTestsTask"> <classpath> <pathelement location="${cactus.ant.jar}"/> <pathelement path="${java.class.path}"/> </classpath> </taskdef> </target> <!-- ======================================================================== Prepare the output directory by copying the source files into it ======================================================================== --> <target name="prepare" depends="init"> <mkdir dir="${out.src.dir}"/> <!-- Copy all source files to destination dir. Apply the filters in order to replace the tokens for the copyright year and the version --> <copy todir="${out.src.dir}" filtering="on"> <fileset dir="${src.java.dir}"> <patternset refid="all.src.files"/> </fileset> <fileset dir="${src.java.servlet.dir}"> <patternset refid="all.src.files"/> </fileset> </copy> </target> <!-- ======================================================================== Compiles the source directory ======================================================================== --> <!-- Preparation target for the compile target --> <target name="prepare-compile" depends="prepare"> <mkdir dir="${out.classes.dir}"/> </target> <!-- Run the java compilation --> <target name="compile" depends="prepare-compile"> <javac srcdir="${out.src.dir}" destdir="${out.classes.dir}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> <!-- Exclude all files that are not .java source files --> <!-- All doc files --> <exclude name="**/package.html"/> <exclude name="**/overview.html"/> <!-- All conf files (including test files) --> <exclude name="**/*.txt"/> <exclude name="**/*.xml"/> <exclude name="**/*.properties"/> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> </classpath> </javac> <!-- Copies non java files that need to be in the classes directory --> <copy todir="${out.classes.dir}"> <fileset dir="${src.java.dir}"> <patternset refid="all.nonjava.files"/> </fileset> <fileset dir="${conf.test.dir}"> <include name="cactus.properties"/> </fileset> </copy> </target> <!-- ======================================================================== Create the runtime war file ======================================================================== --> <!-- Preparation target for the war target --> <target name="prepare-war" depends="compile"> <mkdir dir="${out.conf.dir}"/> <!-- Copy the manifest in order to replace the version token filter --> <copy todir="${out.conf.dir}" filtering="on"> <fileset dir="${conf.dir}" > <include name="manifest"/> </fileset> </copy> </target> <!-- Generate the war file --> <target name="war" depends="prepare-war"> <war warfile="${final.war.name}" webxml="${conf.dir}/web.xml" manifest="${out.conf.dir}/manifest"> <classes dir="${out.classes.dir}"> <!-- Do not include test files in the runtime jar --> <exclude name="**/Test*.*"/> <exclude name="**/test*.*"/> <!-- Also exclude the test cactus.properties file --> <exclude name="cactus.properties"/> </classes> <fileset dir="${web.dir}"> <exclude name="test/**"/> </fileset> </war> </target> <!-- ======================================================================== Generates source zip of the project ======================================================================== --> <target name="source" depends="prepare"> <zip zipfile="${final.src.name}" basedir="."> <exclude name="${out.dir}/**"/> <exclude name="**/*.log"/> <exclude name="**/*.bak"/> <exclude name="**/*.class"/> <exclude name="${build.dir}/build.properties"/> </zip> </target> <!-- ======================================================================== Generate the javadoc ======================================================================== --> <!-- Preparation target for the javadoc target --> <target name="prepare-javadoc" depends="prepare"> <mkdir dir="${out.javadoc.dir}"/> </target> <!-- Generate the javadoc for the current Servlet API --> <target name="javadoc" depends="prepare-javadoc"> <javadoc sourcepath="${out.src.dir}" packagenames="org.apache.commons.cactus.sample.*" destdir="${out.javadoc.dir}" author="true" public="true" version="true" use="true" windowtitle="${project.fullname} ${project.version} for Servlet @servlet.api@ API" doctitle="${project.fullname} ${project.version} for Servlet @servlet.api@ API" bottom="Copyright &copy; ${year} Apache Software Foundation. All Rights Reserved."> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> </classpath> </javadoc> </target> <!-- ======================================================================== Generate the full documentation ======================================================================== --> <!-- Preparation target for the doc target --> <target name="prepare-doc" depends="javadoc"> <mkdir dir="${out.doc.dir}"/> </target> <!-- Generate the documentation --> <target name="doc" depends="prepare-doc"> <!-- Create the zipped documentation --> <zip zipfile="${final.doc.name}" basedir="${out.doc.dir}"/> </target> <!-- ======================================================================== Remove all build generated files ======================================================================== --> <target name="clean" depends="init"> <!-- Deletes all files ending with '~' --> <delete> <fileset dir="." includes="**/*~" defaultexcludes="no"/> </delete> <!-- Remove the out directory --> <delete dir="${out.dir}"/> <!-- Delete log files --> <delete> <fileset dir="."> <include name="**/*.log"/> </fileset> </delete> </target> <!-- ======================================================================== Run the client JUnit test cases. This target should not be called directly. It must be called by a test_XXX target (where XXX is the name of the server - see included xml file for different servers) ======================================================================== --> <target name="tests"> <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes"> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> <pathelement location="${out.classes.dir}"/> </classpath> <formatter type="plain" usefile="false"/> <!-- Functional tests --> <test name="org.apache.commons.cactus.sample.TestSampleServlet"/> <test name="org.apache.commons.cactus.sample.TestSampleServletConfig"/> <!-- Cactus unit tests requiring servlet engine --> <test name="org.apache.commons.cactus.sample.unit.TestServletTestCase1"/> <test name="org.apache.commons.cactus.sample.unit.TestServletTestCase2"/> <test name="org.apache.commons.cactus.sample.unit.TestServletTestCase3"/> <test name="org.apache.commons.cactus.sample.unit.TestServletTestCase4"/> <test name="org.apache.commons.cactus.sample.unit.TestServletTestCaseSpecific"/> <test name="org.apache.commons.cactus.sample.unit.TestJspTestCase"/> </junit> </target> <!-- ======================================================================== Create a test war file that includes the sample application unit tests ======================================================================== --> <target name="testwar" depends="compile"> <!-- Gather libraries --> <copy tofile="${out.lib.dir}/junit.jar" file="${junit.jar}"/> <copy tofile="${out.lib.dir}[EMAIL PROTECTED]@.jar" file="${cactus.jar}"/> <!-- Make sure the directory for the war exist --> <mkdir dir="${out.test.dir}"/> <!-- Create the war file --> <war warfile="${out.test.dir}/test.war" webxml="${conf.test.dir}/web.xml"> <classes dir="${out.classes.dir}"> <exclude name="cactus.properties"/> </classes> <!-- We need to copy the Cactus and JUnit jars in the war. This is because if we just put these jars in the global classpath for the Servlet engine, the Cactus jar might not be able to load the test case class as it loadable only by the war classloader --> <lib dir="${out.lib.dir}"> <include name="junit.jar"/> <include name="[EMAIL PROTECTED]@.jar"/> </lib> <fileset dir="${web.dir}"/> </war> </target> <!-- ======================================================================== Do it all ! (clean, war, source, doc) ======================================================================== --> <target name="all" depends="clean,war,source,doc"/> <!-- ======================================================================== Include the usage target and the test targets for the different servlet engine ======================================================================== --> &build-tests; </project> 1.1 jakarta-commons/cactus/conf/sample/build/servlet22/build-tests.xml Index: build-tests.xml =================================================================== <!-- ======================================================================== Help on usage. List available targets ======================================================================== --> <target name="usage" depends="init"> <echo message=""/> <echo message="${project.fullname} build file"/> <echo message="------------------------------------------------------"/> <echo message=""/> <echo message=" Available targets are :"/> <echo message=""/> <echo message=" war --> generates the war file (default)"/> <echo message=" clean --> cleans up the build directory"/> <echo message=" source --> generates source zip of the project"/> <echo message=" doc --> generates the docs (javadoc, ...)"/> <echo message=" all --> do it all at once"/> <echo message=" (clean, war, source, doc)"/> <echo message=""/> <echo message=" Targets for running the tests for Servlet API 2.2 :"/> <echo message=""/> <echo message=" tests_all --> run tests on all servlet engines"/> <echo message=" tests_resin_12 --> run tests for Resin 1.2"/> <echo message=" tests_tomcat_32 --> run tests for Tomcat 3.2"/> <echo message=" tests_weblogic_51 --> run tests for WebLogic 5.1"/> <echo message=" tests_orion_14 --> run tests for Orion 1.4"/> <echo message=""/> </target> <!-- ======================================================================== Run all Cactus tests for Servlet API 2.2 ======================================================================== --> <target name="tests_all" depends="tests_resin_12,tests_tomcat_32,tests_orion_14,tests_weblogic_51"> </target> <!-- ======================================================================== Run Resin 1.2 tests ======================================================================== --> <target name="tests_resin_12" depends="prepare_tests_resin_12" if="resin.home.12"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_resin_12" stopTarget="stop_resin_12" testTarget="tests"/> </target> <!-- ======================================================================== Start Resin 1.2 ======================================================================== --> <target name="start_resin_12"> <java classname="org.apache.commons.cactus.ant.ResinRun" fork="yes"> <arg value="-start"/> <arg value="-conf"/> <arg value="resin.conf"/> <!-- Needed so that Resin use the resin.home.12 variable as it's root directory for resolving file paths --> <jvmarg value="-Dresin.home=${out.resin12.dir}"/> <classpath> <pathelement location="${cactus.ant.jar}"/> <fileset dir="${resin.home.12}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Stop Resin 1.2 ======================================================================== --> <target name="stop_resin_12"> <java classname="org.apache.commons.cactus.ant.ResinRun" fork="yes"> <arg value="-stop"/> <classpath> <pathelement location="${cactus.ant.jar}"/> <fileset dir="${resin.home.12}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_resin_12" depends="testwar" unless="resin.home.12"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'resin.home.12' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_resin_12" depends="check_tests_resin_12" if="resin.home.12"> <echo message="resin.home.12 = ${resin.home.12}"/> <property name="out.resin12.dir" value="${out.test.dir}/resin12"/> <property name="conf.resin12.dir" value="${conf.test.dir}/resin12"/> <mkdir dir="${out.resin12.dir}"/> <!-- Copy resin configuration files --> <copy file="${conf.resin12.dir}/resin.conf" tofile="${out.resin12.dir}/resin.conf"/> <!-- Create the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.resin12.dir}/test.war"/> </target> <!-- ======================================================================== Run Tomcat 3.2 tests ======================================================================== --> <target name="tests_tomcat_32" depends="prepare_tests_tomcat_32" if="tomcat.home.32"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_tomcat_32" stopTarget="stop_tomcat_32" testTarget="tests"/> </target> <!-- ======================================================================== Start Tomcat 3.2 ======================================================================== --> <target name="start_tomcat_32"> <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> <arg value="-config"/> <arg value="${out.tomcat32.dir}/conf/server.xml"/> <classpath> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home.32}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Stop Tomcat 3.2 ======================================================================== --> <target name="stop_tomcat_32"> <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> <jvmarg value="-Dtomcat.home=${tomcat.home.32}"/> <arg value="-stop"/> <classpath> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home.32}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_tomcat_32" depends="testwar" unless="tomcat.home.32"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'tomcat.home.32' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_tomcat_32" depends="check_tests_tomcat_32" if="tomcat.home.32"> <echo message="tomcat.home.32 = ${tomcat.home.32}"/> <property name="out.tomcat32.dir" value="${out.test.dir}/tomcat32"/> <property name="conf.tomcat32.dir" value="${conf.test.dir}/tomcat32"/> <filter token="out.tomcat32.dir" value="${out.tomcat32.dir}"/> <!-- Create work and conf directories and copy configuration files --> <mkdir dir="${out.tomcat32.dir}/conf"/> <mkdir dir="${out.tomcat32.dir}/work"/> <mkdir dir="${out.tomcat32.dir}/webapps"/> <!-- Delete some config file so that they will be copied every time --> <delete file="${out.tomcat32.dir}/conf/testserver.xml"/> <!-- Copy the default tomcat web.xml to our test conf/ directory. This is needed otherwise tomcat does not start --> <copy file="${tomcat.home.32}/conf/web.xml" tofile="${out.tomcat32.dir}/conf/web.xml"/> <copy file="${conf.tomcat32.dir}/server.xml" tofile="${out.tomcat32.dir}/conf/server.xml" filtering="on"/> <!-- Copy the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.tomcat32.dir}/webapps/test.war"/> </target> <!-- ======================================================================== Run Orion 1.4 tests ======================================================================== --> <target name="tests_orion_14" depends="prepare_tests_orion_14" if="orion.home.14"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_orion_14" stopTarget="stop_orion_14" testTarget="tests"/> </target> <!-- ======================================================================== Start Orion 1.4 ======================================================================== --> <target name="start_orion_14"> <java classname="com.evermind.server.ApplicationServer" fork="yes"> <arg value="-config"/> <arg value="${out.orion14.dir}/conf/server.xml"/> <classpath> <fileset dir="${orion.home.14}"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Stop Orion 1.4 ======================================================================== --> <target name="stop_orion_14"> <java classname="com.evermind.client.orion.OrionConsoleAdmin" fork="yes"> <arg value="ormi://localhost:23791/"/> <arg value="admin"/> <arg value="password"/> <arg value="-shutdown"/> <classpath> <fileset dir="${orion.home.14}"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_orion_14" depends="testwar" unless="orion.home.14"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'orion.home.14' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_orion_14" depends="check_tests_orion_14" if="orion.home.14"> <echo message="orion.home.14 = ${orion.home.14}"/> <property name="out.orion14.dir" value="${out.test.dir}/orion14"/> <property name="conf.orion14.dir" value="${conf.test.dir}/orion14"/> <!-- Create work and conf directories and copy configuration files --> <mkdir dir="${out.orion14.dir}"/> <mkdir dir="${out.orion14.dir}/conf"/> <copy file="${conf.orion14.dir}/server.xml" tofile="${out.orion14.dir}/conf/server.xml"/> <copy file="${conf.orion14.dir}/application.xml" tofile="${out.orion14.dir}/conf/application.xml"/> <copy file="${conf.orion14.dir}/default-web-site.xml" tofile="${out.orion14.dir}/conf/default-web-site.xml"/> <copy file="${conf.orion14.dir}/principals.xml" tofile="${out.orion14.dir}/conf/principals.xml"/> <copy file="${conf.orion14.dir}/rmi.xml" tofile="${out.orion14.dir}/conf/rmi.xml"/> <!-- Copy the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.orion14.dir}/test.war"/> </target> <!-- ======================================================================== Run WebLogic 5.1 tests ======================================================================== --> <target name="tests_weblogic_51" depends="prepare_tests_weblogic_51" if="weblogic.home.51"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_weblogic_51" stopTarget="stop_weblogic_51" testTarget="tests"/> </target> <!-- ======================================================================== Start WebLogic 5.1 ======================================================================== --> <target name="start_weblogic_51"> <java classname="weblogic.Server" fork="yes"> <classpath> <pathelement location="${weblogic.home.51}/lib/weblogic510sp8boot.jar"/> <pathelement location="${weblogic.home.51}/classes/boot"/> </classpath> <jvmarg value="-ms64m"/> <jvmarg value="-mx64m"/> <jvmarg value="-Dweblogic.class.path=${weblogic.home.51}/lib/weblogic510sp8.jar;${weblogic.home.51}/license;${weblogic.home.51}/classes;${weblogic.home.51}/lib/weblogicaux.jar"/> <jvmarg value="-Dweblogic.home=${out.weblogic51.dir}"/> <jvmarg value="-Dweblogic.system.home=${out.weblogic51.dir}"/> <jvmarg value="-Dweblogic.system.name=testinstance"/> <jvmarg value="-Djava.security.manager"/> <jvmarg value="-Djava.security.policy==${conf.weblogic51.dir}/weblogic.policy"/> </java> </target> <!-- ======================================================================== Stop WebLogic 5.1 ======================================================================== --> <target name="stop_weblogic_51"> <java classname="weblogic.Admin" fork="yes"> <classpath> <pathelement location="${weblogic.home.51}/lib/weblogic510sp8.jar"/> <pathelement location="${weblogic.home.51}/license"/> <pathelement location="${weblogic.home.51}/classes"/> <pathelement location="${weblogic.home.51}/lib/weblogicaux.jar"/> </classpath> <arg value="t3://localhost:8080"/> <arg value="SHUTDOWN"/> <arg value="system"/> <arg value="password"/> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_weblogic_51" depends="testwar" unless="weblogic.home.51"> <echo message=""/> <echo message="***********************************************************"/> <echo message="WARNING : The 'weblogic.home.51' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="***********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_weblogic_51" depends="check_tests_weblogic_51" if="weblogic.home.51"> <echo message="weblogic.home.51 = ${weblogic.home.51}"/> <property name="out.weblogic51.dir" value="${out.test.dir}/weblogic51"/> <property name="conf.weblogic51.dir" value="${conf.test.dir}/weblogic51"/> <filter token="out.wlinstance.dir" value="${out.weblogic51.dir}/testinstance"/> <mkdir dir="${out.weblogic51.dir}/testinstance"/> <!-- Delete some config file so that they will be copied every time --> <delete file="${out.weblogic51.dir}/weblogic.properties"/> <copy file="${conf.weblogic51.dir}/weblogic.properties" tofile="${out.weblogic51.dir}/weblogic.properties" filtering="on"/> <!-- Copy the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.weblogic51.dir}/testinstance/test.war"/> <!-- This is needed here because WebLogic 5.1 does not support automatic war deployment (except with latest Service Packs and even when it does there are issues with support files --> <unwar src="${out.weblogic51.dir}/testinstance/test.war" dest="${out.weblogic51.dir}/testinstance/test"/> </target> 1.1 jakarta-commons/cactus/conf/sample/build/servlet22/build.properties.sample Index: build.properties.sample =================================================================== # Properties related to the user's environment. This file should be provided # for building the Cactus Sample or the properties need to be specified on # the command line when starting Ant with the -D switch servlet.jar = f:/applis/apache-dev/jakarta-servletapi/lib/servlet.jar cactus.jar = ../lib/commons-cactus.jar cactus.ant.jar = ../lib/commons-cactus-ant.jar junit.jar=f:/applis/jakarta-ant-1.4alpha/lib/junit.jar # Servlet engine locations for the tests # Note: If you don't want to run the test on a given servlet engine, just # comment it's home property. For example, if you don't want to run the # tests on the Resin 1.2, comment the "resin.home.12" property. resin.home.12 = f:/applis/resin-1.2.s010208 tomcat.home.32 = f:/applis/jakarta-tomcat-3.2.1 orion.home.14 = f:/applis/orion-1.4.5 weblogic.home.51 = e:/weblogic 1.1 jakarta-commons/cactus/conf/sample/build/servlet23/build-tests.xml Index: build-tests.xml =================================================================== <!-- ======================================================================== Help on usage. List available targets ======================================================================== --> <target name="usage" depends="init"> <echo message=""/> <echo message="${project.fullname} build file"/> <echo message="------------------------------------------------------"/> <echo message=""/> <echo message=" Available targets are :"/> <echo message=""/> <echo message=" war --> generates the war file (default)"/> <echo message=" clean --> cleans up the build directory"/> <echo message=" source --> generates source zip of the project"/> <echo message=" doc --> generates the docs (javadoc, ...)"/> <echo message=" all --> do it all at once"/> <echo message=" (clean, war, source, doc)"/> <echo message=""/> <echo message=" Targets for running the tests for Servlet API 2.3 :"/> <echo message=""/> <echo message=" tests_all --> run tests on all servlet engines"/> <echo message=" tests_resin_13 --> run tests for Resin 1.3"/> <echo message=" tests_tomcat_40 --> run tests for Tomcat 4.0"/> <echo message=""/> </target> <!-- ======================================================================== Run all Cactus tests for Servlet API 2.3 ======================================================================== --> <target name="tests_all" depends="tests_resin_13,tests_tomcat_40"> </target> <!-- ======================================================================== Run Resin 1.3 tests ======================================================================== --> <target name="tests_resin_13" depends="prepare_tests_resin_13" if="resin.home.13"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_resin_13" stopTarget="stop_resin_13" testTarget="tests"/> </target> <!-- ======================================================================== Start Resin 1.3 ======================================================================== --> <target name="start_resin_13"> <java classname="org.apache.commons.cactus.ant.ResinRun" fork="yes"> <arg value="-start"/> <arg value="-conf"/> <arg value="resin.conf"/> <!-- Needed so that Resin use the resin.home.13 variable as it's root directory for resolving file paths --> <jvmarg value="-Dresin.home=${out.resin13.dir}"/> <classpath> <pathelement location="${cactus.ant.jar}"/> <fileset dir="${resin.home.13}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Stop Resin 1.3 ======================================================================== --> <target name="stop_resin_13"> <java classname="org.apache.commons.cactus.ant.ResinRun" fork="yes"> <arg value="-stop"/> <classpath> <pathelement location="${cactus.ant.jar}"/> <fileset dir="${resin.home.13}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_resin_13" depends="testwar" unless="resin.home.13"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'resin.home.13' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_resin_13" depends="check_tests_resin_13" if="resin.home.13"> <echo message="resin.home.13 = ${resin.home.13}"/> <property name="out.resin13.dir" value="${out.test.dir}/resin13"/> <property name="conf.resin13.dir" value="${conf.test.dir}/resin13"/> <mkdir dir="${out.resin13.dir}"/> <!-- Copy resin configuration files --> <copy file="${conf.resin13.dir}/resin.conf" tofile="${out.resin13.dir}/resin.conf"/> <!-- Create the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.resin13.dir}/test.war"/> </target> <!-- ======================================================================== Run Tomcat 4.0 tests ======================================================================== --> <target name="tests_tomcat_40" depends="prepare_tests_tomcat_40" if="tomcat.home.40"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_tomcat_40" stopTarget="stop_tomcat_40" testTarget="tests"/> </target> <!-- ======================================================================== Start Tomcat 4.0 ======================================================================== --> <target name="start_tomcat_40"> <java classname="org.apache.catalina.startup.Bootstrap" fork="yes"> <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/> <arg value="-config"/> <arg value="${out.tomcat40.full.dir}/conf/server.xml"/> <arg value="start"/> <classpath> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home.40}"> <include name="bin/bootstrap.jar"/> <include name="server/catalina.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Stop Tomcat 4.0 ======================================================================== --> <target name="stop_tomcat_40"> <java classname="org.apache.catalina.startup.Bootstrap" fork="yes"> <jvmarg value="-Dcatalina.home=${tomcat.home.40}"/> <arg value="stop"/> <classpath> <fileset dir="${tomcat.home.40}"> <include name="bin/bootstrap.jar"/> <include name="server/catalina.jar"/> </fileset> </classpath> </java> </target> <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_tomcat_40" depends="testwar" unless="tomcat.home.40"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'tomcat.home.40' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_tomcat_40" depends="check_tests_tomcat_40" if="tomcat.home.40"> <echo message="tomcat.home.40 = ${tomcat.home.40}"/> <property name="out.tomcat40.dir" value="${out.test.dir}/tomcat40"/> <property name="conf.tomcat40.dir" value="${conf.test.dir}/tomcat40"/> <property name="out.tomcat40.full.dir" value="${basedir}/${out.tomcat40.dir}"/> <filter token="out.tomcat40.full.dir" value="${out.tomcat40.full.dir}"/> <!-- Create work and conf directories and copy configuration files --> <mkdir dir="${out.tomcat40.dir}/conf"/> <mkdir dir="${out.tomcat40.dir}/work"/> <mkdir dir="${out.tomcat40.dir}/webapps"/> <!-- Delete some config file so that they will be copied every time --> <delete file="${out.tomcat40.dir}/conf/server.xml"/> <!-- Remove the auto deployed webapp so that it is redeployed every --> <!-- time. --> <delete dir="${out.tomcat40.dir}/webapps/test"/> <!-- Copy the default tomcat web.xml to our test conf/ directory. --> <!-- This is needed otherwise tomcat does not start. --> <copy file="${tomcat.home.40}/conf/web.xml" tofile="${out.tomcat40.dir}/conf/web.xml"/> <copy file="${conf.tomcat40.dir}/server.xml" tofile="${out.tomcat40.dir}/conf/server.xml" filtering="on"/> <!-- Copy the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.tomcat40.dir}/webapps/test.war"/> </target> 1.1 jakarta-commons/cactus/conf/sample/build/servlet23/build.properties.sample Index: build.properties.sample =================================================================== # Properties related to the user's environment. This file should be provided # for building the Cactus Sample or the properties need to be specified on # the command line when starting Ant with the -D switch servlet.jar = f:/applis/apache-dev/jakarta-servletapi/lib/servlet.jar cactus.jar = ../../cactus-23.jar cactus.ant.jar = ../../cactus-ant.jar junit.jar=f:/applis/jakarta-ant-1.4alpha/lib/junit.jar # Servlet engine locations for the tests # Note: If you don't want to run the test on a given servlet engine, just # comment it's home property. For example, if you don't want to run the # tests on the Resin 1.3, comment the "resin.home.13" property. resin.home.13 = f:/applis/resin-1.3.s010125 tomcat.home.40 = f:/applis/jakarta-tomcat-4.0-b1 1.1 jakarta-commons/cactus/conf/sample/conf/manifest Index: manifest =================================================================== Manifest-Version: 1.0 Created-By: Ant Name: cactus/sample Specification-Title: Cactus Sample Specification-Vendor: Apache Software Foundation Implementation-Vendor: Apache Software Foundation Specification-Version: @version@ Implementation-Version: @version@ Implementation-Title: cactus-sample 1.1 jakarta-commons/cactus/conf/sample/conf/web.xml Index: web.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"> <web-app> </web-app> 1.1 jakarta-commons/cactus/conf/sample/conf/test/cactus.properties Index: cactus.properties =================================================================== # Configuration file for Cactus. # Each project using Cactus need to have such a file put in the CLASSPATH # (Meaning the directory containgin this file should be in the CLASSPATH, not # the file itself of course ... :) ) # Defines the URLs that will be used by Cactus to call it's redirectors # (Servlet and JSP). You need to specify in these URLs the webapp context # that you use for your application. In the example below, the context is # "test". cactus.servletRedirectorURL = http://localhost:8080/test/ServletRedirector cactus.jspRedirectorURL = http://localhost:8080/test/JspRedirector 1.1 jakarta-commons/cactus/conf/sample/conf/test/web.xml Index: web.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"> <web-app> <servlet> <servlet-name>ServletRedirector</servlet-name> <servlet-class>org.apache.commons.cactus.server.ServletTestRedirector</servlet-class> <init-param> <param-name>param1</param-name> <param-value>value1 used for testing</param-value> </init-param> </servlet> <servlet> <servlet-name>JspRedirector</servlet-name> <jsp-file>/test/redirector.jsp</jsp-file> <init-param> <param-name>param1</param-name> <param-value>value1 used for testing</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ServletRedirector</servlet-name> <url-pattern>/ServletRedirector</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>JspRedirector</servlet-name> <url-pattern>/JspRedirector</url-pattern> </servlet-mapping> </web-app> 1.1 jakarta-commons/cactus/conf/sample/conf/test/orion14/application.xml Index: application.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE orion-application PUBLIC "-//Evermind//DTD J2EE Application runtime 1.2//EN" "http://www.orionserver.com/dtds/orion-application.dtd"> <orion-application> <web-module id="test" path="../test.war"/> <namespace-access> <read-access> <namespace-resource root=""> <security-role-mapping> <group name="administrators" /> </security-role-mapping> </namespace-resource> </read-access> <write-access> <namespace-resource root=""> <security-role-mapping> <group name="administrators" /> </security-role-mapping> </namespace-resource> </write-access> </namespace-access> </orion-application> 1.1 jakarta-commons/cactus/conf/sample/conf/test/orion14/default-web-site.xml Index: default-web-site.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE web-site PUBLIC "Orion Web-site" "http://www.orionserver.com/dtds/web-site.dtd"> <web-site host="[ALL]" port="8080" display-name="Default Orion WebSite"> <!-- The default web-app for this site, bound to the root --> <default-web-app application="default" name="test"/> <web-app application="default" name="test" root="/test" /> </web-site> 1.1 jakarta-commons/cactus/conf/sample/conf/test/orion14/principals.xml Index: principals.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE principals PUBLIC "//Evermind - Orion Principals//" "http://www.orionserver.com/dtds/principals.dtd"> <principals> <groups> <group name="administrators"> <description>administrators</description> <permission name="administration" /> <permission name="com.evermind.server.AdministrationPermission" /> </group> <group name="guests"> <description>guests</description> </group> <group name="users"> <description>users</description> <permission name="rmi:login" /> <permission name="com.evermind.server.rmi.RMIPermission" /> </group> </groups> <users> <user username="admin" password="password" deactivated="false"> <description>The default administrator</description> <group-membership group="administrators" /> <group-membership group="guests" /> <group-membership group="users" /> </user> </users> </principals> 1.1 jakarta-commons/cactus/conf/sample/conf/test/orion14/rmi.xml Index: rmi.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE rmi-server PUBLIC "Orion RMI-server" "http://www.orionserver.com/dtds/rmi-server.dtd"> <rmi-server port="23791"> </rmi-server> 1.1 jakarta-commons/cactus/conf/sample/conf/test/orion14/server.xml Index: server.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE application-server PUBLIC "Orion Application Server Config" "http://www.orionserver.com/dtds/application-server.dtd"> <application-server> <global-application name="default" path="./application.xml" /> <web-site path="./default-web-site.xml" /> <rmi-config path="./rmi.xml" /> <principals path="./principals.xml" /> </application-server> 1.1 jakarta-commons/cactus/conf/sample/conf/test/resin12/resin.conf Index: resin.conf =================================================================== <caucho.com> <http-server> <app-dir>.</app-dir> <http port='8080'/> <host id=''> <war-dir id='.'/> </host> </http-server> </caucho.com> 1.1 jakarta-commons/cactus/conf/sample/conf/test/resin13/resin.conf Index: resin.conf =================================================================== <caucho.com> <http-server> <app-dir>.</app-dir> <http port='8080'/> <host id=''> <war-dir id='.'/> </host> </http-server> </caucho.com> 1.1 jakarta-commons/cactus/conf/sample/conf/test/tomcat32/server.xml Index: server.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1"?> <Server> <ContextManager home="@out.tomcat32.dir@" debug="0" workDir="work" showDebugInfo="true" > <ContextInterceptor className="org.apache.tomcat.context.AutoSetup" /> <ContextInterceptor className="org.apache.tomcat.context.WebXmlReader" /> <ContextInterceptor className="org.apache.tomcat.context.LoaderInterceptor" /> <ContextInterceptor className="org.apache.tomcat.context.DefaultCMSetter" /> <ContextInterceptor className="org.apache.tomcat.context.WorkDirInterceptor" /> <RequestInterceptor className="org.apache.tomcat.request.SessionInterceptor" noCookies="false" /> <RequestInterceptor className="org.apache.tomcat.request.SimpleMapper1" debug="0" /> <RequestInterceptor className="org.apache.tomcat.request.InvokerInterceptor" debug="0" prefix="/servlet/" /> <RequestInterceptor className="org.apache.tomcat.request.StaticInterceptor" debug="0" suppress="false" /> <RequestInterceptor className="org.apache.tomcat.session.StandardSessionInterceptor" /> <RequestInterceptor className="org.apache.tomcat.request.AccessInterceptor" debug="0" /> <RequestInterceptor className="org.apache.tomcat.request.SimpleRealm" debug="0" /> <ContextInterceptor className="org.apache.tomcat.context.LoadOnStartupInterceptor" /> <Connector className="org.apache.tomcat.service.PoolTcpConnector"> <Parameter name="handler" value="org.apache.tomcat.service.http.HttpConnectionHandler"/> <Parameter name="port" value="8080"/> </Connector> <Connector className="org.apache.tomcat.service.PoolTcpConnector"> <Parameter name="handler" value="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"/> <Parameter name="port" value="8007"/> </Connector> <Context path="" docBase="" debug="0" /> </ContextManager> </Server> 1.1 jakarta-commons/cactus/conf/sample/conf/test/tomcat40/server.xml Index: server.xml =================================================================== <Server port="8005" shutdown="SHUTDOWN" debug="0"> <Service name="Tomcat-Standalone"> <Connector className="org.apache.catalina.connector.http.HttpConnector" port="8080" minProcessors="5" maxProcessors="75" acceptCount="10" debug="0"/> <Engine name="Standalone" defaultHost="localhost" debug="0"> <Realm className="org.apache.catalina.realm.MemoryRealm" /> <Host name="localhost" debug="0" appBase="@out.tomcat40.full.dir@/webapps"> </Host> </Engine> </Service> </Server> 1.1 jakarta-commons/cactus/conf/sample/conf/test/weblogic51/weblogic.policy Index: weblogic.policy =================================================================== grant { permission java.security.AllPermission; }; 1.1 jakarta-commons/cactus/conf/sample/conf/test/weblogic51/weblogic.properties Index: weblogic.properties =================================================================== weblogic.system.listenPort=8080 # Define the test webapp [EMAIL PROTECTED]@/test #------------------------------------------------------------------------------- # Properties below are needed to have a functionning servlet engine #------------------------------------------------------------------------------- # No access.log file generated weblogic.httpd.enableLogFile=true # this property need to exist but the password can be anything weblogic.password.system=password # some security stuff weblogic.allow.execute.weblogic.servlet=everyone 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/loader.xml Index: loader.xml =================================================================== <?xml version="1.0"?> <!-- CVS $Revision: 1.1 $ $Date: 2001/04/09 11:52:31 $ --> <loader> <processor name="xslt"> <parameter name="stylesheet" value="sbk:/style/stylesheets/book2project.xsl"/> </processor> </loader> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/add.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/fix.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/jakarta-logo.gif <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/logocactus.gif <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/note.gif <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/remove.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/resources/update.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/stylesheets/book2project.xsl Index: book2project.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- match the root book element --> <xsl:template match="book"> <project> <parameter name="copyright" value="{@copyright}"/> <resource source="sbk:/style/resources/logocactus.gif" target="images/logocactus.gif"/> <resource source="sbk:/style/resources/jakarta-logo.gif" target="images/jakarta-logo.gif"/> <resource source="sbk:/style/resources/update.jpg" target="images/update.jpg"/> <resource source="sbk:/style/resources/remove.jpg" target="images/remove.jpg"/> <resource source="sbk:/style/resources/add.jpg" target="images/add.jpg"/> <resource source="sbk:/style/resources/fix.jpg" target="images/fix.jpg"/> <resource source="sbk:/style/resources/note.gif" target="images/note.gif"/> <xsl:apply-templates/> </project> </xsl:template> <xsl:template match="menu-item"> <xsl:if test="not(@type) or ( @type!='external' )"> <create source="{@source}" target="{substring(@source,0,string-length(@source)-3)}.html" producer="parser" printer="html"> <xsl:if test="@type and ( @type!='hidden' and @type!='document' )"> <processor name="xslt"> <parameter name="stylesheet" value="sbk:/style/stylesheets/{@type}2document.xsl"/> </processor> </xsl:if> <processor name="xslt"> <parameter name="docid" value="{@source}"/> <parameter name="stylesheet" value="sbk:/style/stylesheets/document2html.xsl"/> </processor> </create> </xsl:if> </xsl:template> <xsl:template match="external"> </xsl:template> <xsl:template match="project"> </xsl:template> </xsl:stylesheet> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/stylesheets/changes2document.xsl Index: changes2document.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="changes"> <document> <header> <title><xsl:value-of select="@title"/></title> </header> <body> <xsl:apply-templates/> </body> </document> </xsl:template> <xsl:template match="release"> <s1> <xsl:attribute name="title"> <xsl:value-of select="@name"/><xsl:text> </xsl:text> <xsl:value-of select="@version"/><xsl:text> </xsl:text> <xsl:if test="@date"> <xsl:value-of select="@date"/> </xsl:if> </xsl:attribute> <sl> <xsl:apply-templates/> </sl> </s1> </xsl:template> <xsl:template match="action"> <li> <icon src="images/{@type}.jpg" alt="{@type}"/> <xsl:apply-templates/> <xsl:text>(</xsl:text><xsl:value-of select="@dev"/><xsl:text>)</xsl:text> <xsl:if test="@due-to"> <xsl:text> Thanks to </xsl:text> <link href="mailto:{@due-to-email}"><xsl:value-of select="@due-to"/></link> <xsl:text>.</xsl:text> </xsl:if> <xsl:if test="@fixes-bug"> <xsl:text> Fixes </xsl:text> <link href="http://xml.apache.org/bugs/show_bug.cgi?id={@fixes-bug}"> <xsl:text>bug </xsl:text><xsl:value-of select="@fixes-bug"/> </link> <xsl:text>.</xsl:text> </xsl:if> </li> </xsl:template> <xsl:template match="devs"> <!-- remove --> </xsl:template> </xsl:stylesheet> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/stylesheets/copyover.xsl Index: copyover.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="@*|*|text()|processing-instruction()"> <xsl:copy> <xsl:apply-templates select="@*|*|text()|processing-instruction()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/stylesheets/document2html.xsl Index: document2html.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="stylebook.project"/> <xsl:param name="copyright"/> <xsl:param name="docid"/> <xsl:param name="target"/> <xsl:output method="html" indent="yes"/> <!-- <xsl:strip-space elements="*"/> --> <!-- voodoo magic to calculate base directory --> <xsl:template name="get-base-directory"> <xsl:call-template name="get-base-directory-internal"> <xsl:with-param name="file" select="$docid"/> </xsl:call-template> </xsl:template> <xsl:template name="get-base-directory-internal"> <xsl:param name="file"/> <xsl:choose> <xsl:when test="contains( $file, '/' )"> <xsl:variable name="remainder" select="substring-after($file, '/')" /> <xsl:variable name="path"> <xsl:call-template name="get-base-directory-internal"> <xsl:with-param name="file" select="$remainder"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="concat('../',$path)"/> </xsl:when> <xsl:otherwise>./</xsl:otherwise> </xsl:choose> </xsl:template> <!-- ====================================================================== --> <!-- document section --> <!-- ====================================================================== --> <xsl:template match="document"> <html> <head> <title><xsl:value-of select="header/title"/></title> </head> <body text="#000000" link="#525D76" vlink="#023264" alink="#023264" topmargin="4" leftmargin="4" marginwidth="4" marginheight="4" bgcolor="#ffffff"> <!-- THE TOP BAR (HEADER) --> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td valign="top" align="left"> <a href="http://jakarta.apache.org/index.html"> <img hspace="0" vspace="0" border="0"> <xsl:attribute name="src"><xsl:call-template name="get-base-directory"/>images/jakarta-logo.gif</xsl:attribute> </img> </a> </td> <td width="100%" valign="middle" align="left" bgcolor="#ffffff"> <img hspace="0" vspace="0" border="0" alt="{header/title}" align="right"> <xsl:attribute name="src"><xsl:call-template name="get-base-directory"/>/images/logocactus.gif</xsl:attribute> </img> </td> </tr> <tr> <td width="100%" height="2" colspan="2"><hr noshade="" size="1"/></td> </tr> </table> <!-- THE MAIN PANEL (SIDEBAR AND CONTENT) --> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <!-- THE SIDE BAR --> <td width="1%" valign="top"> </td> <td width="14%" valign="top" nowrap="1"> <br/> <font face="arial,helvetica,sanserif"> <xsl:apply-templates select="document($stylebook.project)"/> </font> </td> <!-- THE CONTENT PANEL --> <td width="*" valign="top" align="left"> <table border="0" cellspacing="0" cellpadding="3"> <tr><td><br/><xsl:apply-templates/></td></tr> <tr> <td align="right"> <xsl:if test="header/authors"> <p>by <xsl:for-each select="header/authors/person"> <a href="mailto:{@email}"><xsl:value-of select="@name"/></a> <xsl:if test="not(position()=last())">, </xsl:if> </xsl:for-each> </p> </xsl:if> </td> </tr> </table> </td> </tr> </table> <br/> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td><hr noshade="" size="1"/></td></tr> <tr> <td align="center"> <font face="arial,helvetica,sanserif" size="-1" color="#525D76"> <i> Copyright © <xsl:value-of select="$copyright"/>. All Rights Reserved. </i> </font> </td> </tr> </table> </body> </html> </xsl:template> <!-- ====================================================================== book section ====================================================================== --> <xsl:template match="menu-item"> <xsl:choose> <xsl:when test="@type='external'"> <li> <font size="-1"> <a href="{@href}" target="{@id}"><xsl:value-of select="@label"/></a> </font> </li> </xsl:when> <xsl:when test="not(@type) or @type!='hidden'"> <li> <a> <xsl:attribute name="href"><xsl:call-template name="get-base-directory"/><xsl:value-of select="substring(@source,0,string-length(@source)-3)"/>.html</xsl:attribute> <font size="-1"><xsl:value-of select="@label"/></font> </a> </li> </xsl:when> <xsl:otherwise><!-- hidden --></xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="separator"> <br/> </xsl:template> <xsl:template match="menu"> <br/> <!-- alternate color #F3510C --> <font size="+1" color="#000000"><xsl:value-of select="@label"/></font> <br/> <font size="-1"><xsl:apply-templates/></font> <br/> </xsl:template> <xsl:template match="project"> <br/> <a href="{@href}"> <font size="+1" color="#F3510C"><xsl:value-of select="@label"/></font> </a> <br/> </xsl:template> <!-- ====================================================================== --> <!-- header section --> <!-- ====================================================================== --> <xsl:template match="header"> <!-- <center> <table width="80%"> <tr> <td bgcolor="#F3DD61"> <br/> <center> <b> <font face="arial,helvetica,sanserif" color="#000000"> <xsl:value-of select="title"/> <xsl:if test="subtitle"> : <xsl:value-of select="subtitle"/> </xsl:if> </font> </b> </center> <br/> </td> </tr> </table> </center> <br/> --> </xsl:template> <!-- ====================================================================== --> <!-- body section --> <!-- ====================================================================== --> <xsl:template match="s1"> <xsl:call-template name="section"> <xsl:with-param name="width">100%</xsl:with-param> <xsl:with-param name="font-size">+1</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template match="s2"> <xsl:call-template name="section"> <xsl:with-param name="width">95%</xsl:with-param> <xsl:with-param name="font-size">+0</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template match="s3"> <xsl:call-template name="section"> <xsl:with-param name="width">90%</xsl:with-param> <xsl:with-param name="font-size">-1</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template match="s4"> <xsl:call-template name="section"> <xsl:with-param name="width">85%</xsl:with-param> <xsl:with-param name="font-size">-2</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="section"> <xsl:param name="width" /> <xsl:param name="font-size" /> <div align="right"> <table border="0" cellspacing="0" cellpadding="2"> <xsl:attribute name="width"><xsl:value-of select="$width"/></xsl:attribute> <tr> <td bgcolor="#525D76"> <font face="arial,helvetica,sanserif" color="#ffffff"> <xsl:attribute name="size"><xsl:value-of select="$font-size"/></xsl:attribute> <b><xsl:value-of select="@title"/></b> </font> </td> </tr> <tr> <td> <font face="arial,helvetica,sanserif" color="#000000"><br/><xsl:apply-templates/></font> </td> </tr> </table> </div> <br/> </xsl:template> <!-- ====================================================================== --> <!-- footer section --> <!-- ====================================================================== --> <xsl:template match="footer"> <!-- ignore on general documents --> </xsl:template> <!-- ====================================================================== --> <!-- paragraph section --> <!-- ====================================================================== --> <xsl:template match="p"> <p align="justify"><xsl:apply-templates/></p> </xsl:template> <xsl:template match="source"> <div align="center"> <table border="1" cellspacing="2" cellpadding="2"> <tr> <td><pre><xsl:apply-templates/></pre></td> </tr> </table> </div> </xsl:template> <xsl:template match="fixme"> <!-- ignore on documentation --> </xsl:template> <!-- ====================================================================== --> <!-- list section --> <!-- ====================================================================== --> <xsl:template match="ul|ol|dl"> <blockquote> <xsl:copy><xsl:apply-templates/></xsl:copy> </blockquote> </xsl:template> <xsl:template match="li"> <xsl:copy><xsl:apply-templates/></xsl:copy> </xsl:template> <xsl:template match="sl"> <ul><xsl:apply-templates/></ul> </xsl:template> <xsl:template match="dt"> <li> <strong><xsl:value-of select="."/></strong> <xsl:text> - </xsl:text> <xsl:value-of select="following::dd"/> </li> </xsl:template> <xsl:template match="dd"> <!-- ignore since already used --> </xsl:template> <!-- ====================================================================== --> <!-- note section --> <!-- ====================================================================== --> <xsl:template match="note"> <p> <table width="100%" cellspacing="3" cellpadding="0" border="0"> <tr> <td width="28" valign="top"> <img src="images/note.gif" width="28" height="29" vspace="0" hspace="0" border="0" alt="Note"/> </td> <td valign="top"> <font size="-1" face="arial,helvetica,sanserif" color="#000000"> <i> <xsl:apply-templates/> </i> </font> </td> </tr> </table> </p> </xsl:template> <!-- ====================================================================== --> <!-- table section --> <!-- ====================================================================== --> <xsl:template match="table"> <table width="100%" border="0" cellspacing="2" cellpadding="2"> <caption><xsl:value-of select="caption"/></caption> <xsl:apply-templates/> </table> </xsl:template> <xsl:template match="tr"> <tr><xsl:apply-templates/></tr> </xsl:template> <xsl:template match="th"> <td bgcolor="#039acc" colspan="{@colspan}" rowspan="{@rowspan}" valign="center" align="center"> <font color="#ffffff" size="-1" face="arial,helvetica,sanserif"> <b><xsl:apply-templates/></b>  </font> </td> </xsl:template> <xsl:template match="td"> <td bgcolor="#a0ddf0" colspan="{@colspan}" rowspan="{@rowspan}" valign="top" align="left"> <font color="#000000" size="-1" face="arial,helvetica,sanserif"> <xsl:apply-templates/>  </font> </td> </xsl:template> <xsl:template match="tn"> <td bgcolor="#ffffff" colspan="{@colspan}" rowspan="{@rowspan}">   </td> </xsl:template> <xsl:template match="caption"> <!-- ignore since already used --> </xsl:template> <!-- ====================================================================== --> <!-- markup section --> <!-- ====================================================================== --> <xsl:template match="strong"> <b><xsl:apply-templates/></b> </xsl:template> <xsl:template match="em"> <i><xsl:apply-templates/></i> </xsl:template> <xsl:template match="filename"> <filename><i><xsl:apply-templates/></i></filename> </xsl:template> <xsl:template match="code"> <code><font face="courier, monospaced"><xsl:apply-templates/></font></code> </xsl:template> <!-- ====================================================================== --> <!-- images section --> <!-- ====================================================================== --> <xsl:template match="figure"> <p align="center"><img src="{@src}" alt="{@alt}" border="0" vspace="4" hspace="4"/></p> </xsl:template> <xsl:template match="img"> <img src="{@src}" alt="{@alt}" border="0" vspace="4" hspace="4" align="right"/> </xsl:template> <xsl:template match="icon"> <img src="{@src}" alt="{@alt}" border="0" align="absmiddle"/> </xsl:template> <!-- ====================================================================== --> <!-- links section --> <!-- ====================================================================== --> <xsl:template match="link"> <a href="{@href}"><xsl:apply-templates/></a> </xsl:template> <xsl:template match="jump"> <a href="{@href}#{@anchor}"><xsl:apply-templates/></a> </xsl:template> <xsl:template match="fork"> <a href="{@href}" target="_blank"><xsl:apply-templates/></a> </xsl:template> <xsl:template match="anchor"> <a name="{@id}"><xsl:comment>anchor</xsl:comment></a> </xsl:template> <!-- ====================================================================== --> <!-- specials section --> <!-- ====================================================================== --> <xsl:template match="br"> <br/> </xsl:template> </xsl:stylesheet> 1.1 jakarta-commons/cactus/docs/framework/skins/jakarta.apache.org/stylesheets/todo2document.xsl Index: todo2document.xsl =================================================================== <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="copyover.xsl"/> <xsl:template match="todo"> <document> <header> <title><xsl:value-of select="@title"/></title> </header> <body> <xsl:apply-templates/> </body> </document> </xsl:template> <xsl:template match="actions"> <s2 title="{@priority}"> <sl> <xsl:for-each select="action"> <li> <strong><xsl:text>[</xsl:text><xsl:value-of select="@context"/><xsl:text>]</xsl:text></strong><xsl:text> </xsl:text> <xsl:apply-templates/> </li> </xsl:for-each> </sl> </s2> </xsl:template> </xsl:stylesheet> 1.1 jakarta-commons/cactus/docs/framework/xdocs/ant.xml Index: ant.xml =================================================================== <?xml version="1.0"?> <!-- <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> --> <document> <header> <title>Ant Integration</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Continuous integration"> <p> A strong principle of eXtreme Programming (XP) is the continuous integration aspect (see the <link href="http://www.martinfowler.com/articles/continuousIntegration.html"> Continuous Integration</link> article by Martin Fowler). The traditional approach has been to developing the code first, then test it and then integrate it with other appications. The continuous integration principle is to develop code, tests and integrate at the same time, i.e. at any point in time, you have a functioning code along with tests and integrated. </p> <p> In order to be able to do continuous integration, you need to be able to automatically run the build for your application, including passing the unit tests (based on JUnit, Cactus, HttpUnit or others). Ant is the perfect tool for this task. </p> </s1> <s1 title="Ant benefits"> <p> The benefits of using Ant for running unit tests are as follows : </p> <table> <tr> <th> Benefits </th> </tr> <tr> <td> Ant is written in Java and thus the same scripts can be used on several systems (Windows and Unix for example). Is is therefore very well suited for building java applications. </td> </tr> <tr> <td> Ant provides enough built-in and optional tasks to be able to achieve almost any needed build task without needing to use system dependent scripts. </td> </tr> <tr> <td> By being able to very quickly rerun unit test you can verify that your tests still pass when you modify some part of your code ( regression testing) </td> </tr> <tr> <td> As it is automated, it fits well in the continuous integration principle and your tests can thus be ran automatically and continously </td> </tr> </table> </s1> <s1 title="Writing an Ant build script tutorial"> <p> The sample Ant build file described below is taken from the <link href="downloads.html">Cactus Sample for Servlet API 2.2 </link> project. </p> <note> This section is both a tutorial for automating builds and unit testing with Ant and Cactus and also a best practice and methodology guide for using Ant in general (independent of Cactus). This is an Ant configuration that has been working for me on several project. Of course, you are free to adapt/modify it to suit your needs. </note> <s2 title="Project directory structure"> <p> Create the following directories : </p> <table> <tr> <th> Directory name </th> <th> Content of the directory </th> </tr> <tr> <td> <code>build</code> </td> <td> The Ant build file and some other ancillary files (properties file, ...) </td> </tr> <tr> <td> <code>conf</code> </td> <td> Configuration files for the project. These are the configuration files that will <em>not</em> be put into the runtime jar. They are configuration file that need to be visible and modifyable by a user of the project. If they were bundled in the jar they would be hard to modify. On the other hand, we don't want a proliferation of configuration files, so all <em>technical</em> configuration files (messages to display for errors, ...) should be put in the <code>src</code> directory in correct java packages. </td> </tr> <tr> <td> <code>conf/test</code> </td> <td> Configuration files needed for testing the project only. </td> </tr> <tr> <td> <code>docs</code> </td> <td> Project documentation. </td> </tr> <tr> <td> <code>docs/skins</code> </td> <td> Documentation skin for Stylebook (if using Stylebook). </td> </tr> <tr> <td> <code>docs/xdocs</code> </td> <td> Documentation files (XML files) for Stylebook (if using Stylebook). </td> </tr> <tr> <td> <code>src</code> </td> <td> The project sources : java files + java test files + properties files + test properties files + other files for runtime or test (XML files, ...). Note that all test files should begin by 'Test' or 'test' in order to easily separate them from other files so that in an Ant target we'll be able to include only the runtime files. </td> </tr> <tr> <td> <code>web</code> </td> <td> The project web files : HTML, JSP, ... (if any) </td> </tr> </table> <note> In the sample application provided with Cactus, we don't generate any web site documentation (only javadoc) so we're not using the stylebook-related directories and Ant targets. However we do so in Cactus itself, so if you need to take a look, download the Cactus sources. </note> <note> An <code>out</code> directory will be created by the Ant build. All build-generated files will be put in that directory (compiled classes, generated javadoc documentation, test configuration files for running an application server, ...). </note> <note> We don't have any <code>lib</code> directory because it is always better not to include dependent jars in your project whenever possible for the following reasons : better continuous integration with other libraries (meaning they also evolve and you should test as much as possible with the latest version to discover potential problems early, more lightweight downloads, less jar proliferation (you'll end up with tens of the same jars otherwise), more version control and integration checks (if your project uses 2 external libraries that need another third library but not in the same version you are in trouble !), ... </note> </s2> <s2 title="Ant Target List"> <p> Define the following targets in your <code>build.xml</code>. </p> <note> The <em>Type</em> column specify whether the target is an external target that can be called by the user of the build file or if it is an internal target, intended to be called internally by another target inside the build script. </note> <table> <tr> <th> Target name </th> <th> Description </th> <th> Type </th> </tr> <tr> <td> <jump anchor="init"><code>init</code></jump> </td> <td> Defines token filters, timestamp, display some information on screen, ... </td> <td> Internal </td> </tr> <tr> <td> <jump anchor="usage"><code>usage</code></jump> </td> <td> Display usage information about the targets. </td> <td> External </td> </tr> <tr> <td> <jump anchor="prepare"><code>prepare</code></jump> </td> <td> Set up the output directory where build generated files will be put and copy the java sources to this output directory, replacing tokens with the values defined in the <code>init</code> target. </td> <td> Internal </td> </tr> <tr> <td> <jump anchor="compile"><code>compile</code></jump> </td> <td> Compile the java sources and put the result in the output directory. All copies non java source files such as <code>.properties</code> files, XML configuration files, ... </td> <td> Internal </td> </tr> <tr> <td> <jump anchor="source"><code>source</code></jump> </td> <td> Generate a zipped file containing the full sources of the project (i.e. the whole directory structure, excluding any build generated files). </td> <td> External </td> </tr> <tr> <td> <jump anchor="javadoc"><code>javadoc</code></jump> </td> <td> Generates the javadoc of the project. This javadoc will be part of the project documentation, as generated by the <code>doc</code> target. </td> <td> Internal </td> </tr> <tr> <td> <jump anchor="doc"><code>doc</code></jump> </td> <td> Generates the full project documentation : javadoc + README files + documentation web site (using Stylebook for example). </td> <td> External </td> </tr> <tr> <td> <jump anchor="clean"><code>clean</code></jump> </td> <td> Remove any build generated files. In particular, delete the output directory. </td> <td> External </td> </tr> <tr> <td> <jump anchor="jar"><code>jar</code></jump>, <jump anchor="war"><code>war</code></jump>, <code>ear</code>, ... </td> <td> Generate the project runtime. If the project is a framework, it is usually a jar. If the project is a web application, it is usually a war file. If the project is an EJB application, it is usually either one or several jars or an ear file. Etc ... </td> <td> External </td> </tr> <tr> <td> <jump anchor="tests"><code>tests_XXX</code></jump> where XXX is the name of the servlet engine on which the tests run. </td> <td> Run the Cactus unit tests. </td> <td> External </td> </tr> </table> </s2> <anchor id="basedir"/> <s2 title="Step 1 : The Ant project basedir"> <p> You <code>build.xml</code> file being in located in <code>build/</code> you should set the <code>project</code> tag <code>basedir</code> attribute to '<code>..</code>' so that all other paths are relative to your project root directory. Indeed, the batch file (shell script) that was used to bootstrap Ant is located in <code><root>/build</code>, so '<code>..</code>' is the root directory. </p> <p> Example : </p> <source><![CDATA[ <?xml version="1.0"?> [...] <project name="Cactus Sample" default="war" basedir=".."> ]]></source> </s2> <s2 title="Step 2 : initialization of project properties"> <p> You should define as properties all values that can be factorized and which are used often in your build file such as source locations, output locations, external jar locations and names, ... You can also define useful file patterns there (see the sample below). </p> <p> A good principle is to defined any properties that depend on your environment (such as external jar locations) in a file (let's call it <code>build.properties</code> located either where <code>build.xml</code> is located or in your home directory. The properties defined in this file will be loaded by <code>build.xml</code> using the following code : </p> <source><![CDATA[ <!-- Give user a chance to override without editing this file (and without typing -D each time it compiles it) --> <property file="build/build.properties" /> <property file="${user.home}/build.properties" /> ]]></source> <p> Here are our properties initializations : </p> <source><![CDATA[ <project name="Cactus Sample" default="war" basedir=".."> <!-- Give user a chance to override without editing this file (and without typing -D each time it compiles it) --> <property file="build/build.properties" /> <property file="${user.home}/build.properties" /> <!-- Generic project properties --> <property name="project.fullname" value="Cactus Sample"/> <property name="project.version" value="@version@"/> <property name="project.name" value="commons-cactus-sample"/> <!-- Miscellaneous settings --> <property name="year" value="@year@"/> <property name="debug" value="on"/> <property name="optimize" value="off"/> <property name="deprecation" value="off"/> <!-- ======================================================================== Set the properties related to the source tree ======================================================================== --> <!-- Source locations for the build --> <property name="src.dir" value="src"/> <property name="src.java.dir" value="${src.dir}/share"/> <property name="src.java.servlet.dir" value="${src.dir}[EMAIL PROTECTED]@"/> <property name="build.dir" value="build"/> <property name="etc.dir" value="${build.dir}/etc"/> <property name="lib.dir" value="lib"/> <property name="conf.dir" value="conf"/> <property name="conf.test.dir" value="conf/test"/> <property name="web.dir" value="web"/> <!-- ======================================================================== Set the properties related to the build area ======================================================================== --> <!-- Destination locations for the build (relative to the basedir as --> <!-- specified in the basedir attribute of the project tag) --> <property name="out.dir" value="out"/> <property name="out.dist.dir" value="${out.dir}/dist"/> <property name="out.lib.dir" value="${out.dir}/lib"/> <property name="out.test.dir" value="${out.dir}/test"/> <property name="out.src.dir" value="${out.dir}/src"/> <property name="out.classes.dir" value="${out.dir}/classes"/> <property name="out.doc.dir" value="${out.dir}/doc"/> <property name="out.javadoc.dir" value="${out.doc.dir}/javadoc"/> <property name="out.conf.dir" value="${out.dir}/conf"/> <!-- Names of deliverables --> <!-- The Cactus Sample war file. This is the file that should be used at runtime by end users (it excludes the test classes) --> <property name="final.war.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.war"/> <!-- The full sources of Cactus Sample in a zip file --> <property name="final.src.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.zip"/> <!-- The Cactus Sample documentation in a zip : javadoc --> <property name="final.doc.name" value="${out.dir}/${project.name}[EMAIL PROTECTED]@.zip"/> <!-- ======================================================================== Useful file patterns for targets ======================================================================== --> <!-- All source files of the projet. These source files will be copied to the destination source directory in the prepare task --> <patternset id="all.src.files"> <!-- All java files --> <include name="**/*.java"/> <!-- All doc files --> <include name="**/package.html"/> <include name="**/overview.html"/> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> <!-- All non java files in the src directory --> <patternset id="all.nonjava.files"> <!-- All conf files (including test files) --> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.properties"/> </patternset> ]]></source> </s2> <anchor id="init"/> <s2 title="Step 3 : 'init' target"> <p> Useful for initializing a timestamp (DSTAMP, TODAY, TSTAMP), defining token filters, printing some information messages, registering custom Ant tasks, ... </p> <source><![CDATA[ <!-- ======================================================================== Initialize the build. Must be called by all targets ======================================================================== --> <target name="init"> <!-- So that we can use the ${TSTAMP}, ${DSTAMP}, ... time stamps in targets, if need be --> <tstamp/> <echo message="--------- ${project.fullname} ${project.version} ---------"/> <echo message=""/> <echo message="java.class.path = ${java.class.path}"/> <echo message=""/> <echo message="java.home = ${java.home}"/> <echo message="user.home = ${user.home}"/> <echo message=""/> <echo message="basedir = ${basedir}"/> <echo message=""/> <echo message="servlet.jar = ${servlet.jar}"/> <echo message="cactus.jar = ${cactus.jar}"/> <echo message="junit.jar = ${junit.jar}"/> <echo message="cactus.ant.jar = ${cactus.ant.jar}"/> <!-- Filters --> <filter token="version" value="${project.version}"/> <filter token="year" value="${year}"/> <!-- Initialize custom Ant task needed for running the server tests --> <taskdef name="runservertests" classname="org.apache.commons.cactus.ant.RunServerTestsTask"> <classpath> <pathelement location="${cactus.ant.jar}"/> <pathelement path="${java.class.path}"/> </classpath> </taskdef> </target> ]]></source> </s2> <anchor id="usage"/> <s2 title="Step 4 : 'usage' targets"> <p> Display a usage message. </p> <source><![CDATA[ <!-- ======================================================================== Help on usage. List available targets ======================================================================== --> <target name="usage" depends="init"> <echo message=""/> <echo message="${project.fullname} build file"/> <echo message="------------------------------------------------------"/> <echo message=""/> <echo message=" Available targets are :"/> <echo message=""/> <echo message=" war --> generates the war file (default)"/> <echo message=" clean --> cleans up the build directory"/> <echo message=" source --> generates source zip of the project"/> <echo message=" doc --> generates the docs (javadoc, ...)"/> <echo message=" all --> do it all at once"/> <echo message=" (clean, war, source, doc)"/> <echo message=""/> <echo message=" Targets for running the tests for Servlet API 2.2 :"/> <echo message=""/> <echo message=" tests_resin_12 --> run tests for Resin 1.2"/> <echo message=" tests_tomcat_32 --> run tests for Tomcat 3.2"/> <echo message=" tests_weblogic_51 --> run tests for WebLogic 5.1"/> <echo message=" tests_orion_14 --> run tests for Orion 1.4"/> <echo message=""/> </target> ]]></source> </s2> <anchor id="prepare"/> <s2 title="Step 5 : 'prepare' target"> <p> This target is needed for both compiling and generating the javadoc. It copies all the source files from their <code>src/</code> directory to the <code>out</code> directory, replacing tokens in the source code (replacing the <code>@version@</code> by the version number for example). </p> <source><![CDATA[ <!-- ======================================================================== Prepare the output directory by copying the source files into it ======================================================================== --> <target name="prepare" depends="init"> <mkdir dir="${out.src.dir}"/> <!-- Copy all source files to destination dir. Apply the filters in order to replace the tokens for the copyright year and the version --> <copy todir="${out.src.dir}" filtering="on"> <fileset dir="${src.java.dir}"> <patternset refid="all.src.files"/> </fileset> <fileset dir="${src.java.servlet.dir}"> <patternset refid="all.src.files"/> </fileset> </copy> </target> ]]></source> </s2> <anchor id="compile"/> <s2 title="Step 6 : 'compile' target"> <p> The <code>compile</code> target simply compiles the java files into <code>.class</code> files and also copies the support files that are in <code>src/</code> to the directory where the class file have been generated. </p> <source><![CDATA[ <!-- ======================================================================== Compiles the source directory ======================================================================== --> <!-- Preparation target for the compile target --> <target name="prepare-compile" depends="prepare"> <mkdir dir="${out.classes.dir}"/> </target> <!-- Run the java compilation --> <target name="compile" depends="prepare-compile"> <javac srcdir="${out.src.dir}" destdir="${out.classes.dir}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> <!-- Exclude all files that are not .java source files --> <!-- All doc files --> <exclude name="**/package.html"/> <exclude name="**/overview.html"/> <!-- All conf files (including test files) --> <exclude name="**/*.txt"/> <exclude name="**/*.xml"/> <exclude name="**/*.properties"/> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> </classpath> </javac> <!-- Copies non java files that need to be in the classes directory --> <copy todir="${out.classes.dir}"> <fileset dir="${src.java.dir}"> <patternset refid="all.nonjava.files"/> </fileset> <fileset dir="${conf.test.dir}"> <include name="cactus.properties"/> </fileset> </copy> </target> ]]></source> </s2> <anchor id="source"/> <s2 title="Step 7 : 'source' target"> <p> Zip up the sources for distribution. </p> <source><![CDATA[ <!-- ======================================================================== Generates source zip of the project ======================================================================== --> <target name="source" depends="prepare"> <zip zipfile="${final.src.name}" basedir="."> <exclude name="${out.dir}/**"/> <exclude name="**/*.log"/> <exclude name="**/*.bak"/> <exclude name="**/*.class"/> <exclude name="${build.dir}/build.properties"/> </zip> </target> ]]></source> </s2> <anchor id="javadoc"/> <s2 title="Step 8 : 'javadoc' target"> <p> Generate the project's javadoc. </p> <source><![CDATA[ <!-- ======================================================================== Generate the javadoc ======================================================================== --> <!-- Preparation target for the javadoc target --> <target name="prepare-javadoc" depends="prepare"> <mkdir dir="${out.javadoc.dir}"/> </target> <!-- Generate the javadoc for the current Servlet API --> <target name="javadoc" depends="prepare-javadoc"> <javadoc sourcepath="${out.src.dir}" packagenames="org.apache.commons.cactus.sample.*" destdir="${out.javadoc.dir}" author="true" public="true" version="true" use="true" windowtitle="${project.fullname} ${project.version} for Servlet @servlet.api@ API" doctitle="${project.fullname} ${project.version} for Servlet @servlet.api@ API" bottom="Copyright &copy; ${year} Apache Software Foundation. All Rights Reserved."> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> </classpath> </javadoc> </target> ]]></source> </s2> <anchor id="doc"/> <s2 title="Step 9 : 'doc' target"> <p> Generate the project's documentation. It includes the javadoc, additional README files (if any) and the documentation web site (built using Stylebook for example, as shown in the example below). </p> <p> Example not using Stylebook : </p> <source><![CDATA[ <!-- ======================================================================== Generate the full documentation ======================================================================== --> <!-- Preparation target for the doc target --> <target name="prepare-doc" depends="javadoc"> <mkdir dir="${out.doc.dir}"/> </target> <!-- Generate the documentation --> <target name="doc" depends="prepare-doc"> <!-- Create the zipped documentation --> <zip zipfile="${final.doc.name}" basedir="${out.doc.dir}"/> </target> ]]></source> <p> Example using Stylebook (from the Cactus build file itself) : </p> <source><![CDATA[ <!-- ======================================================================== Generate the full documentation for a given Servlet API, i.e. web site + javadoc ======================================================================== --> <!-- Preparation target for the doc target --> <target name="prepare-doc" depends="javadoc"> <mkdir dir="${out.doc.dir}"/> <mkdir dir="${out.doc.dir}/images"/> <!-- Copy doc-book.xml to book.xml for defining the documentation web site and replacing token filters (year) --> <delete file="${xdoc.dir}/book.xml"/> <copy file="${xdoc.dir}/doc-book.xml" tofile="${xdoc.dir}/book.xml" filtering="on"/> <!-- Copy the images --> <copy todir="${out.site.dir}/images"> <fileset dir="${xdoc.dir}/images"/> </copy> </target> <!-- Generate the documentation --> <target name="doc" depends="prepare-doc"> <!-- Generate the documentation web site --> <stylebook book="${xdoc.dir}/book.xml" skinDirectory="${skin.dir}/jakarta.apache.org" targetDirectory="${out.doc.dir}"> <classpath> <pathelement path="${java.class.path}"/> </classpath> </stylebook> </target> ]]></source> </s2> <anchor id="clean"/> <s2 title="Step 10 : 'clean' target"> <p> Removes all build generated files. </p> <source><![CDATA[ <!-- ======================================================================== Remove all build generated files ======================================================================== --> <target name="clean" depends="init"> <!-- Deletes all files ending with '~' --> <delete> <fileset dir="." includes="**/*~" defaultexcludes="no"/> </delete> <!-- Remove the out directory --> <delete dir="${out.dir}"/> <!-- Delete log files --> <delete> <fileset dir="."> <include name="**/*.log"/> </fileset> </delete> </target> ]]></source> </s2> <s2 title="Step 11 : 'jar', 'war' targets"> <anchor id="jar"/> <s3 title="'jar' target"> <p> This target is useful if your project is a framework for example and you need to deliver a jar file. We also include a manifest file in the jar, with version information. We copy the manifest to the output directory in order to replace the <code>@version@</code> token with it's value. </p> <p> Example (from the Cactus build file) : </p> <source><![CDATA[ <!-- ======================================================================== Create the runtime jar file ======================================================================== --> <!-- Preparation target for the jar target --> <target name="prepare-jar" depends="compile"> <mkdir dir="${out.conf.dir}"/> <mkdir dir="${out.lib.dir}"/> <!-- Copy the manifest in order to replace the version token filter --> <copy todir="${out.conf.dir}" filtering="on"> <fileset dir="${conf.dir}" > <include name="manifest"/> </fileset> </copy> </target> <!-- Generate the jar file --> <target name="jar" depends="prepare-jar"> <jar jarfile="${final.jar.name}" basedir="${out.classes.dir}" manifest="${out.conf.dir}/manifest"> <!-- Do not include test files in the runtime jar --> <exclude name="**/Test*.*"/> <exclude name="**/test*.*"/> </jar> </target> ]]></source> </s3> <anchor id="war"/> <s3 title="'war' target"> <p> This target is useful if you're building a web application. We also include a manifest file in the war, with version information. We copy the manifest to the output directory in order to replace the <code>@version@</code> token with it's value. </p> <p> Example (from the Cactus sample) : </p> <source><![CDATA[ <!-- ======================================================================== Create the runtime war file ======================================================================== --> <!-- Preparation target for the war target --> <target name="prepare-war" depends="compile"> <mkdir dir="${out.conf.dir}"/> <!-- Copy the manifest in order to replace the version token filter --> <copy todir="${out.conf.dir}" filtering="on"> <fileset dir="${conf.dir}" > <include name="manifest"/> </fileset> </copy> </target> <!-- Generate the war file --> <target name="war" depends="prepare-war"> <war warfile="${final.war.name}" webxml="${conf.dir}/web.xml" manifest="${out.conf.dir}/manifest"> <classes dir="${out.classes.dir}"> <!-- Do not include test files in the runtime jar --> <exclude name="**/Test*.*"/> <exclude name="**/test*.*"/> <!-- Also exclude the test cactus.properties file --> <exclude name="cactus.properties"/> </classes> <fileset dir="${web.dir}"> <exclude name="test/**"/> </fileset> </war> </target> ]]></source> </s3> </s2> <anchor id="tests"/> <s2 title="Step 12 : 'tests_XXX' target"> <p> The <code>tests_XXX</code> target is in charge of running the Cactus unit tests. It must prepare the test environment for a given servlet engine and package the tests, start that servlet engine, run the tests by starting the JUnit runner and stop the servlet engine. </p> <p> See the <link href="servlets.html">tutorial for running tests in a servlet engine</link> for a detailed tutorial on how to do this. </p> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/architecture.xml Index: architecture.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Cactus Architecture</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Assumptions that lead to the current Cactus design"> <p> Here are some assumptions that I have made for the design of Cactus : </p> <table> <tr> <th colspan="2"> Assumptions </th> </tr> <tr> <td> <strong>Assumption 1</strong> </td> <td> The tests need to run on the server side. Indeed in a component model, the components have a closed relationship with their container : they benefit from the container's services, ... and thus they cannot easily be run outside the container. Simulating a container is too much work and leads to building a complete new container if all features need to be supported. </td> </tr> <tr> <td> <strong>Assumption 2</strong> </td> <td> We need to be able to launch the tests that are located on the server side. The solution is to use a proxy class that is located on the server side. There are 2 possible implementations : (1) use a servlet which starts the tests or (2) use an EJB. I have chosen a servlet because it is the simplest solution and not all servlet engine also support EJBs. </td> </tr> <tr> <td> <strong>Assumption 3</strong> </td> <td> We need to call this servlet. Again 2 solutions : (1) open a browser and call the servlet URL or (2) write some java code that uses the <code>URLConnection</code> class to automatically call the servlet. This is what I call the client side part of Cactus. Of course the best solution is (2) for the following reasons : <br/> - The tests can be automated, i.e. it is possible to do automatic regression tests. See the <link href="http://www.xprogramming.com">eXtreme Programming</link> philosophy for better understanding this. The rationale is : everytime you modify some piece of code, you run all the tests again to make sure everything is still working. <br/> - It is possible to verify the results returned by the Servlet : cookies, headers, ... By calling directly the Servlet URL in a browser, it is not possible to do so. </td> </tr> <tr> <td> <strong>Assumption 4</strong> </td> <td> In order to formalize test suites and have a sexy GUI interface there were 2 solutions : (1) make my own framework and GUI or (2) use a well-known, everywhere used framework. Of course, I have chosen this second solution : all the tests are started using JUnit. </td> </tr> </table> </s1> <s1 title="How it works"> <figure src="images/archi.jpg" alt="Cactus Architecture"/> <p> The process is as follows for each XXX test method of your <code>TestYYY</code> test class : </p> <ol> <li> JUnit calls your the <code>TestYYY.runTest()</code> method (inherited from <code>ServletTestCase</code>). This later looks for a <code>beginXXX(ServletTestRequest)</code> method. If one is found, it executes it. This is executed on the client side (i.e. not in a server engine). The <code>ServletTestRequest</code> parameter passed to the <code>beginXXX()</code> method is used to set the HTTP headers, the HTTP parameters, ... that will be sent in step 2 to the Redirector proxy. </li> <li> The <code>TestYYY.runTest()</code> method then opens an HTTP connection to the Redirector proxy. All the parameters set up in the <code>beginXXX()</code> method are put in the HTTP request (HTTP headers, HTTP parameters, ...) </li> <li> The Redirector proxy acts as a proxy for your <code>TestYYY</code> test class, but on the server side. It means that <code>TestYYY</code> is instantiated twice : once on the client side and once on the server side. The client side instance is used for executing the <code>beginXXX()</code> and <code>endXXX()</code> methods (see steps 1 and 8) and the server side instance is used for executing the <code>testXXX()</code> methods (see step 4). The Redirector proxy does the following : <ul> <li> creates an instance of <code>TestYYY</code> using reflection. It sets by reflection the Cactus implicit objects (see the section below on Servlet Redriector Proxy and JSP Redirector Proxy for a list of available objects). </li> <li> creates instances of Cactus wrappers for some server objects (<code>HttpServletRequest</code>, <code>ServletConfig</code>, <code>ServletContext</code>, ...). This is to be able to to override some methods in order to return simulated values. For example, the Cactus framework can simulate an URI (i.e. act as if this URI was called instead of the Redirector proxy URI). Thus, the <code>getServerName()</code>, <code>getServerPort()</code>, <code>getRequestURI()</code>, ... methods return values based on the simulated URI (if there is any defined by the user). </li> <li> creates an HTTP Session if the user has expressed the wish (using the <code>ServletTestRequest.setAutomaticSession(boolean)</code> code in the <code>beingXXX()</code> method. By default a session is always created) and it fills by reflection the <code>session</code> implicit object. </li> </ul> </li> <li> The <code>TestYYY.setUp()</code>, <code>TestYYY.testXXX()</code> and <code>tearDown()</code> methods are executed (in that order). They are called by the Redirector proxy using reflection. </li> <li> Your <code>TestYYY.testXXX()</code> method calls your server side code, executing the test and using the JUnit asserts to assert the result (<code>assert()</code>, <code>assertEquals()</code>, <code>fail()</code>, ...) </li> <li> If the test fails, your <code>TestYYY.testXXX()</code> methods throws exceptions to the Redirector proxy. </li> <li> If an exception has been raised, the Redirector proxy returns the information about the exception (it's name, class, stack trace) back to the client side. It will then be printed by JUnit in it's Test Runner console. </li> <li> If no exception occurred, the <code>TestYYY.runTest()</code> method looks for an <code>endXXX(HttpURLConnection)</code> method and executes it if found. At this stage, you have the opportunity to check returned HTTP headers, Cookies and the servlet output stream in the <code>endXXX()</code> method, again using JUnit asserts and helper utility classes provided by Cactus (see the sample application). </li> </ol> <s2 title="Redirector Proxies"> <p> Cactus provides 2 implementation for the Redirector Proxy : </p> <ul> <li> <em>A Servlet Redirector</em>. This redirector is a servlet that should be used for unit testing servlet methods. It provides the following implicit objects : <code>request</code>, <code>response</code>, <code>session</code> and <code>config</code>. </li> <li> <em>A JSP Redirector</em>. This redirector is a JSP page that should be used for unit testing server code that need access to the following objects : <code>pageContext</code> and <code>out</code>. These objects are provided in addition to all the objects provided by the Servlet Redirector. It can be useful for testing simple JSP custom Tag libraries. </li> </ul> <note> Testing custom JSP Tag libraries is still in beta. I am still not sure of the usefulness of this ... I think unit testing tag libraries is much less relevant than doing functional tests, but this is an open subject ... </note> <s3 title="Servlet Redirector Proxy"> <figure src="images/archi_servlet.jpg" alt="Servlet Redirector Architecture"/> <p> The client side opens 2 HTTP connections to the Servlet redirector. Once to execute the tests and retrieve the servlet output stream and a second time to get the test result. This is to be able to get the exception data (message, stack trace, ...) if the test failed. The test results are stored in a servlet-context-wide scope variable which is retrieved on the second HTTP connection. </p> </s3> <s3 title="JSP Redirector Proxy"> <figure src="images/archi_jsp.jpg" alt="JSP Redirector Architecture"/> <p> The client side opens 2 HTTP connections. Once to the Redirector JSP to execute the tests and retrieve the JSP output stream and a second time to the Servlet Redirector to get the test result. This is to be able to get the exception data (message, stack trace, ...) if the test failed. The test results are stored in a servlet-context-wide scope variable which is retrieved on the second HTTP connection. </p> </s3> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/changes.xml Index: changes.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE changes SYSTEM "./dtd/changes-v10.dtd"> <changes title="History of Changes"> <devs> <person name="Vincent Massol" email="[EMAIL PROTECTED]" id="VMA"/> </devs> <release version="1.0b1" date="April 9 2001"> <action dev="VMA" type="update"> Updated the Cactus distribution so that everything is contained into one single file (doc + jars + sample). The sources are available separately in a second file. </action> <action dev="VMA" type="add"> Added a section on the main web site page to explain the reason for the Cactus name. </action> <action dev="VMA" type="update"> Tested with JUnit 3.6. </action> <action dev="VMA" type="update"> Changed the web site skin to be the Jakarta skin and not the Apache XML skin. This is because Cactus is now part of the Jakarta Commons project. </action> <action dev="VMA" type="update"> Updated the web site installation section to better explain the required steps to install Cactus. Namely, it covers <link href="installation_ant.html">installing Ant</link> and <link href="installation_sample.html">installing the Cactus Sample application</link>. </action> <action dev="VMA" type="remove"> Removed the deliverable dependencies jar. Instead, provides a zipped installation of Ant containing the needed jars for tasks used by Cactus and Cactus Sample build files. </action> <action dev="VMA" type="update"> Removed the <code>misc/</code> directory and JBuilder files from CVS and source distribution. </action> <action dev="VMA" type="update"> Renamed the project from J2EEUnit to Cactus. Although it was a difficult decision to make, it had to be done as J2EE is a Sun trademark. Renamed all occurrences of J2EEUnit to Cactus and changed package names (from <code>j2eeunit.*</code> to <code>org.apache.commons.castor.*</code>. </action> <action dev="VMA" type="fix"> The sample application sources now contains all needed configuration files (the manifest and web.xml files were missing in the previous release). </action> <action dev="VMA" type="update"> Donated the project to the Apache Software Foundation. Changed license from GPL to APL. Moved packages from <code>j2eeunit.*</code> to <code>org.apache.commons.j2eeunit.*</code> and changed copyrights </action> </release> </changes> 1.1 jakarta-commons/cactus/docs/framework/xdocs/configuration.xml Index: configuration.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Configuring Cactus</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Configuration"> <p> Configuring Cactus is very simple. You simply need to provide a file named <code>cactus.properties</code> that you will put in your CLASSPATH (meaning you need to put the directory where this file is located in your CLASSPATH, not the file itself !). </p> <p> Moreover, in order for Cactus to work, you need to register a generic servlet (called the Redirector servlet) and/or a generic JSP (called the Redirector JSP) in your <code>web.xml</code> file if you are using a web application or in your specific Servlet engine configuration file if it does not support web applications (see the <link href="installation.html">installation</link> section for help on modifying your <code>web.xml</code> file). </p> <note> You need the Redirector JSP only if you want to make unit tests that need to access JSP implicit objects (<code>PageContext</code> and <code>JspWriter</code>). </note> <s2 title="cactus.properties"> <p> You need to se the following properties in your Cactus configuration file (<code>cactus.properties</code>) : </p> <table> <tr> <td> <strong>Property Name</strong> </td> <td> <code>cactus.servletRedirectorURL</code> </td> </tr> <tr> <td> <strong>Description</strong> </td> <td> URL to which the Redirector Servlet is mapped to </td> </tr> <tr> <td> <strong>Example</strong> </td> <td> <code>http://localhost:8080/test/ServletRedirector</code> </td> </tr> </table> <p> <br/> </p> <table> <tr> <td> <strong>Property Name</strong> </td> <td> <code>cactus.jspRedirectorURL</code> </td> </tr> <tr> <td> <strong>Description</strong> </td> <td> URL to which the Redirector JSP is mapped to </td> </tr> <tr> <td> <strong>Example</strong> </td> <td> <code>http://localhost:8080/test/JspRedirector</code> </td> </tr> </table> <p> Sample <code>cactus.properties</code> file : </p> <source><![CDATA[ # Configuration file for Cactus. # Each project using Cactus need to have such a file put in the CLASSPATH # (Meaning the directory containgin this file should be in the CLASSPATH, not # the file itself of course ... :) ) # Defines the URLs that will be used by Cactus to call it's redirectors # (Servlet and JSP). You need to specify in these URLs the webapp context # that you use for your application. In the example below, the context is # "test". cactus.servletRedirectorURL = http://localhost:8080/test/ServletRedirector cactus.jspRedirectorURL = http://localhost:8080/test/JspRedirector ]]></source> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/contributors.xml Index: contributors.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Contributors</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Cactus contributors"> <p>Thanks to all that have contributed so far to Cactus ... </p> <s2 title="Commiters"> <table> <tr> <td> <link href="mailto:[EMAIL PROTECTED]">Vincent Massol</link><br/> Main developer of Cactus, current project maintainer. </td> </tr> <tr> <td> <link href="mailto:[EMAIL PROTECTED]">Lyonel Thouvenot</link><br/> Cactus logo (and web site design and graphisms when Cactus was not using Stylebook). </td> </tr> </table> </s2> <s2 title="Contributors"> <p> Thanks to all that have reported bugs or suggested ideas for Cactus. </p> <p> A special thank to Erik Meade for linking Cactus on the <link href="http://junit.org">JUnit web site</link>. </p> <p> Thanks also to the <link href="http://jakarta.apache.org">Apache Jakarta</link> project and more specifically the <link href="http://jakarta.apache.org/commons">Jakarta Commons</link> project for accepting the donation of J2EEUnit (renamed Cactus), thus giving it a home and a family. </p> </s2> <s2 title="Sponsors"> <table> <tr> <td> <link href="http://www.octo.com">OCTO Technology</link> (the company for which I work),<br/> An IT consulting company on the cutting edge of new technologies, providing expert Architects in the fields of applications servers (J2EE, Microsoft DNA & .NET, ...), EAI and IRM. </td> </tr> </table> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/doc-book.xml Index: doc-book.xml =================================================================== <?xml version="1.0"?> <book software="Cactus" title="Local Cactus Documentation" copyright="@year@ The Apache Software Foundation"> <menu label="About"> <menu-item label="News" source="index.xml"/> <menu-item label="Features" source="features.xml"/> <menu-item label="Changes" source="changes.xml" type="changes"/> <menu-item label="Todo" source="todo.xml" type="todo"/> <menu-item label="Contributors" source="contributors.xml"/> </menu> <menu label="Downloads"> <menu-item label="Downloads" source="downloads.xml"/> </menu> <menu label="User Guides"> <menu-item label="Installation" source="installation.xml"/> <menu-item label="Installing Ant" source="installation_ant.xml"/> <menu-item label="Installing Sample" source="installation_sample.xml"/> <menu-item label="Configuration" source="configuration.xml"/> <menu-item label="Using" source="using.xml"/> <menu-item label="Servlet Sample" source="sample_servlet.xml"/> </menu> <menu label="Developer's Corner"> <menu-item label="Architecture" source="architecture.xml"/> <menu-item label="Ant integration" source="ant.xml"/> <menu-item label="Servlet Engines" source="servlets.xml"/> <menu-item label="API Reference" href="javadoc/index.html" type="external"/> </menu> <menu label="Support"> <menu-item label="CVS" href="http://jakarta.apache.org/site/cvsindex.html" type="external"/> <menu-item label="Bug database" href="http://jakarta.apache.org/site/bugs.html" type="external"/> <menu-item label="Mailing lists" href="http://jakarta.apache.org/site/mail.html" type="external"/> <menu-item label="FAQ" href="http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayTopics/action/SetAll/project_id/2/faq_id/39" type="external"/> </menu> </book> 1.1 jakarta-commons/cactus/docs/framework/xdocs/downloads.xml Index: downloads.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Downloads</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="File list"> <p> Here follows the list of files that you can download : </p> <ul> <li> <strong><code>commons-cactus-<servletapi>-<version>.zip</code> </strong> : the Cactus distribution. It contains : <ul> <li> <strong><code>commons-cactus.jar</code></strong> : the Cactus runtime jar, </li> <li> <strong><code>commons-cactus-ant.jar</code></strong> : some custom Ant tasks that are helpful for automating running Cactus unit tests. Especially the <code>runservertests</code> which automagically start a servlet engine, run the Cactus tests against it and stop the server once it is finished, </li> <li> A Cactus Sample application that shows how to write Cactus tests and how to run and deploy them in a servlet engine using Ant, </li> <li> The Cactus documentation (includes the javadoc + a local copy of the Cactus web site) </li> </ul> </li> <li> <strong><code>commons-cactus-src-<version>.zip</code></strong> : the full Cactus sources, </li> <li> <strong><code>commons-cactus-ant-<version of Ant>-<date>.zip</code></strong> : a prepackaged version of Ant, which contains all needed external jars for tasks used by Cactus build files. This is not a compulsory download but it makes it easier for installing Ant and preparing it for Cactus. This file is only delivered for releases (and not for nightly builds). </li> </ul> <note> <code><servletapi></code> represents the Servlet API specifications for which you want to write Cactus unit tests for. </note> <note> <code><version></code> represents the version number for releases and date stamp for nightly builds. </note> </s1> <s1 title="Releases"> <p> Click <link href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-cactus"> here</link> for Cactus releases. </p> </s1> <s1 title="Nightly builds"> <p> Click <link href="http://jakarta.apache.org/builds/jakarta-commons/nightly/commons-cactus"> here</link> for Cactus nightly builds. </p> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/faq.xml Index: faq.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE faqs SYSTEM "./dtd/faq-v10.dtd"> <faqs title="Frequently Asked Questions"> <faq> <question> How to verify that a cookie was sent from the Servlet back to the client ? </question> <answer> <p> Cactus provides some helper code (<code>cactus.AssertUtils</code>) to retrieve cookies sent back in the HTTP response. For example, you can use the following code (or check the Cactus sample application) : </p> <p> Code in the class to unit test : </p> <source><![CDATA[ public class SampleServlet extends HttpServlet [...] /** * Set a cookie for sending back to the client. This is to verify that * it is possible with Cactus to assert the cookies returned to the client * * @param theResponse the HTTP response */ public void setResponseCookie(HttpServletResponse theResponse) { Cookie cookie = new Cookie("responsecookie", "this is a response cookie"); cookie.setDomain("jakarta.apache.org"); theResponse.addCookie(cookie); } ]]></source> <p> Code in the Cactus test class : </p> <source><![CDATA[ public class TestSampleServlet extends ServletTestCase [...] /** * Test that it is possible to send back a Cookie and verify it on the * client side. */ public void testReceiveCookie() { SampleServlet servlet = new SampleServlet(); servlet.setResponseCookie(response); } /** * Test that it is possible to send back a Cookie and verify it on the * client side. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endReceiveCookie(HttpURLConnection theConnection) { Hashtable cookies = AssertUtils.getCookies(theConnection); Vector list = (Vector)cookies.get("responsecookie"); assert(list.size() == 1); ClientCookie cookie = (ClientCookie)list.elementAt(0); assertEquals("responsecookie", cookie.getName()); assertEquals("this is a response cookie", cookie.getValue()); assertEquals("jakarta.apache.org", cookie.getDomain()); } ]]></source> </answer> </faq> <faq> <question> How to write a unit test for a class that calls the <code>getServletContext()</code> , <code>getServletConfig()</code>, <code>log()</code> (i.e methods inherited from <code>GenericServlet</code>) ? </question> <answer> <p> Simply call the <code>init(ServletConfig)</code> method on your servlet to test prior to calling the method to test. </p> <p> Example (from the Cactus sample application) : </p> <source><![CDATA[ /** * Verify that we can unit test a servlet that makes calls to * <code>getServletConfig()</code>, <code>getServletContext()</code>, * <code>log()</code>, ... (i.e. methods inherited from * <code>GenericServlet</code>). * * @see TestSampleServletConfig_Helper */ public void testServletConfig() throws ServletException { SampleServletConfig servlet = new SampleServletConfig(); // VERY IMPORTANT : Call the init() method in order to initialize the // Servlet ServletConfig object. servlet.init(config); assertEquals("value1 used for testing", servlet.getConfigData()); } ]]></source> </answer> </faq> </faqs> 1.1 jakarta-commons/cactus/docs/framework/xdocs/features.xml Index: features.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Features</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Cactus feature list"> <p><br/></p> <ul> <li> Integrates seamlessly with the JUnit testing framework. Your testing class just has to extend <code>org.apache.commons.cactus.ServletTestCase</code> or <code>org.apache.commons.cactus.JspTestCase</code> (which themselves extends <code>junit.framework.TestCase</code>) instead of extending <code>junit.framework.TestCase</code> directly. </li> <li> Execute your test methods in a servlet/JSP environment, i.e. you have access to the following implicit objects : <code>request</code> ( of type <code>HttpServletRequest</code>), <code>response</code> (of type <code>HttpServletResponse</code>), <code>session</code> (of type <code>HttpSession</code>), <code>config</code> (of type <code>ServletConfig</code>). Moreover you can also have access to 2 additional JSP implicit objects if you need them in your test class : <code>pageContext</code> (of type <code>PageContext</code>) and <code>out</code> (of type <code>JspWriter</code>). </li> <li> Definition of a <code>beginXXX()</code> method for each <code>testXXX()</code> test method. This is for having a chance to initialize the following data that will be available in the <code>HttpServletRequest</code> object in your test method : <ul> <li> HTTP parameters, </li> <li> HTTP headers, </li> <li> HTTP cookies, </li> <li> Simulated URL. You can simulate all the parts of a URL : server name, port, context path, servlet path, path info and the query string. The following methods will return the simulated parts : <ul> <li> <code>HttpServletRequest.getServerName()</code>, </li> <li> <code>HttpServletRequest.getServerPort()</code>, </li> <li> <code>HttpServletRequest.getRequestURI()</code>, </li> <li> <code>HttpServletRequest.getContextPath()</code>, </li> <li> <code>HttpServletRequest.getServletPath()</code>, </li> <li> <code>HttpServletRequest.getQueryString()</code>, </li> <li> <code>HttpServletRequest.getPathInfo()</code> </li> </ul> </li> </ul> </li> <li> Definition of an <code>endXXX()</code> method for each <code>testXXX()</code> test method. This is for having a chance to check the following data from the returned HTTP response : <ul> <li> HTTP headers, </li> <li> HTTP cookies </li> </ul> </li> <li> Predefined Ant 1.3 build scripts that show how to automate Cactus unit tests (automatically starting your servlet engine, running the tests and stopping your server). There are scripts for the following Servlet engines : <ul> <li> Tomcat 3.2.1 (Servlet API 2.2) </li> <li> Tomcat 4.0 (Servlet API 2.3) </li> <li> Resin 1.2 (Servlet API 2.2) </li> <li> Resin 1.3 (Servlet API 2.3) </li> <li> WebLogic 5.1 (Servlet API 2.2) </li> <li> Orion 1.4 (Servlet API 2.2 and 2.3) </li> </ul> </li> <li> Possibility to modify the URL to which the Cactus Redirector servlet and Redirector JSP are mapped to (defined in a properties file) </li> <li> Possibility to specify whether an <code>HttpSession</code> object will be automatically created or not for your test methods </li> <li> Handles <code>setUp()</code> and <code>tearDown()</code> methods which work the same as for JUnit except that they are run on the server side before and after calling each <code>testXXX()</code> method </li> <li> Works with JUnit 3.5 </li> <li> Support for Servlet API 2.2 and 2.3 (Support for Servlet API 2.1 is not provided as it is now too old). </li> <li> Support for JDK 1.2 or greater. </li> <li> Possibility to assert the returned servlet output stream from classes under test (in the <code>endXXX()</code> methods). </li> <li> Helper classes to help assert cookies returned in the HTTP response, ... </li> <li> Implicit objects are actually subclasses of standard servlet objects and provides additional methods to help unit test your code : <ul> <li> Using the <code>config</code> implicit object : <ul> <li> <code>setInitParameter(String, String)</code> : sets a parameter as if it were set in the <code>web.xml</code> file using an <code>init-param</code> tag, </li> <li> <code>setServletName(String)</code> : sets the servlet name. This is the value that is returned by a call to <code>getServletName()</code> </li> </ul> </li> </ul> </li> </ul> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/index.xml Index: index.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Cactus</title> <subtitle>Server-Side Unit Testing Framework</subtitle> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Project description"> <p> Cactus is a simple test framework for unit testing server-side java code. It is based on <link href="http://junit.org">JUnit</link>. It's primary goal is to be able to unit test server side java methods which use Servlet objects such as <code>HttpServletRequest</code>, <code>HttpServletResponse</code>, <code>HttpSession</code>, ... (see the full <link href="features.html">feature list</link>). This framework is <em>not</em> a functional test framework which views your server classes as a black box and only tests the returned results from externally calling your application (see <link href="http://sourceforge.net/projects/httpunit">HttpUnit</link> for this). Both frameworks are complementary. </p> </s1> <s1 title="Latest news"> <table> <tr> <td> 09/04/2001 </td> <td> Cactus 1.0 beta 1 is available for <link href="downloads.html">download</link>. Check the updated <link href="features.html">feature list</link> and the <link href="changes.html">changes</link> for the details. </td> </tr> <tr> <td> 09/04/2001 </td> <td> The web site has been updated to reflect the modifications that occurred during the donation to Apache and the change of name : the license has changed to APL, the packages have moved from <code>j2eeunit.*</code> to <code>org.apache.commons.cactus.*</code> </td> </tr> <tr> <td> 09/04/2001 </td> <td> J2EEUnit has been renamed to Cactus. </td> </tr> <tr> <td> 09/04/2001 </td> <td> J2EEUnit has been donated to the Apache Software Foundation. </td> </tr> </table> </s1> <s1 title="Why the name ?"> <p> Here are some stories and reasons about the name :) </p> <ul> <li> It's a cool name ... Short, easy to pronounce, same meanings in all spoken languages, has some punch ... </li> <li> There is a cool french song by Jacques Dutronc about Cactuses that goes "le monde entier est un cactus ..." (the whole world is a Cactus). The lyrics is available <link href="http://miditext.com/Textes/24859.htm">here</link> and the music (.wma format) <link href="http://miditext.com/wma/24859.wma">here</link>. It is a song that says that cactuses are everywhere and that everything is a cactus. I like that ! :) ... </li> <li> The J2EEUnit name (which was the previous name of Cactus) was fine but there was a Sun trademark on the J2EE part of the name ... </li> <li> Cactus is actually an acronym ... ha ha .. for Computer Assisted Construction of Test Unit for the Server, or Cool and Comprehensive Test Unit for the Server, or ... (please send your suggestions to <link href="mailto:[EMAIL PROTECTED]">me</link>) ... </li> <li> The company for which I work (<link href="http://www.octo.com"> OCTO Technology</link>) had organized a diner to celebrate our 3 years of existence. I was looking for a new name for J2EEUnit. I asked some workmates of mine to help me look for a name. We tried to find a name which had something to do with the Apache name. We though of indians of course ... we tried several names and then Dominique said "Cactus" (you know, indians, the desert, cactuses. That's one cliché of indians we have here in France !). I immediatly liked it ... </li> <li> The Cactus name has a rich visual iconography associated with it. So it should be possible to find a nice and funny logo (I'm still looking for the perfect logo ... Again if you have ideas, you can send them to <link href="mailto:[EMAIL PROTECTED]">me</link>) ... </li> <li> A Cactus is full of spines. Visually you can imagine that a piece of code that has gone through this rigourous and comprehensive testing has had all it's bug revealed ! ... </li> <li> We can imagine a motto like "Tested on Apache-Cactus" ! </li> <li> Any more ... ? </li> </ul> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/installation.xml Index: installation.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Installing Cactus</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Forewords"> <p> You have 2 options for installing Cactus : </p> <ul> <li> Integrate Cactus in your existing developement environment and build process. This is what I call the "manual" installation because you'll have to understand how Cactus works, </li> <li> Use the Cactus Sample as a starting point. The Cactus Sample application is more than just an example of how to use Cactus. It is a <em>methodology</em> for using Cactus. This methodology is described in the <link href="ant.html">Ant integration</link> and in the <link href="servlets.html">Servlet engine integration</link> tutorials. The Cactus Sample is the implementation of this methodology. </li> </ul> <p> The steps below will explain how to "manually" install Cactus in your developement environment. For explanations on how to install the Cactus Sample, go <link href="installation_sample.html">here</link>. </p> </s1> <s1 title="System Requirements"> <p> In order to use Cactus for unit-testing you need to have the following software already installed on your system : </p> <ul> <li> <strong>Java Virtual Machine</strong> A Java 1.2 or greater compatible virtual machine must be present. Note that all servlet engines require a JVM to run so if you are already using servlets you already have one installed. </li> <li> <strong>Servlet Engine</strong> A Servlet 2.x compliant servlet engine for running your J2EUnit tests must be present. Cactus works with any servlet engine. Sample Ant scripts are even provided for the most common ones (see the <link href="features.html">features list</link>). </li> <li> <strong>Ant (optional)</strong> Ant is needed only if you wish to either run the Cactus Sample application or if you wish to use Ant as your build system for running and automating your unit tests. See the <link href="installation_ant.html">Ant installation</link> tutorial. </li> </ul> </s1> <s1 title="Installing Cactus"> <p> The steps below show how to set up an environment for executing servlet unit tests. However, look at the <link href="downloads.html">Cactus Sample sources</link> for an already set up environment that uses Ant to automate the running of unit tests. </p> <s2 title="Step 1 : Installation of Cactus in your application to test"> <p> Cactus works by calling a Redirector (either Servlet Redirector or JSP Redirector, both part of Cactus) that you need to put where both the server-side code that you need to test and your test code are located. In other words, you need to do the following : </p> <ol> <li> Put the <code>cactus-<servlet API>-<version>.jar</code> file in the <code>WEB-INF/lib</code> directory of the webapp that you are testing (If your servlet engine does not support web applications, just make sure that it is in the <code>CLASSPATH</code> of your servlet engine). </li> <li> Modify your <code>web.xml</code> file to include a mapping for the Redirector Servlet (If your servlet engine does not support web applications, you won't have any <code>web.xml</code> file. You'll need to edit your servlet engine configuration file and find out how to map a URL to a Servlet). This mapping contains : <ul> <li> the name of the Redirector Servlet class, </li> <li> the URI that will be used to call the Redirector Servlet. This needs to match the URL specified in the <code>cactus.properties</code> configuration file (see <link href="configuration.html">configuration</link>), </li> <li> configuration data that can be retrieved using the <code>config</code> implicit object. </li> </ul> </li> <li> Modify your <code>web.xml</code> file to include a mapping for the Redirector JSP. This mapping contains : <ul> <li> the name of the Redirector JSP page, </li> <li> the URI that will be used to call the Redirector JSP. This needs to match the URL specified in the <code>cactus.properties</code> configuration file (see <link href="configuration.html">configuration</link>). </li> <li> configuration data that can be retrieved using the <code>config</code> implicit object. </li> </ul> </li> <li> Copy the Cactus Redirector JSP file called <code>redirector.jsp</code> in the document root of your test webapp. </li> </ol> <note> The steps 3 and 4 above are only necessary if you wish to use the Redirector JSP for your tests and thus have access to the <code>pageContext</code> and <code>out</code> implicit objects (for testing custom tag libraries for example). </note> <p> For example, if you have the following configuration : </p> <ul> <li> Your webapp is called "<code>mywebapp</code>" </li> <li> The URLs specified in your <code>cactus.properties</code> are "<code>http://localhost:8080/mywebapp/ServletRedirector</code>" for the <code>cactus.servletRedirectorURL</code> property and "<code>http://localhost:8080/mywebapp/JspRedirector</code>" for the <code>cactus.jspRedirectorURL</code> property </li> <li> The Cactus Redirector JSP file <code>redirector.jsp</code> is put in a subdirectory named <code>test/</code> in your webapp document root. </li> </ul> <p> then your <code>web.xml</code> file should look like : </p> <source><![CDATA[ <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"> <web-app> <servlet> <servlet-name>ServletRedirector</servlet-name> <servlet-class>cactus.server.ServletTestRedirector</servlet-class> <init-param> <param-name>param1</param-name> <param-value>value1 used for testing</param-value> </init-param> </servlet> <servlet> <servlet-name>JspRedirector</servlet-name> <jsp-file>/test/redirector.jsp</jsp-file> <init-param> <param-name>param1</param-name> <param-value>value1 used for testing</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ServletRedirector</servlet-name> <url-pattern>/ServletRedirector</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>JspRedirector</servlet-name> <url-pattern>/JspRedirector</url-pattern> </servlet-mapping> </web-app> ]]></source> </s2> <s2 title="Step 2 : Installation of your test code"> <p> You also need to put the test classes that you have written (see the <link href="using.html">using</link> section) on the server side, along with the code to test. Put these classes in your <code>WEB-INF/classes</code> or <code>WEB-INF/lib</code> (If your servlet engine does not support web applications, just make sure that it is in the <code>CLASSPATH</code> of your servlet engine). </p> </s2> <s2 title="Step 3 : Client-side installation with JUnit"> <p> A Cactus suite of tests is started using JUnit test runners (see the <link href="using.html">using</link> section). You need to put the following files in your client-side CLASSPATH : </p> <ul> <li> The JUnit jar file, </li> <li> The Cactus jar : <code>cactus-<servlet API>-<version>.jar</code>, </li> <li> Your test classes. This is needed because the <code>beginXXX()</code> and <code>endXXX()</code> methods are executed on the client side (see the <link href="using.html">using</link> section for explanations on how to write tests using Cactus and see the <link href="architecture.html">architecture</link> section for an explanation on how Cactus works) </li> </ul> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/installation_ant.xml Index: installation_ant.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Installing Ant</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Forewords"> <p> Ant is a Java based build tool. It is used to build the Cactus framework itself and the Cactus Sample application. </p> </s1> <s1 title="Ant tasks needed by Cactus"> <p> Cactus uses the following optional tasks of Ant : </p> <ul> <li> <strong><code><stylebook></code></strong> to build the Cactus web site and Cactus documentation. The Stylebook version required by the Cactus build is the Stylebook 1.0b3 for Xalan2 (named <code>stylebook-1.0-b3_xalan-2.jar</code>) which needs the Xalan 2.0 jar and the Xerces 1.3 jar. The Ant stylebook task It is not used by the Cactus Sample application build process. </li> <li> <strong><code><junit></code></strong> to run the unit tests of Cactus itself and the Cactus unit tests in the Sample application. </li> <li> The Cactus Sample application uses a custom task provided by Cactus in the <code>cactus-ant-<version>.jar</code> jar file (the task is called <strong><code><runservertests></code></strong>). </li> </ul> </s1> <s1 title="Installing Ant on Windows systems"> <p> Ant is an application that needs to be installed somewhere on your hard drive. </p> <p> Follow the steps below to install Ant : </p> <ol> <li> Download Jakarta Ant (<code>jakarta-ant-<version>-bin.zip</code>) from <link href="http://jakarta.apache.org/ant/index.html">here</link>. I recommend version 1.3 or above. Alternatively you can download a prepackaged Ant version (containing required optional tasks and jars) from <link href="TODO">here</link>, </li> <li> Unzip it in a directory. Let's call this directory <code>antroot</code>, </li> <li> Create an environment variable named <code>ANT_HOME</code> that points to your <code>antroot</code> directory, </li> <li> Modify the <code>PATH</code> environment variable to include the <code>%ANT_HOME%\bin</code> directory (so that you'll be able to type <code>ant</code> in a DOS shell, in whatever directory and it will call the <code>%ANT_HOME%\bin\ant.bat</code> script, </li> <li> Download the Ant optional task jar (<code>jakarta-ant-<version>-optional.jar</code>) from <link href="http://jakarta.apache.org/ant/index.html">here</link> and put it in <code>%ANT_HOME%\lib</code>, </li> <li> If you haven't downloaded the prepackaged Ant zip, you'll need to download the Stylebook 1.0b3 for Xalan 2 jar (from ?), the latest <link href="http://xml.apache.org/xalan-j/">Xalan</link>, the latest <link href="http://xml.apache.org/xerces-j">Xerces</link> and the latest <link href="http://junit.org">JUnit</link> jars. You'll also need to ensure that you use a JAXP 1.1 parser (Ant 1.3 comes with a JAXP 1.0 parser only, called <code>parser.jar</code>. Ant 1.4 already bundles a JAXP 1.1 parser, called <code>crimson.jar</code>). You can download one (crimson) from <link href="http://java.sun.com/xml/download.html">here</link>. Put all these jars in <code>%ANT_HOME%\lib</code>. </li> </ol> <note> You should ensure that the Ant optional jar that you download contains the <stylebook> and <junit> tasks. Alternatively you can download the prepackaged Ant zip as mentionned above. </note> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/installation_sample.xml Index: installation_sample.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Installing the Cactus Sample</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Prerequisites"> <p> You need to install the following prior to building the Cactus Sample application : </p> <ul> <li> A JVM (1.2 or above), </li> <li> A Servlet Engine (Servlet API 2.2 or above). The Cactus Sample Ant build script supports automatic running the Cactus unit tests on the following Servle Engines (however, it is easy to support others) <ul> <li> Tomcat 3.2 </li> <li> Tomcat 4.0 </li> <li> WebLogic 5.1 </li> <li> Orion Server 1.4 </li> <li> Resin 1.2 </li> <li> Resin 1.3 </li> </ul> </li> <li> Ant (see the <link href="installation_ant.html">"Installing Ant"</link> tutorial). </li> <li> Servlet API corresponding to the Cactus Sample release you have downloaded (for Servlet API 2.2 or 2.3). Download the API : <ul> <li> For Servlet API 2.2 <ul> <li> From <link href="http://java.sun.com/products/servlet/download.html"> Sun</link> or from the <link href="http://jakarta.apache.org/builds/jakarta-servletapi/"> Jakarta reference implementation</link> </li> </ul> </li> <li> For Servlet API 2.3 <ul> <li> From <link href="http://java.sun.com/products/servlet/download.html"> Sun</link> or from the <link href="http://jakarta.apache.org/builds/jakarta-servletapi-4/"> Jakarta reference implementation</link> </li> </ul> </li> </ul> You can put these libraries whereever you want on your hard disk. You'll just have to specify the location where they are in the <code>build.properties</code> file, as described below. </li> </ul> </s1> <s1 title="Installing the Cactus Sample"> <p> Follow these steps : </p> <ul> <li> Download the <link href="downloads.html">Cactus Sample</link> and unzip it in a directory. Let's call this directory <em><code>sampleroot</code></em>. </li> <li> Rename (or copy) the <em><code>sampleroot</code></em> <code>/build/build.properties.sample</code> file to <code>build.properties</code>. This file defines the dependencies between the Cactus Sample build process and your environment (location of external jars, home directory for installed servlet engine(s), ...). Edit this file to reflect your environment values. </li> <li> In your shell, cd to the <em><code>sampleroot</code></em> <code>/build</code> directory and type '<code>ant usage</code>' to get the list of callable targets. </li> </ul> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/javadoc.xml Index: javadoc.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>API Reference</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Javadocs"> <p> These are the generated javadocs for the different Servlet API. </p> <table> <tr> <th> <strong>Name</strong> </th> </tr> <tr> <td> <link href="javadoc/servlet22/index.html">Javadoc for Cactus 1.0 Servlet API 2.2</link> </td> </tr> <tr> <td> <link href="javadoc/servlet23/index.html">Javadoc for Cactus 1.0 Servlet API 2.3</link> </td> </tr> </table> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/sample_servlet.xml Index: sample_servlet.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Servlet Sample</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Servlet Sample Application"> <p> Cactus provides a <link href="downloads.html">sample application</link> that shows how to write test cases for unit testing servlet methods. You should have a look at this sample application as it gives thorough example. However, this section only focuses on explaining the principle by showing a very simple example. </p> <p> For the sake of simplicity let's imagine we have a servlet called <code>SimpleServlet</code> which has a single method : </p> <ul> <li> <code>registerUser()</code> : Gets the user name from a HTTP request parameter, save it in the HTTP Session and send a Cookie back to the client with the user name in it. The returned HTML prints the name that was retrieved from the HTTP request's parameter. </li> </ul> <s2 title="Step 1 : The SimpleServlet's code"> <p> Here is the code to unit test : </p> <source><![CDATA[ package sample; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class SimpleServlet extends HttpServlet { public void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse) throws IOException { PrintWriter pw = theResponse.getWriter(); theResponse.setContentType("text/html"); pw.print("<html><head/><body>"); pw.print("<h1>Your name is " + registerUser(theRequest, theResponse) + "</h1>"); pw.print("</body></html>"); } public String registerUser(HttpServletRequest theRequest, HttpServletResponse theResponse) { // Get the user name from the HTTP request's parameter String name = theRequest.getParameter("USER_NAME"); // Save it in the session HttpSession session = theRequest.getSession(); session.putValue("NAME", name); // And return a cookie Cookie cookie = new Cookie("ID", name); theResponse.addCookie(cookie); return name; } } ]]></source> </s2> <s2 title="Step 2 : Unit testing strategy"> <p> Notice that we mentionned we were going to test the <code>registerUser()</code> method but nothing was said about the <code>doGet()</code> method ... Indeed, unit testing the <code>doGet()</code> (or <code>doPost()</code>) is not completely relevant. This kind of test is actually more a functional test (you can use a framework such as <link href="http://httpunit.sourceforge.net">HttpUnit</link> for doing this). However, for some simple cases it is not always easy to differentiate between unit test and functional test, you might want the test to be part of your unit test suite or it is a simple case that do not need to set up a functional test framework. For these cases, Cactus support asserting the output stream returned from your servlet, so it is possible to unit test the <code>doGet()</code> type methods, as demonstrated below. </p> <p> However, you should try to not put any logic in your <code>doGet</code> and <code>doPost()</code> methods. You should rather delegate any code logic to other methods (such as the <code>registerUser()</code> method is the sample below). It is called the facade pattern. If you do it this way, you can easily unit test your logic code methods one by one. </p> </s2> <s2 title="Step 3 : The test code"> <source><![CDATA[ public class TestSimpleServlet extends ServletTestCase { [standard JUnit code. See the using section] /** * Sets the HTTP request parameter that will be available in the test * method. */ public void beginRegisterUser(ServletTestRequest theRequest) { theRequest.addParameter("USER_NAME", "Vincent"); } /** * Unit test the registerUSer method. */ public void testRegisterUser() { // Instantiate the class to test SimpleServlet servlet = new SimpleServlet(); // Call the method to test String name = servlet.registerUser(request, response); // Verify that it returns the correct name assertEquals("Vincent", name); // Verify that the name has been put in the session assertEquals("Vincent", (String)session.getValue("NAME")); } /** * Verify that a cookie has been returned */ public void endRegisterUser(HttpURLConnection theConnection) { Hashtable cookies = AssertUtils.getCookies(theConnection); Vector list = (Vector)cookies.get("ID"); assert(list.size() == 1); ClientCookie cookie = (ClientCookie)list.elementAt(0); assertEquals("ID", cookie.getName()); assertEquals("Vincent", cookie.getValue()); } /** * Test the output stream returned by the <code>doGet()</code> method. */ public void testDoGet() { SimpleServlet servlet = new SimpleServlet(); servlet.doGet(request, response); } /** * Test the output stream returned by the <code>doGet()</code> method. */ public void endDoGet(HttpURLConnection theConnection) { assertEquals("<html><head/><body><h1>Your name is Vincent</h1></body></html>", AssertUtils.getResponseAsString(theConnection)); } } ]]></source> <note> Notice that in the <code>endRegisterUser()</code> and <code>endDoGet()</code> test methods we use methods from a helper class provided by Cactus to help retrieve cookies sent back from the servlet and to help assert the returned servlet output stream. </note> <note> For unanswered questions, see the section on <link href="using.html">using Cactus</link> and the <link href="faq.html">FAQ</link>. </note> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/servlets.xml Index: servlets.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Testing with servlet engines</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="How to run Cactus tests in your servlet engine"> <p> There are 2 parts in Cactus : </p> <ul> <li> <em>The Server part</em> : It must contain the following elements : <ul> <li> the classes you want to test, </li> <li> your Cactus test classes, </li> <li> the Cactus jar, </li> <li> the JUnit jar, </li> </ul> </li> <li> <em>The Client part</em> : It must contain the following elements : <ul> <li> your Cactus test classes, </li> <li> the Cactus jar, </li> <li> the Servlet API jar. This is needed because the <code>ServletTestCase</code> and <code>JspTestCase</code> classes use server objects. </li> <li> the <code>cactus.properties</code> Cactus configuration file, </li> <li> the JUnit jar, </li> </ul> </li> </ul> <p> The Server part is usually packaged as a war file that you put in your Servlet engine webapps directory. </p> <p> On the client side you simply need to put the above-mentionned classes in your <code>CLASSPATH</code> (don't forget to put the <code>cactus.properties</code> file in your <code>CLASSPATH</code>). You start running the tests by starting a JUnit runner (either the gui one or the text one). </p> </s1> <s1 title="Automating tests with your servlet engine and Ant"> <p> The strategy for automating the unit tests with Ant is made up of the following steps : </p> <ul> <li> <em>Step 1</em> : set up your servlet engine needed configuration files in your <code>out/</code> directory (see the <link href="ant.html">Ant tutorial</link> for the directory layout), </li> <li> <em>Step 2</em> : package your tests as a <code>.war</code> file and copy this war at a location in your <code>out/</code> directory where you servlet engine will find it, </li> <li> <em>Step 3</em> : start your servlet engine in another thread and wait for it to be started (by trying to open an HTTP connection on a test URL), </li> <li> <em>Step 4</em> : run the JUnit test runner on your test classes, </li> <li> <em>Step 5</em> : stop the running servlet engine </li> </ul> <p> The following targets need to be defined for performing these steps : </p> <table> <tr> <th> Target name </th> <th> Description </th> <th> Type </th> </tr> <tr> <td> <code>prepare_tests_<servlet engine name></code> </td> <td> Prepare the servlet engine needed configuration files </td> <td> Internal </td> </tr> <tr> <td> <code>testwar</code> </td> <td> Generate the test <code>.war</code> </td> <td> Internal </td> </tr> <tr> <td> <code>start_<servlet engine name></code> </td> <td> Starts the servlet engine </td> <td> Internal </td> </tr> <tr> <td> <code>tests</code> </td> <td> Start the JUnit test runner on the Cactus test classes </td> <td> Internal </td> </tr> <tr> <td> <code>stop_<servlet engine name></code> </td> <td> Stops the servlet engine </td> <td> Internal </td> </tr> <tr> <td> <code>tests_<servlet engine name></code> </td> <td> Run the tests for that servlet engine </td> <td> External </td> </tr> </table> <p> <br/> </p> <s2 title="Supported servlet engines"> <p> Cactus will work with any servlet engine that supports Servlet API 2.2 and above. The Cactus sample application provides Ant build scripts to automate running the tests for the following servlet engines : </p> <ul> <li> Tomcat 3.2 (script for Servlet API 2.2) </li> <li> Tomcat 4.0 (script for Servlet API 4.0) </li> <li> Resin 1.2.x (script for Servlet API 2.2) </li> <li> Resin 1.3.x (script for Servlet API 2.3) </li> <li> Orion 1.4.x (script for Servlet API 2.2) </li> <li> WebLogic 5.1 (script for Servlet API 2.2) </li> </ul> </s2> <s2 title="Step 1 : 'prepare_tests_<servlet engine name>' target"> <p> This step is very dependent on the servlet engine. Basically it consists in creating the needed directory structure in the <code>out/</code> directory and copy the configuration files located in <code>conf/test</code>. See the tutorial for your specific servlet engine. </p> <p> We also check here if the home directory of the servlet engine has been specified. If not, then the tests for that servlet engine are not run. </p> <p> It will look like (example for Resin) : </p> <source><![CDATA[ <!-- ======================================================================== Display a warning message if the needed servlet engine home property is not set ======================================================================== --> <target name="check_tests_resin_12" depends="testwar" unless="resin.home.12"> <echo message=""/> <echo message="*********************************************************"/> <echo message="WARNING : The 'resin.home.12' property has not been set."/> <echo message=" No test will be run on that servlet engine."/> <echo message="*********************************************************"/> <echo message=""/> </target> <!-- ======================================================================== Prepare directories and variables for running the tests ======================================================================== --> <target name="prepare_tests_resin_12" depends="check_tests_resin_12" if="resin.home.12"> <echo message="resin.home.12 = ${resin.home.12}"/> <property name="out.resin12.dir" value="${out.test.dir}/resin12"/> <property name="conf.resin12.dir" value="${conf.test.dir}/resin12"/> <mkdir dir="${out.resin12.dir}"/> <!-- Copy resin configuration files --> <copy file="${conf.resin12.dir}/resin.conf" tofile="${out.resin12.dir}/resin.conf"/> <!-- Create the war file --> <copy file="${out.test.dir}/test.war" tofile="${out.resin12.dir}/test.war"/> </target> ]]></source> </s2> <s2 title="Step 2 : 'testwar' target"> <p> Generate the war file containing classes to test and test classes. </p> <source><![CDATA[ <!-- ======================================================================== Create a test war file that includes the sample application unit tests ======================================================================== --> <target name="testwar" depends="compile"> <!-- Gather libraries --> <copy tofile="${out.lib.dir}/junit.jar" file="${junit.jar}"/> <copy tofile="${out.lib.dir}/cactus-22.jar" file="${cactus.jar}"/> <!-- Make sure the directory for the war exist --> <mkdir dir="${out.test.dir}"/> <!-- Create the war file --> <war warfile="${out.test.dir}/test.war" webxml="${conf.test.dir}/web.xml"> <classes dir="${out.classes.dir}"> <exclude name="cactus.properties"/> </classes> <!-- We need to copy the Cactus and JUnit jars in the war. This is because if we just put these jars in the global classpath for the Servlet engine, the Cactus jar might not be able to load the test case class as it loadable only by the war classloader --> <lib dir="${out.lib.dir}"> <include name="junit.jar"/> <include name="cactus-22.jar"/> </lib> <fileset dir="${web.dir}"/> </war> </target> ]]></source> <p> The <code>web.xml</code> need to contain the correct mapping for the Cactus Redirector servlet and Redirector JSP. See the <link href="installation.html">installation</link> tutorial. </p> </s2> <s2 title="Step 3 : 'start_<servlet engine name>' target"> <p> Again, this step depends on the servlet engine. The usual way to start the server is to use the Ant <code>java</code> task. See the tutorial for your specific servlet engine. </p> <p> Example (for Tomcat 3.2) : </p> <source><![CDATA[ <!-- ======================================================================== Start Tomcat 3.2 ======================================================================== --> <target name="start_tomcat_32"> <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> <arg value="-config"/> <arg value="${out.tomcat32.dir}/conf/server.xml"/> <classpath> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home.32}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> ]]></source> </s2> <s2 title="Step 4 : 'tests' target"> <p> Starts the JUnit tests : </p> <source><![CDATA[ <!-- ======================================================================== Run the client JUnit test cases. This target should not be called directly. It must be called by a test_XXX target (where XXX is the name of the server - see included xml file for different servers) ======================================================================== --> <target name="tests"> <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes"> <classpath> <pathelement path="${java.class.path}"/> <pathelement location="${servlet.jar}"/> <pathelement location="${cactus.jar}"/> <pathelement location="${out.classes.dir}"/> </classpath> <formatter type="plain" usefile="false"/> <!-- Define tests here --> <test name="cactus.sample.TestSampleServlet"/> <test name="cactus.sample.TestSampleServletConfig"/> </junit> </target> ]]></source> </s2> <s2 title="Step 5 : 'stop_<servlet engine name>' target"> <p> Again, this step depends on the servlet engine. The usual way to stop the server is to use the Ant <code>java</code> task. See the tutorial for your specific servlet engine. </p> <p> Example (for Tomcat 3.2) : </p> <source><![CDATA[ <!-- ======================================================================== Stop Tomcat 3.2 ======================================================================== --> <target name="stop_tomcat_32"> <java classname="org.apache.tomcat.startup.Tomcat" fork="yes"> <jvmarg value="-Dtomcat.home=${tomcat.home.32}"/> <arg value="-stop"/> <classpath> <pathelement location="${java.home}/../lib/tools.jar"/> <fileset dir="${tomcat.home.32}/lib"> <include name="*.jar"/> </fileset> </classpath> </java> </target> ]]></source> </s2> <s2 title="'tests_<servlet engine name>' target"> <p> This is the target that is called externally for starting the tests for a given servlet engine. It will call the <code>start_<servlet engine name></code> target in another thread, wait for the servlet engine to be started (by continously trying to connect to a URL), run the tests by calling the <code>tests</code> target and then stop the servlet engine by calling the <code>stop_<servlet engine name></code> target. It will also depend (in the Ant sense) on the <code>prepare_tests_<servlet engine name></code> and <code>testwar</code> targets to prepare the test environment. </p> <p> Cactus provides a custom Ant task (named <code>runservertests</code> hereafter) to do this. This task is located in the <code>cactus-ant.jar</code> file. Here is an example of using this task for running the tests in Tomcat : </p> <source><![CDATA[ <!-- ======================================================================== Run Tomcat 3.2 tests ======================================================================== --> <target name="tests_tomcat_32" depends="prepare_tests_tomcat_32" if="tomcat.home.32"> <!-- Start the servlet engine, wait for it to be started, run the unit tests, stop the servlet engine, wait for it to be stopped. The servlet engine is stopped if the tests fail for any reason --> <runservertests testURL="http://localhost:8080" startTarget="start_tomcat_32" stopTarget="stop_tomcat_32" testTarget="tests"/> </target> ]]></source> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/site-book.xml Index: site-book.xml =================================================================== <?xml version="1.0"?> <book software="Cactus" title="Cactus Documentation" copyright="@year@ The Apache Software Foundation"> <menu label="About"> <menu-item label="News" source="index.xml"/> <menu-item label="Features" source="features.xml"/> <menu-item label="Changes" source="changes.xml" type="changes"/> <menu-item label="Todo" source="todo.xml" type="todo"/> <menu-item label="Contributors" source="contributors.xml"/> </menu> <menu label="Downloads"> <menu-item label="Downloads" source="downloads.xml"/> </menu> <menu label="User Guides"> <menu-item label="Installation" source="installation.xml"/> <menu-item label="Installing Ant" source="installation_ant.xml"/> <menu-item label="Installing Sample" source="installation_sample.xml"/> <menu-item label="Configuration" source="configuration.xml"/> <menu-item label="Using" source="using.xml"/> <menu-item label="Servlet Sample" source="sample_servlet.xml"/> </menu> <menu label="Developer's Corner"> <menu-item label="Architecture" source="architecture.xml"/> <menu-item label="Ant integration" source="ant.xml"/> <menu-item label="Servlet Engines" source="servlets.xml"/> <menu-item label="API Reference" source="javadoc.xml"/> </menu> <menu label="Support"> <menu-item label="CVS" href="http://jakarta.apache.org/site/cvsindex.html" type="external"/> <menu-item label="Bug database" href="http://jakarta.apache.org/site/bugs.html" type="external"/> <menu-item label="Mailing lists" href="http://jakarta.apache.org/site/mail.html" type="external"/> <menu-item label="FAQ" href="http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayTopics/action/SetAll/project_id/2/faq_id/39" type="external"/> </menu> </book> 1.1 jakarta-commons/cactus/docs/framework/xdocs/todo.xml Index: todo.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE todo SYSTEM "./dtd/todo-v10.dtd"> <todo title="Things To Do for Cactus"> <devs> <person name="Vincent Massol" email="[EMAIL PROTECTED]" id="VMA"/> <person name="Philip Aston" email="[EMAIL PROTECTED]" id="PAS"/> <person name="P. Babu Naidu" email="[EMAIL PROTECTED]" id="BNA"/> </devs> <actions priority="medium"> <action context="docs"> Write a tutorial that shows how to test EJBs. </action> <action context="samples"> Add a sample that shows how to test EJBs. </action> <action context="design" assigned-to="VMA"> Add support for testing custom JSP Taglibs (suggested by Sohail Aslam) + tutorial + sample </action> <action context="design" assigned-to="VMA"> Add support for testing Servlet API 2.3 Filters. </action> <action context="docs" assigned-to="VMA"> Write a short "Testing strategy" tutorial that explains the different kind of tests and what tool to use for each kind. Speak about facade, MCV model. </action> </actions> <actions priority="low"> <action context="docs" assigned-to="VMA"> Add a page to the web site that explains the long term goals of Cactus: go as far as possible for testing server-side components but explain why this is limited and will fail in the long term as components benefit more and more from services provided by the container. The solution will be to provide testing API/SPI in the container specifications so that frameworks like Cactus can be plugged into the containers. Explain that one goal of Cactus is to make Tomcat/Sun aware of this and try to push in this direction. (Note: This is my view, verify if other share it or if I'm wrong in thinking in these terms). </action> <action context="code" assigned-to="PAS"> Modify the Ant <code>runservertest</code> task so that it also works when a servlet engine is already up and running (thanks to Philip Aston who requested and provided the code for this feature) </action> <action context="code"> Make the methods <code>setUp()</code> and <code>tearDown()</code> protected on the server side so that it is consistent with JUnit (for the moment they need to be public to work). </action> <action context="code"> Manage multivalued HTTP headers in <code>ServletTestRequest</code>. </action> <action context="docs"> Write a Cactus integration tutorial for JBuilder 4. </action> <action context="docs"> Write a Cactus integration tutorial for VAJava 3.5. </action> <action context="build"> Add Ant scripts to support WebLogic 6.0. </action> <action context="code" assigned-to="VMA"> Handle <code>getRealPath()</code>, <code>getPathTranslated()</code> in the <code>ServletRedirectorRequest</code> class. </action> <action context="admin" assigned-to="VMA"> On the Cactus news web page, provide a list of pages that have been recently modified so that end users can see at a glance what has changed recently on the web site. </action> <action context="build" assigned-to="VMA"> Generate changelog file from CVS change log information and put in the documentation of each release. </action> <action context="docs" assigned-to="VMA"> Add a license section to the Cactus web site that explains that Cactus is under the APL license and shows the license statement. </action> <action context="docs" assigned-to="VMA"> Add a contributing section to the Cactus web site (see the contributing section of Cocoon as a sample). </action> <action context="build" assigned-to="VMA"> On the documentation web pages (i.e. not the site web pages) add a sub header for each page with a message saying "Click here if you want to see the latest online version of this page". Modify a stylebook stylesheet to do this (combined with an Ant token filter or an Ant replace task). </action> <action context="code"> Add API in <code>ServletTestRequest</code> to send data to the URL connection output stream. This is to easily test code that sends bytes of data as POST data to the servlet (requested by Daniel Cohen and custommonkey). </action> <action context="code"> Automatically add the query string parameters defined when using the <code>ServletTestRequest.setURL()</code> API to the list of parameters passed to the server redirector, so that it won't be necessary to call <code>ServletTestRequest.addParameter()</code> for each of these parameters. </action> </actions> <actions priority="wish"> <action context="code"> Integration for Netbeans by integration with the Netbeans XTest module. </action> <action context="design" assigned-to="BNA"> Provide a mechanism for easier testing of EJBs. The mechanism is to be defined (requested by notyy). </action> </actions> </todo> 1.1 jakarta-commons/cactus/docs/framework/xdocs/using.xml Index: using.xml =================================================================== <?xml version="1.0"?> <!DOCTYPE document SYSTEM "./dtd/document-v10.dtd"> <document> <header> <title>Using Cactus</title> <authors> <person name="Vincent Massol" email="[EMAIL PROTECTED]"/> </authors> </header> <body> <s1 title="Tutorial for creating a Cactus Test Case"> <p> This section explains how to write a test case, using Cactus. </p> <s2 title="Step 1 : Imports"> <p> You need to include the following imports in your test class (this is because Cactus uses JUnit as the client side application for calling the tests) : </p> <source><![CDATA[ import org.apache.commons.cactus.*; import org.apache.commons.cactus.util.*; import junit.framework.*; ]]></source> </s2> <s2 title="Step 2 : Extend ServletTestCase or JspTestCase"> <p> Instead of extending TestCase as you would do if you were writing a JUnit test class, you need to extend <code>ServletTestCase</code> or <code>JspTestCase</code>. You would extend <code>ServletTestCase</code> to unit test servlet methods and <code>JspTestCase</code> to unit test simple custom JSP tags. </p> <source><![CDATA[ public class TestSampleServlet extends ServletTestCase { ]]></source> <p> or </p> <source><![CDATA[ public class TestSampleTag extends JspTestCase { ]]></source> </s2> <s2 title="Step 3 : Standard JUnit methods"> <p> Define the following standard JUnit methods : </p> <ul> <li> A constructor with a single parameter (it is the test name), </li> <li> A <code>main()</code> method in which you start a JUnit test runner if you want your test to be executable, </li> <li> A <code>suite()</code> method to list the tests that should be executed by your test class </li> </ul> <source><![CDATA[ public TestSampleServlet(String theName) { super(theName); } public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestSampleServlet.class.getName()}); } public static Test suite() { return new TestSuite(TestSampleServlet.class); } ]]></source> </s2> <s2 title="Step 4 : setUp() and tearDown() methods"> <p> As in JUnit, you can define a <code>setUp()</code> and a <code>tearDown()</code> methods. They are executed respectively before and after each test case. However, whereas in JUnit they are executed on the client side, in Cactus they are executed on the server side. It means that you will be able to access the Cactus implicit object (see step 6 below) within them. In other words, you'll be able to do things such as putting a value in the HTTP Session prior to calling the test cases, etc. </p> </s2> <s2 title="Step 5 : Signature of the test methods"> <p> This is where it is a bit different from JUnit ! For each test <code>XXX</code> that you want to implement you can define 3 methods (2 being optionals) : </p> <ul> <li> <code>void beginXXX(ServletTestRequest)</code> : This method is optional and should be used to set up some HTTP-request related parameters before your test case is executed. Whereas the <code>setUp()</code> method is global for all test cases, this method is only executed before the test case of the same name (i.e. <code>testXXX()</code>). This method is executed on the client side. </li> </ul> <p> The <code>ServletTestRequest</code> object passed to the <code>beginXXX()</code> method contains all the methods needed to set up the HTTP parameters. See the <link href="javadoc.html">javadoc</link> for <code>ServletTestRequest</code> for detailed information on the API. Here is a short summary : </p> <table> <tr> <th colspan="2"> <strong>ServletTestRequest</strong> </th> </tr> <tr> <td> <code>addCookie(String, String)</code> </td> <td> Adds a cookie to the list of cookies that will be available in <code>testXXX()</code>, <code>setUp()</code> and <code>tearDown()</code> using the <code>HttpServletRequest.getCookies()</code> API </td> </tr> <tr> <td> <code>addHeader(String, String)</code> </td> <td> Adds a HTTP header to the list of headers that will be available in <code>testXXX()</code>, <code>setUp()</code> and <code>tearDown()</code> using the <code>HttpServletRequest.getHeader()</code> API. </td> </tr> <tr> <td> <code>addParameter(String, String)</code> </td> <td> Adds a HTTP parameter to the list of parameters that will be available in <code>testXXX()</code>, <code>setUp()</code> and <code>tearDown()</code> using the <code>HttpServletRequest.getParameter()</code> API. </td> </tr> <tr> <td> <code>setAutomaticSession(boolean)</code> </td> <td> If <code>false</code>, no HTTP session wil be automatically created (i.e. the implicit <code>session</code> object will be <code>null</code>. See section 6 below for implicit objects). By default the value is <code>true</code>. </td> </tr> <tr> <td> <code>setURL(String, String, String, String, String)</code> </td> <td> If used, simulates a URL. From the point of view of your test case, it is as if your servlet were called by this URL instead of the Redirector servlet URL (see <link href="configuration.html">configuration</link>). The parameters are : server name (+ port number), context path, servlet path, path info, query string. </td> </tr> </table> <ul> <li> <code>void testXXX()</code> : This is the test method. In it, you will instantiate the class to test, call the method method and write the checking to verify that the test was successful using JUnit <code>asserts(..)</code>, <code>assertEquals(...)</code>, <code>fail(...)</code>, etc methods. </li> <li> <code>void endXXX(HttpURLConnection)</code> : This method is optional and should be used to test HTTP-response related values that might have been set by the tested method. For example, you might want to verify that a cookie was sent back to the client, that a HTTP header has been correctly set, the returned servlet output stream, etc. This method is executed on the client side. Cactus provides helper methods in the <code>org.apache.commons.cactus.util</code> package (download the <link href="downloads.xml">Cactus sample application</link> for example on how to use them) : <ul> <li> <em>AssertUtils.getCookies()</em> : retrieves all cookies sent back from the server side, </li> <li> <em>AssertUtils.getResponseAsString()</em> which returns the server output stream as a string that you can assert. </li> </ul> </li> </ul> <p> The <code>HttpURLConnection</code> object passed to this method is the standard <code>java.net.HttpURLConnection</code>. Thus you have access to all the standard API (<code>getHeaderField(), ...</code>) </p> </s2> <s2 title="Step 6 : Implicit objects"> <p> Depending on whether your test class extended <code>ServletTestCase</code> or <code>JspTestCase</code> you have access to different server-side objects. </p> <s3 title="Implicit objects provided by ServletTestCase"> <p> The following server-side objects are made available to your testXXX(), setUp() and tearDown() methods : </p> <ul> <li> <code>request</code> : This is the <code>HttpServletRequest</code> object. Actually, it is a modified <code>HttpServletRequest</code> that overrides some of the original <code>HttpServletRequest</code> methods in order to return the parts of the simulated URL that may have been set up in the <code>beginXXX()</code> method using the <code>ServletTestRequest.setURL()</code> method. The overridden methods are : <ul> <li> <code>HttpServletRequest.getServerName()</code>, </li> <li> <code>HttpServletRequest.getServerPort()</code>, </li> <li> <code>HttpServletRequest.getRequestURI()</code>, </li> <li> <code>HttpServletRequest.getContextPath()</code>, </li> <li> <code>HttpServletRequest.getServletPath()</code>, </li> <li> <code>HttpServletRequest.getQueryString()</code>, </li> <li> <code>HttpServletRequest.getPathInfo()</code> </li> </ul> </li> <li> <code>response</code> : This is the <code>HttpServletResponse</code> object that will be used to return the HTTP response to the client. </li> <li> <code>session</code> : This is the <code>HttpSession</code> object. It is created only if the automatic session creation is set to <code>true</code> (it is set using the <code>ServletTestRequest.setAutomaticSession(boolean)</code>), which is the default. If you have set it to <code>false</code> then the session's value is <code>null</code>. </li> <li> <code>config</code> : This is a <code>ServletConfig</code> object. It is the configuration that comes from the Redirector Servlet. Thus if you want to test a method that needs a <code>ServletConfig</code> object to retrieve some static configuration values, you should define these values in the <code>web.xml</code> mapping section for the Redirector Servlet. </li> </ul> </s3> <s3 title="Implicit objects provided by JspTestCase"> <p> All the implicit objects provided by <code>ServletTestCase</code> are also provided by <code>JspTestCase</code>. In addition, the following implicit objects are also provided : </p> <ul> <li> <code>pageContext</code> : This is a <code>PageContext</code> object. It is the page context implicit object available in any JSP page. </li> <li> <code>out</code> : This is a <code>JspWriter</code> object. It is the out implicit object available in any JSP page. You should this object to write data in the output stream. </li> </ul> </s3> <s3 title="Additional methods provided by some implicit objects"> <p> Implicit objects are actually subclasses of standard servlet objects and provides additional methods to help unit test your code : </p> <ul> <li> Using the <code>config</code> implicit object : <ul> <li> <code>setInitParameter(String, String)</code> : sets a parameter as if it were set in the <code>web.xml</code> file using an <code>init-param</code> tag, </li> <li> <code>setServletName(String)</code> : sets the servlet name. This is the value that is returned by a call to <code>getServletName()</code> </li> </ul> </li> </ul> </s3> </s2> <s2 title="Step 7 : Writing the test methods"> <p> You write your test methods the same way as you do in JUnit, instanciating the class to test, calling it's method to test and doing asserts to verify the results. The only difference from JUnit is that you can use the implicit objects defined in step 6. </p> </s2> </s1> </body> </document> 1.1 jakarta-commons/cactus/docs/framework/xdocs/dtd/changes-v10.dtd Index: changes-v10.dtd =================================================================== <!-- =================================================================== Apache Changes DTD (Version 1.0) PURPOSE: This DTD was developed to create a simple yet powerful document type for software development changes for use with the Apache projects. It is an XML-compliant DTD and it's maintained by the Apache XML project. TYPICAL INVOCATION: <!DOCTYPE document PUBLIC "-//APACHE//DTD Changes Vx.yz//EN" "http://xml.apache.org/DTD/changes-vxyz.dtd"> where x := major version y := minor version z := status identifier (optional) NOTES: It is important, expecially in open developped software projects, to keep track of software changes both to give users indications of bugs that might have been resolved, as well, and not less important, to provide credits for the support given to the project. It is considered vital to provide adequate payback using recognition and credits to let users and developers feel part of the community, thus increasing development power. AUTHORS: Stefano Mazzocchi <[EMAIL PROTECTED]> FIXME: CHANGE HISTORY: 19991129 Initial version. (SM) 20000316 Added bugfixing attribute. (SM) COPYRIGHT: Copyright (c) @year@ The Apache Software Foundation. Permission to copy in any form is granted provided this notice is included in all copies. Permission to redistribute is granted provided this file is distributed untouched in all its parts and included files. ==================================================================== --> <!-- =============================================================== --> <!-- Extend the Documentation DTD --> <!-- =============================================================== --> <!-- FIXME (SM): this is hardcoding. Find a better way of doing this possibly using public identifiers --> <!ENTITY % document-dtd SYSTEM "document-v10.dtd"> %document-dtd; <!-- =============================================================== --> <!-- Common entities --> <!-- =============================================================== --> <!ENTITY % types "add|remove|update|fix"> <!-- =============================================================== --> <!-- Document Type Definition --> <!-- =============================================================== --> <!ELEMENT changes (devs, release*)> <!ATTLIST changes %common.att; %title.att;> <!ELEMENT devs (person+)> <!ATTLIST devs %common.att;> <!ELEMENT release (action+)> <!ATTLIST release %common.att; version CDATA #REQUIRED date CDATA #REQUIRED> <!ELEMENT action (%content.mix;)*> <!ATTLIST action %common.att; dev IDREF #REQUIRED type (%types;) #IMPLIED due-to CDATA #IMPLIED due-to-email CDATA #IMPLIED fixes-bug CDATA #IMPLIED> <!-- =============================================================== --> <!-- End of DTD --> <!-- =============================================================== --> 1.1 jakarta-commons/cactus/docs/framework/xdocs/dtd/characters.ent Index: characters.ent =================================================================== <!-- Portions (C) International Organization for Standardization 1986 Permission to copy in any form is granted for use with conforming SGML systems and applications as defined in ISO 8879, provided this notice is included in all copies. --> <!-- Character entity set. --> <!-- Latin A --> <!ENTITY nbsp " "> <!-- U+00A0 ISOnum - no-break space = non-breaking space --> <!ENTITY iexcl "¡"> <!-- U+00A1 ISOnum - inverted exclamation mark --> <!ENTITY cent "¢"> <!-- U+00A2 ISOnum - cent sign --> <!ENTITY pound "£"> <!-- U+00A3 ISOnum - pound sign --> <!ENTITY curren "¤"> <!-- U+00A4 ISOnum - currency sign --> <!ENTITY yen "¥"> <!-- U+00A5 ISOnum - yen sign = yuan sign --> <!ENTITY brvbar "¦"> <!-- U+00A6 ISOnum - broken bar = broken vertical bar --> <!ENTITY sect "§"> <!-- U+00A7 ISOnum - section sign --> <!ENTITY uml "¨"> <!-- U+00A8 ISOdia - diaeresis = spacing diaeresis --> <!ENTITY copy "©"> <!-- U+00A9 ISOnum - copyright sign --> <!ENTITY ordf "ª"> <!-- U+00AA ISOnum - feminine ordinal indicator --> <!ENTITY laquo "«"> <!-- U+00AB ISOnum - left-pointing double angle quotation mark = left pointing guillemet --> <!ENTITY not "¬"> <!-- U+00AC ISOnum - not sign --> <!ENTITY shy "­"> <!-- U+00AD ISOnum - soft hyphen = discretionary hyphen --> <!ENTITY reg "®"> <!-- U+00AE ISOnum - registered sign = registered trade mark sign --> <!ENTITY macr "¯"> <!-- U+00AF ISOdia - macron = spacing macron = overline = APL overbar --> <!ENTITY deg "°"> <!-- U+00B0 ISOnum - degree sign --> <!ENTITY plusmn "±"> <!-- U+00B1 ISOnum - plus-minus sign = plus-or-minus sign --> <!ENTITY sup2 "²"> <!-- U+00B2 ISOnum - superscript two = superscript digit two = squared --> <!ENTITY sup3 "³"> <!-- U+00B3 ISOnum - superscript three = superscript digit three = cubed --> <!ENTITY acute "´"> <!-- U+00B4 ISOdia - acute accent = spacing acute --> <!ENTITY micro "µ"> <!-- U+00B5 ISOnum - micro sign --> <!ENTITY para "¶"> <!-- U+00B6 ISOnum - pilcrow sign = paragraph sign --> <!ENTITY middot "·"> <!-- U+00B7 ISOnum - middle dot = Georgian comma = Greek middle dot --> <!ENTITY cedil "¸"> <!-- U+00B8 ISOdia - cedilla = spacing cedilla --> <!ENTITY sup1 "¹"> <!-- U+00B9 ISOnum - superscript one = superscript digit one --> <!ENTITY ordm "º"> <!-- U+00BA ISOnum - masculine ordinal indicator --> <!ENTITY raquo "»"> <!-- U+00BB ISOnum - right-pointing double angle quotation mark = right pointing guillemet --> <!ENTITY frac14 "¼"> <!-- U+00BC ISOnum - vulgar fraction one quarter = fraction one quarter --> <!ENTITY frac12 "½"> <!-- U+00BD ISOnum - vulgar fraction one half = fraction one half --> <!ENTITY frac34 "¾"> <!-- U+00BE ISOnum - vulgar fraction three quarters = fraction three quarters --> <!ENTITY iquest "¿"> <!-- U+00BF ISOnum - inverted question mark = turned question mark --> <!ENTITY Agrave "À"> <!-- U+00C0 ISOlat1 - latin capital letter A with grave = latin capital letter A grave --> <!ENTITY Aacute "Á"> <!-- U+00C1 ISOlat1 - latin capital letter A with acute --> <!ENTITY Acirc "Â"> <!-- U+00C2 ISOlat1 - latin capital letter A with circumflex --> <!ENTITY Atilde "Ã"> <!-- U+00C3 ISOlat1 - latin capital letter A with tilde --> <!ENTITY Auml "Ä"> <!-- U+00C4 ISOlat1 - latin capital letter A with diaeresis --> <!ENTITY Aring "Å"> <!-- U+00C5 ISOlat1 - latin capital letter A with ring above = latin capital letter A ring --> <!ENTITY AElig "Æ"> <!-- U+00C6 ISOlat1 - latin capital letter AE = latin capital ligature AE --> <!ENTITY Ccedil "Ç"> <!-- U+00C7 ISOlat1 - latin capital letter C with cedilla --> <!ENTITY Egrave "È"> <!-- U+00C8 ISOlat1 - latin capital letter E with grave --> <!ENTITY Eacute "É"> <!-- U+00C9 ISOlat1 - latin capital letter E with acute --> <!ENTITY Ecirc "Ê"> <!-- U+00CA ISOlat1 - latin capital letter E with circumflex --> <!ENTITY Euml "Ë"> <!-- U+00CB ISOlat1 - latin capital letter E with diaeresis --> <!ENTITY Igrave "Ì"> <!-- U+00CC ISOlat1 - latin capital letter I with grave --> <!ENTITY Iacute "Í"> <!-- U+00CD ISOlat1 - latin capital letter I with acute --> <!ENTITY Icirc "Î"> <!-- U+00CE ISOlat1 - latin capital letter I with circumflex --> <!ENTITY Iuml "Ï"> <!-- U+00CF ISOlat1 - latin capital letter I with diaeresis --> <!ENTITY ETH "Ð"> <!-- U+00D0 ISOlat1 - latin capital letter ETH --> <!ENTITY Ntilde "Ñ"> <!-- U+00D1 ISOlat1 - latin capital letter N with tilde --> <!ENTITY Ograve "Ò"> <!-- U+00D2 ISOlat1 - latin capital letter O with grave --> <!ENTITY Oacute "Ó"> <!-- U+00D3 ISOlat1 - latin capital letter O with acute --> <!ENTITY Ocirc "Ô"> <!-- U+00D4 ISOlat1 - latin capital letter O with circumflex --> <!ENTITY Otilde "Õ"> <!-- U+00D5 ISOlat1 - latin capital letter O with tilde --> <!ENTITY Ouml "Ö"> <!-- U+00D6 ISOlat1 - latin capital letter O with diaeresis --> <!ENTITY times "×"> <!-- U+00D7 ISOnum - multiplication sign --> <!ENTITY Oslash "Ø"> <!-- U+00D8 ISOlat1 - latin capital letter O with stroke = latin capital letter O slash --> <!ENTITY Ugrave "Ù"> <!-- U+00D9 ISOlat1 - latin capital letter U with grave --> <!ENTITY Uacute "Ú"> <!-- U+00DA ISOlat1 - latin capital letter U with acute --> <!ENTITY Ucirc "Û"> <!-- U+00DB ISOlat1 - latin capital letter U with circumflex --> <!ENTITY Uuml "Ü"> <!-- U+00DC ISOlat1 - latin capital letter U with diaeresis --> <!ENTITY Yacute "Ý"> <!-- U+00DD ISOlat1 - latin capital letter Y with acute --> <!ENTITY THORN "Þ"> <!-- U+00DE ISOlat1 - latin capital letter THORN --> <!ENTITY szlig "ß"> <!-- U+00DF ISOlat1 - latin small letter sharp s = ess-zed --> <!ENTITY agrave "à"> <!-- U+00E0 ISOlat1 - latin small letter a with grave = latin small letter a grave --> <!ENTITY aacute "á"> <!-- U+00E1 ISOlat1 - latin small letter a with acute --> <!ENTITY acirc "â"> <!-- U+00E2 ISOlat1 - latin small letter a with circumflex --> <!ENTITY atilde "ã"> <!-- U+00E3 ISOlat1 - latin small letter a with tilde --> <!ENTITY auml "ä"> <!-- U+00E4 ISOlat1 - latin small letter a with diaeresis --> <!ENTITY aring "å"> <!-- U+00E5 ISOlat1 - latin small letter a with ring above = latin small letter a ring --> <!ENTITY aelig "æ"> <!-- U+00E6 ISOlat1 - latin small letter ae = latin small ligature ae --> <!ENTITY ccedil "ç"> <!-- U+00E7 ISOlat1 - latin small letter c with cedilla --> <!ENTITY egrave "è"> <!-- U+00E8 ISOlat1 - latin small letter e with grave --> <!ENTITY eacute "é"> <!-- U+00E9 ISOlat1 - latin small letter e with acute --> <!ENTITY ecirc "ê"> <!-- U+00EA ISOlat1 - latin small letter e with circumflex --> <!ENTITY euml "ë"> <!-- U+00EB ISOlat1 - latin small letter e with diaeresis --> <!ENTITY igrave "ì"> <!-- U+00EC ISOlat1 - latin small letter i with grave --> <!ENTITY iacute "í"> <!-- U+00ED ISOlat1 - latin small letter i with acute --> <!ENTITY icirc "î"> <!-- U+00EE ISOlat1 - latin small letter i with circumflex --> <!ENTITY iuml "ï"> <!-- U+00EF ISOlat1 - latin small letter i with diaeresis --> <!ENTITY eth "ð"> <!-- U+00F0 ISOlat1 - latin small letter eth --> <!ENTITY ntilde "ñ"> <!-- U+00F1 ISOlat1 - latin small letter n with tilde --> <!ENTITY ograve "ò"> <!-- U+00F2 ISOlat1 - latin small letter o with grave --> <!ENTITY oacute "ó"> <!-- U+00F3 ISOlat1 - latin small letter o with acute --> <!ENTITY ocirc "ô"> <!-- U+00F4 ISOlat1 - latin small letter o with circumflex --> <!ENTITY otilde "õ"> <!-- U+00F5 ISOlat1 - latin small letter o with tilde --> <!ENTITY ouml "ö"> <!-- U+00F6 ISOlat1 - latin small letter o with diaeresis --> <!ENTITY divide "÷"> <!-- U+00F7 ISOnum - division sign --> <!ENTITY oslash "ø"> <!-- U+00F8 ISOlat1 - latin small letter o with stroke = latin small letter o slash --> <!ENTITY ugrave "ù"> <!-- U+00F9 ISOlat1 - latin small letter u with grave --> <!ENTITY uacute "ú"> <!-- U+00FA ISOlat1 - latin small letter u with acute --> <!ENTITY ucirc "û"> <!-- U+00FB ISOlat1 - latin small letter u with circumflex --> <!ENTITY uuml "ü"> <!-- U+00FC ISOlat1 - latin small letter u with diaeresis --> <!ENTITY yacute "ý"> <!-- U+00FD ISOlat1 - latin small letter y with acute --> <!ENTITY thorn "þ"> <!-- U+00FE ISOlat1 - latin small letter thorn --> <!ENTITY yuml "ÿ"> <!-- U+00FF ISOlat1 - latin small letter y with diaeresis --> <!-- Latin Extended-A --> <!ENTITY OElig "Œ"> <!-- U+0152 ISOlat2 - latin capital ligature OE --> <!ENTITY oelig "œ"> <!-- U+0153 ISOlat2 - latin small ligature oe --> <!-- ligature is a misnomer, this is a separate character in some languages --> <!ENTITY Scaron "Š"> <!-- U+0160 ISOlat2 - latin capital letter S with caron --> <!ENTITY scaron "š"> <!-- U+0161 ISOlat2 - latin small letter s with caron --> <!ENTITY Yuml "Ÿ"> <!-- U+0178 ISOlat2 - latin capital letter Y with diaeresis --> <!-- Spacing Modifier Letters --> <!ENTITY circ "ˆ"> <!-- U+02C6 ISOpub - modifier letter circumflex accent --> <!ENTITY tilde "˜"> <!-- U+02DC ISOdia - small tilde --> <!-- General Punctuation --> <!ENTITY ensp " "> <!-- U+2002 ISOpub - en space --> <!ENTITY emsp " "> <!-- U+2003 ISOpub - em space --> <!ENTITY thinsp " "> <!-- U+2009 ISOpub - thin space --> <!ENTITY zwnj "‌"> <!-- U+200C RFC 2070 - zero width non-joiner --> <!ENTITY zwj "‍"> <!-- U+200D RFC 2070 - zero width joiner --> <!ENTITY lrm "‎"> <!-- U+200E RFC 2070 - left-to-right mark --> <!ENTITY rlm "‏"> <!-- U+200F RFC 2070 - right-to-left mark --> <!ENTITY ndash "–"> <!-- U+2013 ISOpub - en dash --> <!ENTITY mdash "—"> <!-- U+2014 ISOpub - em dash --> <!ENTITY lsquo "‘"> <!-- U+2018 ISOnum - left single quotation mark --> <!ENTITY rsquo "’"> <!-- U+2019 ISOnum - right single quotation mark --> <!ENTITY sbquo "‚"> <!-- U+201A NEW - single low-9 quotation mark --> <!ENTITY ldquo "“"> <!-- U+201C ISOnum - left double quotation mark --> <!ENTITY rdquo "”"> <!-- U+201D ISOnum - right double quotation mark, --> <!ENTITY bdquo "„"> <!-- U+201E NEW - double low-9 quotation mark --> <!ENTITY dagger "†"> <!-- U+2020 ISOpub - dagger --> <!ENTITY Dagger "‡"> <!-- U+2021 ISOpub - double dagger --> <!ENTITY permil "‰"> <!-- U+2030 ISOtech - per mille sign --> <!ENTITY lsaquo "‹"> <!-- U+2039 ISO prop. - single left-pointing angle quotation mark --> <!-- lsaquo is proposed but not yet ISO standardized --> <!ENTITY rsaquo "›"> <!-- U+203A ISO prop. - single right-pointing angle quotation mark --> <!-- rsaquo is proposed but not yet ISO standardized --> <!ENTITY euro "€"> <!-- U+20AC NEW - euro sign --> <!-- Latin Extended-B --> <!ENTITY fnof "ƒ"> <!-- U+0192 ISOtech - latin small f with hook = function = florin --> <!-- Greek --> <!ENTITY Alpha "Α"> <!-- U+0391 - greek capital letter alpha --> <!ENTITY Beta "Β"> <!-- U+0392 - greek capital letter beta --> <!ENTITY Gamma "Γ"> <!-- U+0393 ISOgrk3 - greek capital letter gamma --> <!ENTITY Delta "Δ"> <!-- U+0394 ISOgrk3 - greek capital letter delta --> <!ENTITY Epsilon "Ε"> <!-- U+0395 - greek capital letter epsilon --> <!ENTITY Zeta "Ζ"> <!-- U+0396 - greek capital letter zeta --> <!ENTITY Eta "Η"> <!-- U+0397 - greek capital letter eta --> <!ENTITY Theta "Θ"> <!-- U+0398 ISOgrk3 - greek capital letter theta --> <!ENTITY Iota "Ι"> <!-- U+0399 - greek capital letter iota --> <!ENTITY Kappa "Κ"> <!-- U+039A - greek capital letter kappa --> <!ENTITY Lambda "Λ"> <!-- U+039B ISOgrk3 - greek capital letter lambda --> <!ENTITY Mu "Μ"> <!-- U+039C - greek capital letter mu --> <!ENTITY Nu "Ν"> <!-- U+039D - greek capital letter nu --> <!ENTITY Xi "Ξ"> <!-- U+039E ISOgrk3 - greek capital letter xi --> <!ENTITY Omicron "Ο"> <!-- U+039F - greek capital letter omicron --> <!ENTITY Pi "Π"> <!-- U+03A0 ISOgrk3 - greek capital letter pi --> <!ENTITY Rho "Ρ"> <!-- U+03A1 - greek capital letter rho --> <!ENTITY Sigma "Σ"> <!-- U+03A3 ISOgrk3 - greek capital letter sigma --> <!ENTITY Tau "Τ"> <!-- U+03A4 - greek capital letter tau --> <!ENTITY Upsilon "Υ"> <!-- U+03A5 ISOgrk3 - greek capital letter upsilon --> <!ENTITY Phi "Φ"> <!-- U+03A6 ISOgrk3 - greek capital letter phi --> <!ENTITY Chi "Χ"> <!-- U+03A7 - greek capital letter chi --> <!ENTITY Psi "Ψ"> <!-- U+03A8 ISOgrk3 - greek capital letter psi --> <!ENTITY Omega "Ω"> <!-- U+03A9 ISOgrk3 - greek capital letter omega --> <!ENTITY alpha "α"> <!-- U+03B1 ISOgrk3 - greek small letter alpha --> <!ENTITY beta "β"> <!-- U+03B2 ISOgrk3 - greek small letter beta --> <!ENTITY gamma "γ"> <!-- U+03B3 ISOgrk3 - greek small letter gamma --> <!ENTITY delta "δ"> <!-- U+03B4 ISOgrk3 - greek small letter delta --> <!ENTITY epsilon "ε"> <!-- U+03B5 ISOgrk3 - greek small letter epsilon --> <!ENTITY zeta "ζ"> <!-- U+03B6 ISOgrk3 - greek small letter zeta --> <!ENTITY eta "η"> <!-- U+03B7 ISOgrk3 - greek small letter eta --> <!ENTITY theta "θ"> <!-- U+03B8 ISOgrk3 - greek small letter theta --> <!ENTITY iota "ι"> <!-- U+03B9 ISOgrk3 - greek small letter iota --> <!ENTITY kappa "κ"> <!-- U+03BA ISOgrk3 - greek small letter kappa --> <!ENTITY lambda "λ"> <!-- U+03BB ISOgrk3 - greek small letter lambda --> <!ENTITY mu "μ"> <!-- U+03BC ISOgrk3 - greek small letter mu --> <!ENTITY nu "ν"> <!-- U+03BD ISOgrk3 - greek small letter nu --> <!ENTITY xi "ξ"> <!-- U+03BE ISOgrk3 - greek small letter xi --> <!ENTITY omicron "ο"> <!-- U+03BF NEW - greek small letter omicron --> <!ENTITY pi "π"> <!-- U+03C0 ISOgrk3 - greek small letter pi --> <!ENTITY rho "ρ"> <!-- U+03C1 ISOgrk3 - greek small letter rho --> <!ENTITY sigmaf "ς"> <!-- U+03C2 ISOgrk3 - greek small letter final sigma --> <!ENTITY sigma "σ"> <!-- U+03C3 ISOgrk3 - greek small letter sigma --> <!ENTITY tau "τ"> <!-- U+03C4 ISOgrk3 - greek small letter tau --> <!ENTITY upsilon "υ"> <!-- U+03C5 ISOgrk3 - greek small letter upsilon --> <!ENTITY phi "φ"> <!-- U+03C6 ISOgrk3 - greek small letter phi --> <!ENTITY chi "χ"> <!-- U+03C7 ISOgrk3 - greek small letter chi --> <!ENTITY psi "ψ"> <!-- U+03C8 ISOgrk3 - greek small letter psi --> <!ENTITY omega "ω"> <!-- U+03C9 ISOgrk3 - greek small letter omega --> <!ENTITY thetasym "ϑ"> <!-- U+03D1 NEW - greek small letter theta symbol --> <!ENTITY upsih "ϒ"> <!-- U+03D2 NEW - greek upsilon with hook symbol --> <!ENTITY piv "ϖ"> <!-- U+03D6 ISOgrk3 - greek pi symbol --> <!-- General Punctuation --> <!ENTITY bull "•"> <!-- U+2022 ISOpub - bullet = black small circle --> <!ENTITY hellip "…"> <!-- U+2026 ISOpub - horizontal ellipsis = three dot leader --> <!ENTITY prime "′"> <!-- U+2032 ISOtech - prime = minutes = feet --> <!ENTITY Prime "″"> <!-- U+2033 ISOtech - double prime = seconds = inches --> <!ENTITY oline "‾"> <!-- U+203E NEW - overline = spacing overscore --> <!ENTITY frasl "⁄"> <!-- U+2044 NEW - fraction slash --> <!-- Letterlike Symbols --> <!ENTITY weierp "℘"> <!-- U+2118 ISOamso - script capital P = power set = Weierstrass p --> <!ENTITY image "ℑ"> <!-- U+2111 ISOamso - blackletter capital I = imaginary part --> <!ENTITY real "ℜ"> <!-- U+211C ISOamso - blackletter capital R = real part symbol --> <!ENTITY trade "™"> <!-- U+2122 ISOnum - trade mark sign --> <!ENTITY alefsym "ℵ"> <!-- U+2135 NEW - alef symbol = first transfinite cardinal --> <!-- Arrows --> <!ENTITY larr "←"> <!-- U+2190 ISOnum - leftwards arrow --> <!ENTITY uarr "↑"> <!-- U+2191 ISOnum - upwards arrow --> <!ENTITY rarr "→"> <!-- U+2192 ISOnum - rightwards arrow --> <!ENTITY darr "↓"> <!-- U+2193 ISOnum - downwards arrow --> <!ENTITY harr "↔"> <!-- U+2194 ISOamsa - left right arrow --> <!ENTITY crarr "↵"> <!-- U+21B5 NEW - downwards arrow with corner leftwards = carriage return --> <!ENTITY lArr "⇐"> <!-- U+21D0 ISOtech - leftwards double arrow --> <!ENTITY uArr "⇑"> <!-- U+21D1 ISOamsa - upwards double arrow --> <!ENTITY rArr "⇒"> <!-- U+21D2 ISOtech - rightwards double arrow --> <!ENTITY dArr "⇓"> <!-- U+21D3 ISOamsa - downwards double arrow --> <!ENTITY hArr "⇔"> <!-- U+21D4 ISOamsa - left right double arrow --> <!-- Mathematical Operators --> <!ENTITY forall "∀"> <!-- U+2200 ISOtech - for all --> <!ENTITY part "∂"> <!-- U+2202 ISOtech - partial differential --> <!ENTITY exist "∃"> <!-- U+2203 ISOtech - there exists --> <!ENTITY empty "∅"> <!-- U+2205 ISOamso - empty set = null set = diameter --> <!ENTITY nabla "∇"> <!-- U+2207 ISOtech - nabla = backward difference --> <!ENTITY isin "∈"> <!-- U+2208 ISOtech - element of --> <!ENTITY notin "∉"> <!-- U+2209 ISOtech - not an element of --> <!ENTITY ni "∋"> <!-- U+220B ISOtech - contains as member --> <!ENTITY prod "∏"> <!-- U+220F ISOamsb - n-ary product = product sign --> <!ENTITY sum "∑"> <!-- U+2211 ISOamsb - n-ary sumation --> <!ENTITY minus "−"> <!-- U+2212 ISOtech - minus sign --> <!ENTITY lowast "∗"> <!-- U+2217 ISOtech - asterisk operator --> <!ENTITY radic "√"> <!-- U+221A ISOtech - square root = radical sign --> <!ENTITY prop "∝"> <!-- U+221D ISOtech - proportional to --> <!ENTITY infin "∞"> <!-- U+221E ISOtech - infinity --> <!ENTITY ang "∠"> <!-- U+2220 ISOamso - angle --> <!ENTITY and "∧"> <!-- U+2227 ISOtech - logical and = wedge --> <!ENTITY or "∨"> <!-- U+2228 ISOtech - logical or = vee --> <!ENTITY cap "∩"> <!-- U+2229 ISOtech - intersection = cap --> <!ENTITY cup "∪"> <!-- U+222A ISOtech - union = cup --> <!ENTITY int "∫"> <!-- U+222B ISOtech - integral --> <!ENTITY there4 "∴"> <!-- U+2234 ISOtech - therefore --> <!ENTITY sim "∼"> <!-- U+223C ISOtech - tilde operator = varies with = similar to --> <!ENTITY cong "≅"> <!-- U+2245 ISOtech - approximately equal to --> <!ENTITY asymp "≈"> <!-- U+2248 ISOamsr - almost equal to = asymptotic to --> <!ENTITY ne "≠"> <!-- U+2260 ISOtech - not equal to --> <!ENTITY equiv "≡"> <!-- U+2261 ISOtech - identical to --> <!ENTITY le "≤"> <!-- U+2264 ISOtech - less-than or equal to --> <!ENTITY ge "≥"> <!-- U+2265 ISOtech - greater-than or equal to --> <!ENTITY sub "⊂"> <!-- U+2282 ISOtech - subset of --> <!ENTITY sup "⊃"> <!-- U+2283 ISOtech - superset of --> <!ENTITY nsub "⊄"> <!-- U+2284 ISOamsn - not a subset of --> <!ENTITY sube "⊆"> <!-- U+2286 ISOtech - subset of or equal to --> <!ENTITY supe "⊇"> <!-- U+2287 ISOtech - superset of or equal to --> <!ENTITY oplus "⊕"> <!-- U+2295 ISOamsb - circled plus = direct sum --> <!ENTITY otimes "⊗"> <!-- U+2297 ISOamsb - circled times = vector product --> <!ENTITY perp "⊥"> <!-- U+22A5 ISOtech - up tack = orthogonal to = perpendicular --> <!ENTITY sdot "⋅"> <!-- U+22C5 ISOamsb - dot operator --> <!-- Miscellaneous Technical --> <!ENTITY lceil "⌈"> <!-- U+2308 ISOamsc - left ceiling = apl upstile --> <!ENTITY rceil "⌉"> <!-- U+2309 ISOamsc - right ceiling --> <!ENTITY lfloor "⌊"> <!-- U+230A ISOamsc - left floor = apl downstile --> <!ENTITY rfloor "⌋"> <!-- U+230B ISOamsc - right floor --> <!ENTITY lang "〈"> <!-- U+2329 ISOtech - left-pointing angle bracket = bra --> <!ENTITY rang "〉"> <!-- U+232A ISOtech - right-pointing angle bracket = ket --> <!-- Geometric Shapes --> <!ENTITY loz "◊"> <!-- U+25CA ISOpub - lozenge --> <!-- Miscellaneous Symbols --> <!ENTITY spades "♠"> <!-- U+2660 ISOpub - black spade suit --> <!ENTITY clubs "♣"> <!-- U+2663 ISOpub - black club suit = shamrock --> <!ENTITY hearts "♥"> <!-- U+2665 ISOpub - black heart suit = valentine --> <!ENTITY diams "♦"> <!-- U+2666 ISOpub - black diamond suit --> 1.1 jakarta-commons/cactus/docs/framework/xdocs/dtd/document-v10.dtd Index: document-v10.dtd =================================================================== <!-- =================================================================== Apache Documentation DTD (Version 1.0) PURPOSE: This DTD was developed to create a simple yet powerful document type for software documentation for use with the Apache projects. It is an XML-compliant DTD and it's maintained by the Apache XML project. TYPICAL INVOCATION: <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation Vx.yz//EN" "http://xml.apache.org/DTD/document-vxyz.dtd"> where x := major version y := minor version z := status identifier (optional) NOTES: Many of the design patterns used in this DTD were take from the W3C XML Specification DTD edited by Eve Maler <[EMAIL PROTECTED]>. Where possible, great care has been used to reutilize HTML tag names to reduce learning efforts and to allow HTML editors to be used for complex authorings like tables and lists. AUTHORS: Stefano Mazzocchi <[EMAIL PROTECTED]> Berin Loritsch <[EMAIL PROTECTED]> FIXME: - how can we include char entities without hardwiring them? - should "form" tags be included? - should all style-free HTML 4.0 markup tags be included? - how do we handle the idea of "soft" xlinks? - should we add "soft" links to images? CHANGE HISTORY: 19991121 Initial version. (SM) 19991123 Replaced "res" with more standard "strong" for emphasis. (SM) 19991124 Added "fork" element for window forking behavior. (SM) 19991124 Added "img-inline" element to separate from "img". (SM) 19991129 Removed "affiliation" from "author". (SM) 19991129 Made "author" empty and moved "name|email" as attributes (SM) 19991215 Simplified table section (SM) 19991215 Changed "img-block" in more friendly "figure" (SM) 20000125 Added the "icon" image (SM) 20000126 Allowed "anchor" in all levels (SM) 20000404 Removed the "role" attribute from common-xxx.att (SM) 20000606 Allowed nested markup tags (SM) 20000911 Allowed link tags inside markup (BL) COPYRIGHT: Copyright (c) 1999-2000 The Apache Software Foundation. Permission to copy in any form is granted provided this notice is included in all copies. Permission to redistribute is granted provided this file is distributed untouched in all its parts and included files. ==================================================================== --> <!-- =============================================================== --> <!-- Common character entities (included from external file) --> <!-- =============================================================== --> <!-- FIXME (SM): this is hardcoding. Find a better way of doing this possibly using public identifiers of ISO latin char sets --> <!ENTITY % charEntity SYSTEM "characters.ent"> %charEntity; <!-- =============================================================== --> <!-- Userful entitieis for increased DTD readability --> <!-- =============================================================== --> <!ENTITY % text "#PCDATA"> <!-- =============================================================== --> <!-- Entities for general XML compliance --> <!-- =============================================================== --> <!-- Common attributes Every element has an ID attribute (sometimes required, but usually optional) for links. %common.att; is for common attributes where the ID is optional, and %common-idreq.att; is for common attributes where the ID is required. --> <!ENTITY % common.att 'id ID #IMPLIED xml:lang NMTOKEN #IMPLIED'> <!ENTITY % common-idreq.att 'id ID #REQUIRED xml:lang NMTOKEN #IMPLIED'> <!-- xml:space attribute =============================================== Indicates that the element contains white space that the formatter or other application should retain, as appropriate to its function. ==================================================================== --> <!ENTITY % xmlspace.att 'xml:space (default|preserve) #FIXED "preserve"'> <!-- def attribute ===================================================== Points to the element where the relevant definition can be found, using the IDREF mechanism. %def.att; is for optional def attributes, and %def-req.att; is for required def attributes. ==================================================================== --> <!ENTITY % def.att 'def IDREF #IMPLIED'> <!ENTITY % def-req.att 'def IDREF #REQUIRED'> <!-- ref attribute ===================================================== Points to the element where more information can be found, using the IDREF mechanism. %ref.att; is for optional ref attributes, and %ref-req.att; is for required ref attributes. ================================================================== --> <!ENTITY % ref.att 'ref IDREF #IMPLIED'> <!ENTITY % ref-req.att 'ref IDREF #REQUIRED'> <!-- =============================================================== --> <!-- Entities for XLink compliance --> <!-- =============================================================== --> <!ENTITY % xlink-simple.att 'type (simple|extended|locator|arc) #FIXED "simple" href CDATA #IMPLIED role CDATA #IMPLIED title CDATA #IMPLIED '> <!-- 'xmlns CDATA #FIXED "http://www.w3.org/XML/XLink/0.9" --> <!-- FIXME: brain-dead IE5 has broken support for namespace validation and since I use it for editing I remove this for now --> <!ENTITY % xlink-user-replace.att 'show (new|parsed|replace) #FIXED "replace" actuate (user|auto) #FIXED "user" '> <!ENTITY % xlink-user-new.att 'show (new|parsed|replace) #FIXED "new" actuate (user|auto) #FIXED "user" '> <!ENTITY % xlink-auto-parsed.att 'show (new|parsed|replace) #FIXED "parsed" actuate (user|auto) #FIXED "auto" '> <!-- FIXME (SM): XLink doesn't yet cover the idea of soft links so introducing it here using the same namespace is _somewhat_ illegal. Should we create it own namespace? --> <!ENTITY % xlink-soft.att 'mode (hard|soft) #FIXED "soft" '> <!-- =============================================================== --> <!-- Entities for general usage --> <!-- =============================================================== --> <!-- Key attribute ===================================================== Optionally provides a sorting or indexing key, for cases when the element content is inappropriate for this purpose. ==================================================================== --> <!ENTITY % key.att 'key CDATA #IMPLIED'> <!-- Title attributes ================================================== Indicates that the element requires to have a title. ==================================================================== --> <!ENTITY % title.att 'title CDATA #REQUIRED'> <!-- Name attributes ================================================== Indicates that the element requires to have a name. ==================================================================== --> <!ENTITY % name.att 'name CDATA #REQUIRED'> <!-- Email attributes ================================================== Indicates that the element requires to have an email. ==================================================================== --> <!ENTITY % email.att 'email CDATA #REQUIRED'> <!-- =============================================================== --> <!-- General definitions --> <!-- =============================================================== --> <!-- A person is a general human entity --> <!ELEMENT person EMPTY> <!ATTLIST person %common.att; %name.att; %email.att;> <!-- =============================================================== --> <!-- Content definitions --> <!-- =============================================================== --> <!ENTITY % local.content.mix ""> <!ENTITY % markup "strong|em|code|sub|sup"> <!ENTITY % links "link|connect|jump|fork|anchor"> <!ENTITY % special "br|img|icon"> <!ENTITY % link-content.mix "%text;|%markup;|%special;%local.content.mix;"> <!ENTITY % content.mix "%link-content.mix;|%links;"> <!-- ==================================================== --> <!-- Phrase Markup --> <!-- ==================================================== --> <!-- Strong (typically bold) --> <!ELEMENT strong (%text;|%markup;|%links;)*> <!ATTLIST strong %common.att;> <!-- Emphasis (typically italic) --> <!ELEMENT em (%text;|%markup;|%links;)*> <!ATTLIST em %common.att;> <!-- Code (typically monospaced) --> <!ELEMENT code (%text;|%markup;|%links;)*> <!ATTLIST code %common.att;> <!-- Superscript (typically smaller and higher) --> <!ELEMENT sup (%text;|%markup;|%links;)*> <!ATTLIST sup %common.att;> <!-- Subscript (typically smaller and lower) --> <!ELEMENT sub (%text;|%markup;|%links;)*> <!ATTLIST sub %common.att;> <!-- FIXME (SM): should we add these HTML 4.0 markups which are style-free? -dfn -samp -kbd -var -cite -abbr -acronym --> <!-- ==================================================== --> <!-- Hypertextual Links --> <!-- ==================================================== --> <!-- hard replacing link (equivalent of <a ...>) --> <!ELEMENT link (%link-content.mix;)*> <!ATTLIST link %common.att; %xlink-simple.att; %xlink-user-replace.att;> <!-- Hard window replacing link (equivalent of <a ... target="_top">) --> <!ELEMENT jump (%link-content.mix;)*> <!ATTLIST jump anchor CDATA #IMPLIED %common.att; %xlink-simple.att; %xlink-user-new.att;> <!-- Hard window forking link (equivalent of <a ... target="_new">) --> <!ELEMENT fork (%link-content.mix;)*> <!ATTLIST fork %common.att; %xlink-simple.att; %xlink-user-new.att;> <!-- Anchor point (equivalent of <a name="...">) --> <!ELEMENT anchor EMPTY> <!ATTLIST anchor %common-idreq.att;> <!-- Soft link between processed pages (no equivalent in HTML) --> <!ELEMENT connect (%link-content.mix;)*> <!ATTLIST connect %common.att; %xlink-simple.att; %xlink-user-replace.att; %xlink-soft.att;> <!-- ==================================================== --> <!-- Specials --> <!-- ==================================================== --> <!-- Breakline Object (typically forces line break) --> <!ELEMENT br EMPTY> <!ATTLIST br %common.att;> <!-- Image Object (typically an inlined image) --> <!-- FIXME (SM): should we have the notion of soft links even here for inlined objects? --> <!ELEMENT img EMPTY> <!ATTLIST img src CDATA #REQUIRED alt CDATA #REQUIRED height CDATA #IMPLIED width CDATA #IMPLIED usemap CDATA #IMPLIED ismap (ismap) #IMPLIED %common.att;> <!-- Image Icon (typically an inlined image placed as graphical item) --> <!-- FIXME (SM): should we have the notion of soft links even here for inlined objects? --> <!ELEMENT icon EMPTY> <!ATTLIST icon src CDATA #REQUIRED alt CDATA #REQUIRED height CDATA #IMPLIED width CDATA #IMPLIED %common.att;> <!-- =============================================================== --> <!-- Blocks definitions --> <!-- =============================================================== --> <!ENTITY % local.blocks ""> <!ENTITY % paragraphs "p|source|note|fixme|figure"> <!ENTITY % local.lists "%paragraphs;"> <!ENTITY % tables "table"> <!ENTITY % lists "ol|ul|sl|dl|%local.lists;"> <!ENTITY % blocks "anchor|%paragraphs;|%tables;|%lists; %local.blocks;"> <!-- ==================================================== --> <!-- Paragraphs --> <!-- ==================================================== --> <!-- Text Paragraph (normally vertically space delimited) --> <!ELEMENT p (%content.mix;)*> <!ATTLIST p %common.att;> <!-- Source Paragraph (normally space is preserved) --> <!ELEMENT source (%content.mix;)*> <!ATTLIST source %common.att; %xmlspace.att;> <!-- Note Paragraph (normally shown encapsulated) --> <!ELEMENT note (%content.mix;)*> <!ATTLIST note %common.att;> <!-- Fixme Paragraph (normally not shown) --> <!ELEMENT fixme (%content.mix;)*> <!-- the "author" attribute should match the "key" attribute of the <author> element --> <!ATTLIST fixme author CDATA #REQUIRED %common.att;> <!-- ==================================================== --> <!-- Tables --> <!-- ==================================================== --> <!-- Attributes that indicate the spanning of the table cell --> <!ENTITY % cell.span 'colspan CDATA "1" rowspan CDATA "1"'> <!-- Table element --> <!ELEMENT table (caption?, tr+)> <!ATTLIST table %common.att;> <!-- The table title --> <!ELEMENT caption (%content.mix;)*> <!ATTLIST caption %common.att;> <!-- The table row element --> <!ELEMENT tr (th|td)+> <!ATTLIST tr %common.att;> <!-- The table row header element --> <!ELEMENT th (%content.mix;)*> <!ATTLIST th %common.att; %cell.span;> <!-- The table row description element --> <!ELEMENT td (%content.mix;)*> <!ATTLIST td %common.att; %cell.span;> <!-- ==================================================== --> <!-- Lists --> <!-- ==================================================== --> <!-- Unordered list (typically bulleted) --> <!ELEMENT ul (li|%lists;)+> <!-- spacing attribute: Use "normal" to get normal vertical spacing for items; use "compact" to get less spacing. The default is dependent on the stylesheet. --> <!ATTLIST ul %common.att; spacing (normal|compact) #IMPLIED> <!-- Ordered list (typically numbered) --> <!ELEMENT ol (li|%lists;)+> <!-- spacing attribute: Use "normal" to get normal vertical spacing for items; use "compact" to get less spacing. The default is dependent on the stylesheet. --> <!ATTLIST ol %common.att; spacing (normal|compact) #IMPLIED> <!-- Simple list (typically with no mark) --> <!ELEMENT sl (li|%lists;)+> <!ATTLIST sl %common.att;> <!-- List item --> <!ELEMENT li (%content.mix;|%lists;)*> <!ATTLIST li %common.att;> <!-- Definition list (typically two-column) --> <!ELEMENT dl (dt,dd)+> <!ATTLIST dl %common.att;> <!-- Definition term --> <!ELEMENT dt (%content.mix;)*> <!ATTLIST dt %common.att;> <!-- Definition description --> <!ELEMENT dd (%content.mix;)*> <!ATTLIST dd %common.att;> <!-- ==================================================== --> <!-- Special Blocks --> <!-- ==================================================== --> <!-- Image Block (typically a separated and centered image) --> <!-- FIXME (SM): should we have the notion of soft links even here for inlined objects? --> <!ELEMENT figure EMPTY> <!ATTLIST figure src CDATA #REQUIRED alt CDATA #REQUIRED height CDATA #IMPLIED width CDATA #IMPLIED usemap CDATA #IMPLIED ismap (ismap) #IMPLIED %common.att;> <!-- =============================================================== --> <!-- Document --> <!-- =============================================================== --> <!ELEMENT document (header?, body, footer?)> <!ATTLIST document %common.att;> <!-- ==================================================== --> <!-- Header --> <!-- ==================================================== --> <!ENTITY % local.headers ""> <!ELEMENT header (title, subtitle?, version?, type?, authors, notice*, abstract? %local.headers;)> <!ATTLIST header %common.att;> <!ELEMENT title (%text;)> <!ATTLIST title %common.att;> <!ELEMENT subtitle (%text;)> <!ATTLIST subtitle %common.att;> <!ELEMENT version (%text;)> <!ATTLIST version %common.att;> <!ELEMENT type (%text;)> <!ATTLIST type %common.att;> <!ELEMENT authors (person+)> <!ATTLIST authors %common.att;> <!ELEMENT notice (%content.mix;)*> <!ATTLIST notice %common.att;> <!ELEMENT abstract (%content.mix;)*> <!ATTLIST abstract %common.att;> <!-- ==================================================== --> <!-- Body --> <!-- ==================================================== --> <!ENTITY % local.sections ""> <!ENTITY % sections "s1|anchor %local.sections;"> <!ELEMENT body (%sections;)+> <!ATTLIST body %common.att;> <!ELEMENT s1 (s2|%blocks;)*> <!ATTLIST s1 %title.att; %common.att;> <!ELEMENT s2 (s3|%blocks;)*> <!ATTLIST s2 %title.att; %common.att;> <!ELEMENT s3 (s4|%blocks;)*> <!ATTLIST s3 %title.att; %common.att;> <!ELEMENT s4 (%blocks;)*> <!ATTLIST s4 %title.att; %common.att;> <!-- ==================================================== --> <!-- Footer --> <!-- ==================================================== --> <!ENTITY % local.footers ""> <!ELEMENT footer (legal %local.footers;)> <!ELEMENT legal (%content.mix;)*> <!ATTLIST legal %common.att;> <!-- =============================================================== --> <!-- End of DTD --> <!-- =============================================================== --> 1.1 jakarta-commons/cactus/docs/framework/xdocs/dtd/todo-v10.dtd Index: todo-v10.dtd =================================================================== <!-- =================================================================== Apache Todos DTD (Version 1.0) PURPOSE: This DTD was developed to create a simple yet powerful document type for software development todo lists for use with the Apache projects. It is an XML-compliant DTD and it's maintained by the Apache XML project. TYPICAL INVOCATION: <!DOCTYPE document PUBLIC "-//APACHE//DTD Todo Vx.yz//EN" "http://xml.apache.org/DTD/todo-vxyz.dtd"> where x := major version y := minor version z := status identifier (optional) NOTES: It is important, expecially in open developped software projects, to keep track of software changes that need to be done, planned features, development assignment, etc. in order to allow better work parallelization and create an entry point for people that want to help. This DTD wants to provide a solid foundation to provide such information and to allow it to be published as well as distributed in a common format. AUTHORS: Stefano Mazzocchi <[EMAIL PROTECTED]> FIXME: - do we need anymore working contexts? (SM) CHANGE HISTORY: 19991129 Initial version. (SM) 19991225 Added actions element for better structure (SM) COPYRIGHT: Copyright (c) @year@ The Apache Software Foundation. Permission to copy in any form is granted provided this notice is included in all copies. Permission to redistribute is granted provided this file is distributed untouched in all its parts and included files. ==================================================================== --> <!-- =============================================================== --> <!-- Extend the Documentation DTD --> <!-- =============================================================== --> <!-- FIXME (SM): this is hardcoding. Find a better way of doing this possibly using public identifiers --> <!ENTITY % document-dtd SYSTEM "document-v10.dtd"> %document-dtd; <!-- =============================================================== --> <!-- Common entities --> <!-- =============================================================== --> <!ENTITY % priorities "showstopper|high|medium|low|wish|dream"> <!ENTITY % contexts "build|docs|code|admin|design|samples"> <!-- =============================================================== --> <!-- Document Type Definition --> <!-- =============================================================== --> <!ELEMENT todo (devs, actions*)> <!ATTLIST todo %common.att; %title.att;> <!ELEMENT devs (person+)> <!ATTLIST devs %common.att;> <!ELEMENT actions (action+)> <!ATTLIST actions %common.att; priority (%priorities;) #IMPLIED> <!ELEMENT action (%content.mix;)*> <!ATTLIST action %common.att; assigned-to IDREF #IMPLIED context (%contexts;) #REQUIRED> <!-- =============================================================== --> <!-- End of DTD --> <!-- =============================================================== --> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/add.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/archi.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/archi_jsp.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/archi_servlet.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/fix.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/remove.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/images/update.jpg <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/misc/archi.ppt <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/misc/archi_jsp.ppt <<Binary file>> 1.1 jakarta-commons/cactus/docs/framework/xdocs/misc/archi_servlet.ppt <<Binary file>> 1.1 jakarta-commons/cactus/docs/sample/README Index: README =================================================================== This sample application demonstrates how to use Cactus for unit testing server side java code. The goal is to show as many use cases as possible. You can use this sample to get familiar with Cactus and also as a starting point for building your own test classes. In addition, it also shows the following features : - how to integrate Cactus unit tests with Ant by providing an already made Ant build script and several batch/script files. - how to automatically run the unit tests for a great variety of servlet engines (Tomcat 3.2, Tomcat 4.0, Resin 1.2+, Resin 1.3+, Orion 1.4, WebLogic 5.1, ...) - how to completely automate the running of the unit tests for several servlet engines with a single batch/script file and using build listener to report errors. This is very useful for continuous integration for example. For documentation on how to use Cactus, Ant integration, ... see the Cactus web site at http://jakarta.apache.org/commons/cactus Thank you. Vincent Massol 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/ResinRun.java Index: ResinRun.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import java.util.*; import java.lang.reflect.*; /** * Starts/stop Resin by setting up a listener socket. */ public class ResinRun extends Thread { private Object m_Server; private int m_Port = 7777; public static void main(String[] args) { ResinRun run = new ResinRun(); // Look for a -start or -stop flag boolean isStart = true; Vector newArgs = new Vector(); for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("-start")) { isStart = true; } else if (args[i].equalsIgnoreCase("-stop")) { isStart = false; } else if (args[i].equalsIgnoreCase("-port")) { run.m_Port = Integer.parseInt(args[i+1]); i++; } else { newArgs.add(args[i]); } } if (isStart) { String[] strArgs = new String[0]; run.startResin((String[])newArgs.toArray(strArgs)); } else { run.stopResin(); } } private void startResin(String[] args) { if (m_Server == null) { try { Class resinClass = Class.forName("com.caucho.server.http.ResinServer"); Constructor constructor = resinClass.getConstructor(new Class[] { args.getClass(), boolean.class }); m_Server = constructor.newInstance(new Object[] { args, new Boolean(true) }); Method initMethod = resinClass.getMethod("init", new Class[] { boolean.class }); initMethod.invoke(m_Server, new Object[] { new Boolean(true) } ); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Error starting Resin"); } } // Set up listener socket for listening to request to stop Resin new Thread(this).start(); } private void stopResin() { // Open socket connection Socket clientSocket = null; try { clientSocket = new Socket("127.0.0.1", m_Port); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Error opening socket tp 127.0.0.1 on port [" + m_Port + "]"); } finally { try { if (clientSocket != null) { clientSocket.close(); } } catch (IOException e) { throw new RuntimeException("Cannot close client socket"); } } } public void run() { ServerSocket serverSocket = setUpListenerSocket(); // Accept a client socket connection Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { throw new RuntimeException("Error accepting connection for server socket [" + serverSocket + "]"); } finally { // Stop server socket try { serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Cannot close server socket [" + serverSocket + "]"); } } // Stop Resin server if (m_Server != null) { try { Method closeMethod = m_Server.getClass().getMethod("close", null); closeMethod.invoke(m_Server, null); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Cannot stop Resin server"); } } // Stop server socket try { serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Cannot close server socket [" + serverSocket + "]"); } } private ServerSocket setUpListenerSocket() { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(m_Port); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Error setting up the Resin listener socket"); } return serverSocket; } } 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/RunServerTestsTask.java Index: RunServerTestsTask.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; /** * * @version @version@ */ public class RunServerTestsTask extends Task { private String m_TestTarget; /** * */ private StartServerHelper m_StartHelper; /** * */ private StopServerHelper m_StopHelper; public void init() { m_StartHelper = new StartServerHelper(this); m_StopHelper = new StopServerHelper(this); } /** * Executes the task. */ public void execute() throws BuildException { try { callStart(); callTests(); } finally { // Make sure we stop the server callStop(); } } /** * Call the start server task */ private void callStart() { m_StartHelper.execute(); } /** * Call the stop server task */ private void callStop() { m_StopHelper.execute(); } /** * Call the run tests target */ private void callTests() { CallTarget callee; callee = (CallTarget)project.createTask("antcall"); callee.setOwningTarget(target); callee.setTaskName(getTaskName()); callee.setLocation(location); callee.init(); callee.setTarget(m_TestTarget); callee.execute(); } /** * Sets the target to call to start the server. * * @param theStartTarget the Ant target to call */ public void setStartTarget(String theStartTarget) { m_StartHelper.setStartTarget(theStartTarget); } /** * Sets the target to call to stop the server. * * @param theStopTarget the Ant target to call */ public void setStopTarget(String theStopTarget) { m_StopHelper.setStopTarget(theStopTarget); } /** * Sets the URL to call for testing if the server is running. * * @param theTestURL the test URL to ping */ public void setTestURL(String theTestURL) { m_StartHelper.setTestURL(theTestURL); m_StopHelper.setTestURL(theTestURL); } /** * Sets the target to call to run the tests. * * @param theTerstTarget the Ant target to call */ public void setTestTarget(String theTestTarget) { m_TestTarget = theTestTarget; } } 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StartServerHelper.java Index: StartServerHelper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; /** * A helper class for an Ant Task that does the following : * <ul> * <li>create a java thread,</li> * <li>start another Ant target in that thread. This target must be a * blocking target that starts a web server/servlet engine,</li> * <li>wait for that server to be started. This is done by continuously * trying to call a URL.</li> * </ul>. * * @version @version@ */ public class StartServerHelper implements Runnable { /** * The URL that is continuously pinged to verify if the server is running. */ private URL m_TestURL; /** * The Ant target name that will start the web server/servlet engine. */ private String m_StartTarget; /** * The tasks that wraps around this helper class */ private Task m_Task; /** * */ public StartServerHelper(Task theTask) { m_Task = theTask; } /** * Executes the task. */ public void execute() throws BuildException { // Verify that a test URL has been specified if (m_TestURL == null) { throw new BuildException("A testURL attribute must be specified"); } // Verify that a start target has been specified if (m_StartTarget == null) { throw new BuildException("A startTarget Ant target name must be specified"); } // Call the target that starts the server, in another thread. The called // target must be blocking. Thread thread = new Thread(this); thread.start(); // Wait a few ms more (just to make sur the servlet engine is // ready to accept connections) try { Thread.sleep(1000); } catch (InterruptedException e) { throw new BuildException("Interruption during sleep", e); } // Continuously try calling the test URL until it succeeds while (true) { try { HttpURLConnection connection = (HttpURLConnection)m_TestURL.openConnection(); connection.connect(); connection.disconnect(); } catch (IOException e) { try { Thread.sleep(500); } catch (InterruptedException ee) { throw new BuildException("Interruption during sleep", ee); } continue; } break; } // Wait a few ms more (just to be sure !) try { Thread.sleep(500); } catch (InterruptedException e) { throw new BuildException("Interruption during sleep", e); } // We're done ... Ant will continue processing other tasks } /** * The thread that calls the Ant target that starts the web server/servlet * engine. Must be a blocking target. */ public void run() { // Call the Ant target using the "antcall" task. CallTarget callee; callee = (CallTarget)(m_Task.getProject().createTask("antcall")); callee.setOwningTarget(m_Task.getOwningTarget()); callee.setTaskName(m_Task.getTaskName()); callee.setLocation(m_Task.getLocation()); callee.init(); callee.setTarget(m_StartTarget); callee.execute(); // Should never reach this point as the target is blocking, unless the // server is stopped. } /** * @param theTestURL the test URL to ping */ public void setTestURL(String theTestURL) { try { m_TestURL = new URL(theTestURL); } catch (MalformedURLException e) { throw new BuildException("Bad URL [" + theTestURL + "]", e); } } /** * @param theStartTarget the Ant target to call */ public void setStartTarget(String theStartTarget) { m_StartTarget = theStartTarget; } } 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StartServerTask.java Index: StartServerTask.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; /** * An Ant Task that does the following : * <ul> * <li>create a java thread,</li> * <li>start another Ant target in that thread. This target must be a * blocking target that starts a web server/servlet engine,</li> * <li>wait for that server to be started. This is done by continuously * trying to call a URL.</li> * </ul>. * * @version @version@ */ public class StartServerTask extends Task { /** * Helper class */ private StartServerHelper m_Helper; /** * Initialization */ public void init() { m_Helper = new StartServerHelper(this); } /** * Executes the task. */ public void execute() throws BuildException { m_Helper.execute(); } /** * Ant will automatically call this method when the "testURL" attribute * of our task is used. * * @param theTestURL the test URL to ping */ public void setTestURL(String theTestURL) { m_Helper.setTestURL(theTestURL); } /** * Ant will automatically call this method when the "startTarget" attribute * of our task is used. * * @param theStartTarget the Ant target to call */ public void setStartTarget(String theStartTarget) { m_Helper.setStartTarget(theStartTarget); } } 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerHelper.java Index: StopServerHelper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; /** * A helper class for an Ant task that does the following : stop a running * server by calling an Ant target to stop it in another thread and wait for * the servlet engine to be stopped by trying to continously connect to a test * URL. If it succeeds it means the server is not stopped yet ! * * @version @version@ */ public class StopServerHelper implements Runnable { /** * The URL that is continuously pinged to verify if the server is stopped */ private URL m_TestURL; /** * The Ant target name that will stop the web server/servlet engine. */ private String m_StopTarget; /** * The tasks that wraps around this helper class */ private Task m_Task; /** * */ public StopServerHelper(Task theTask) { m_Task = theTask; } /** * Executes the task. */ public void execute() throws BuildException { // Verify that a test URL has been specified if (m_TestURL == null) { throw new BuildException("A testURL attribute must be specified"); } // Verify that a stop target has been specified if (m_StopTarget == null) { throw new BuildException("A stopTarget Ant target name must be specified"); } // Call the target that stops the server, in another thread. Thread thread = new Thread(this); thread.start(); // Wait a few ms more (just to make sure) try { Thread.sleep(500); } catch (InterruptedException e) { throw new BuildException("Interruption during sleep", e); } // Continuously try calling the test URL until it fails while (true) { try { HttpURLConnection connection = (HttpURLConnection)m_TestURL.openConnection(); connection.connect(); connection.disconnect(); } catch (IOException e) { break; } try { Thread.sleep(500); } catch (InterruptedException ee) { throw new BuildException("Interruption during sleep", ee); } } // Wait a few ms more (just to be sure !) try { Thread.sleep(500); } catch (InterruptedException e) { throw new BuildException("Interruption during sleep", e); } m_Task.log("Server stopped !"); // We're done ... Ant will continue processing other tasks } /** * The thread that calls the Ant target that stops the web server/servlet * engine. */ public void run() { // Call the Ant target using the "antcall" task. CallTarget callee; callee = (CallTarget)(m_Task.getProject().createTask("antcall")); callee.setOwningTarget(m_Task.getOwningTarget()); callee.setTaskName(m_Task.getTaskName()); callee.setLocation(m_Task.getLocation()); callee.init(); callee.setTarget(m_StopTarget); callee.execute(); } /** * @param theTestURL the test URL to ping */ public void setTestURL(String theTestURL) { try { m_TestURL = new URL(theTestURL); } catch (MalformedURLException e) { throw new BuildException("Bad URL [" + theTestURL + "]", e); } } /** * @param theStopTarget the Ant target to call */ public void setStopTarget(String theStopTarget) { m_StopTarget = theStopTarget; } } 1.1 jakarta-commons/cactus/src/ant/org/apache/commons/cactus/ant/StopServerTask.java Index: StopServerTask.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.ant; import java.net.*; import java.io.*; import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; /** * Call an Ant stop target in another thread and wait for the servlet engine * to be stopped by trying to continously connect to a test URL. If it succeeds *it means the server is not stopped yet ! * * @version @version@ */ public class StopServerTask extends Task { /** * Helper class */ private StopServerHelper m_Helper; /** * Initialization */ public void init() { m_Helper = new StopServerHelper(this); } /** * Executes the task. */ public void execute() throws BuildException { m_Helper.execute(); } /** * Ant will automatically call this method when the "testURL" attribute * of our task is used. * * @param theTestURL the test URL to ping */ public void setTestURL(String theTestURL) { m_Helper.setTestURL(theTestURL); } /** * Ant will automatically call this method when the "stopTarget" attribute * of our task is used. * * @param theStopTarget the Ant target to call */ public void setStopTarget(String theStopTarget) { m_Helper.setStopTarget(theStopTarget); } } 1.1 jakarta-commons/cactus/src/framework/servlet22/org/apache/commons/cactus/server/HttpServletRequestWrapper.java Index: HttpServletRequestWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.commons.cactus.*; /** * Encapsulation class for the Servlet 2.2 API <code>HttpServletRequest</code>. * This is an implementation that delegates all the call to the * <code>HttpServletRequest</code> object passed in the constructor except for * some overridden methods which are use to simulate a URL. This is to be able to * simulate any URL that would have been used to call the test method : if this * was not done, the URL that would be returned (by calling the * <code>getRequestURI()</code> method or others alike) would be the URL of the * server redirector servlet or JSP and not a URL that the test case want to * simulate. * * @version @version@ */ public class HttpServletRequestWrapper implements HttpServletRequest { /** * The real HTTP request */ private HttpServletRequest m_Request; /** * The URL to simulate */ private ServletURL m_URL; /** * Construct an <code>HttpServletRequest</code> instance that delegates * it's method calls to the request object passed as parameter and that * uses the URL passed as parameter to simulate a URL from which the request * would come from. * * @param theRequest the real HTTP request * @param theURL the URL to simulate or <code>null</code> if none */ public HttpServletRequestWrapper(HttpServletRequest theRequest, ServletURL theURL) { m_Request = theRequest; m_URL = theURL; } public HttpServletRequest getOriginalRequest() { return m_Request; } public boolean isRequestedSessionIdFromURL() { return m_Request.isRequestedSessionIdFromURL(); } public Enumeration getLocales() { return m_Request.getLocales(); } public String getHeader(String theName) { return m_Request.getHeader(theName); } /** * @return the context path from the simulated URL or the real context path * if a simulation URL has not been defined. */ public String getContextPath() { if (m_URL != null) { return m_URL.getContextPath(); } return m_Request.getContextPath(); } public String getScheme() { return m_Request.getScheme(); } /** * @return the path info from the simulated URL or the real path info * if a simulation URL has not been defined. */ public String getPathInfo() { if (m_URL != null) { return m_URL.getPathInfo(); } return m_Request.getPathInfo(); } public String getAuthType() { return m_Request.getAuthType(); } /** * @return the server name from the simulated URL or the real server name * if a simulation URL has not been defined. */ public String getServerName() { if (m_URL != null) { return m_URL.getURL().getHost(); } return m_Request.getServerName(); } public String getRealPath(String thePath) { return m_Request.getRealPath(thePath); } public HttpSession getSession() { return m_Request.getSession(); } public HttpSession getSession(boolean isCreate) { return m_Request.getSession(isCreate); } public String getRemoteHost() { return m_Request.getRemoteHost(); } public Enumeration getHeaderNames() { return m_Request.getHeaderNames(); } public boolean isUserInRole(String theRole) { return m_Request.isUserInRole(theRole); } /** * @return the server port number from the simulated URL or the real server * port number if a simulation URL has not been defined. If not * port is defined, then port 80 is returned. */ public int getServerPort() { if (m_URL != null) { if (m_URL.getURL().getPort() == -1) { return 80; } return m_URL.getURL().getPort(); } return m_Request.getServerPort(); } public BufferedReader getReader() throws IOException { return m_Request.getReader(); } public int getContentLength() { return m_Request.getContentLength(); } /** * @return the URI from the simulated URL or the real URI * if a simulation URL has not been defined. */ public String getRequestURI() { if (m_URL != null) { return m_URL.getURL().getFile(); } return m_Request.getRequestURI(); } public String[] getParameterValues(String theName) { return m_Request.getParameterValues(theName); } public boolean isRequestedSessionIdFromUrl() { return m_Request.isRequestedSessionIdFromUrl(); } public String getContentType() { return m_Request.getContentType(); } public Locale getLocale() { return m_Request.getLocale(); } public void removeAttribute(String theName) { m_Request.removeAttribute(theName); } public String getParameter(String theName) { return m_Request.getParameter(theName); } /** * @return the servlet path from the simulated URL or the real servlet path * if a simulation URL has not been defined. */ public String getServletPath() { if (m_URL != null) { return m_URL.getServletPath(); } return m_Request.getServletPath(); } public boolean isRequestedSessionIdFromCookie() { return m_Request.isRequestedSessionIdFromCookie(); } public ServletInputStream getInputStream() throws IOException { return m_Request.getInputStream(); } public Principal getUserPrincipal() { return m_Request.getUserPrincipal(); } public boolean isSecure() { return m_Request.isSecure(); } public String getPathTranslated() { return m_Request.getPathTranslated(); } public String getRemoteAddr() { return m_Request.getRemoteAddr(); } public String getCharacterEncoding() { return m_Request.getCharacterEncoding(); } public Enumeration getParameterNames() { return m_Request.getParameterNames(); } public String getMethod() { return m_Request.getMethod(); } public void setAttribute(String theName, Object theAttribute) { m_Request.setAttribute(theName, theAttribute); } public Object getAttribute(String theName) { return m_Request.getAttribute(theName); } public int getIntHeader(String theName) { return m_Request.getIntHeader(theName); } public boolean isRequestedSessionIdValid() { return m_Request.isRequestedSessionIdValid(); } /** * @return the query string from the simulated URL or the real query * string if a simulation URL has not been defined. */ public String getQueryString() { if (m_URL != null) { return m_URL.getQueryString(); } return m_Request.getQueryString(); } public long getDateHeader(String theName) { return m_Request.getDateHeader(theName); } public Enumeration getAttributeNames() { return m_Request.getAttributeNames(); } public String getRemoteUser() { return m_Request.getRemoteUser(); } public String getProtocol() { return m_Request.getProtocol(); } public Enumeration getHeaders(String theName) { return m_Request.getHeaders(theName); } public String getRequestedSessionId() { return m_Request.getRequestedSessionId(); } public RequestDispatcher getRequestDispatcher(String thePath) { return m_Request.getRequestDispatcher(thePath); } public Cookie[] getCookies() { return m_Request.getCookies(); } } 1.1 jakarta-commons/cactus/src/framework/servlet22/org/apache/commons/cactus/server/RequestDispatcherWrapper.java Index: RequestDispatcherWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>RequestDispatcher</code> which overrides the * <code>forward()</code> and <code>include</code> methods to use the original * HTTP request object instead of the simulated one used by Cactus. * * @version @version@ */ public class RequestDispatcherWrapper implements RequestDispatcher { /** * The original request dispatcher object */ private RequestDispatcher m_OriginalDispatcher; /** * @param theOriginalDispatcher the original request dispatcher object */ public RequestDispatcherWrapper(RequestDispatcher theOriginalDispatcher) { m_OriginalDispatcher = theOriginalDispatcher; } /** * Call the original <code>RequestDispatcher</code> <code>forward()</code> * method but with the original HTTP request (not the simulation one which * would make the servlet engine choke !). * * @param theRequest the simulation HTTP request * @param theResponse the original HTTP response */ public void forward(ServletRequest theRequest, ServletResponse theResponse) throws IOException, ServletException { HttpServletRequestWrapper request = (HttpServletRequestWrapper)theRequest; m_OriginalDispatcher.forward(request.getOriginalRequest(), theResponse); } /** * Call the original <code>RequestDispatcher</code> <code>include()</code> * method but with the original HTTP request (not the simulation one which * would make the servlet engine choke !). * * @param theRequest the simulation HTTP request * @param theResponse the original HTTP response */ public void include(ServletRequest theRequest, ServletResponse theResponse) throws IOException, ServletException { HttpServletRequestWrapper request = (HttpServletRequestWrapper)theRequest; m_OriginalDispatcher.include(request.getOriginalRequest(), theResponse); } } 1.1 jakarta-commons/cactus/src/framework/servlet22/org/apache/commons/cactus/server/ServletConfigWrapper.java Index: ServletConfigWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>ServletConfig</code> which overrides the * <code>getServletContext()</code> method to return our own wrapper around * <code>ServletContext</code>. * * @version @version@ * @see ServletContext */ public class ServletConfigWrapper implements ServletConfig { /** * The original servlet config object */ private ServletConfig m_OriginalConfig; /** * List of parameters set using the <code>setInitParameter()</code> method. */ private Hashtable m_InitParameters; /** * Simulated name of the servlet */ private String m_ServletName; /** * @param theOriginalConfig the original servlet config object */ public ServletConfigWrapper(ServletConfig theOriginalConfig) { m_OriginalConfig = theOriginalConfig; m_InitParameters = new Hashtable(); } /** * Sets a parameter as if it were set in the <code>web.xml</code> file. * * @param theName the parameter's name * @param theValue the parameter's value */ public void setInitParameter(String theName, String theValue) { m_InitParameters.put(theName, theValue); } /** * Sets the servlet name. That will be the value returned by the * <code>getServletName()</code> method. * * @param theServletName the servlet's name */ public void setServletName(String theServletName) { m_ServletName = theServletName; } //--Overridden methods ----------------------------------------------------- /** * @return our own wrapped servlet context object */ public ServletContext getServletContext() { return new ServletContextWrapper(m_OriginalConfig.getServletContext()); } /** * @param theName the name of the parameter's value to return * @return the value of the parameter, looking for it first in the list of * parameters set using the <code>setInitParameter()</code> method * and then in those set in <code>web.xml</code>. */ public String getInitParameter(String theName) { // Look first in the list of parameters set using the // setInitParameter() method. String value = (String)m_InitParameters.get(theName); if (value == null) { value = m_OriginalConfig.getInitParameter(theName); } return value; } /** * @return the union of the parameters defined in the Redirector * <code>web.xml</code> file and the one set using the * <code>setInitParameter()</code> method. */ public Enumeration getInitParameterNames() { Vector names = new Vector(); Enumeration enum = m_InitParameters.keys(); while (enum.hasMoreElements()) { String value = (String)enum.nextElement(); names.add(value); } enum = m_OriginalConfig.getInitParameterNames(); while (enum.hasMoreElements()) { String value = (String)enum.nextElement(); names.add(value); } return names.elements(); } /** * @return the simulated servlet's name if defined or the redirector * servlet's name */ public String getServletName() { if (m_ServletName != null) { return m_ServletName; } return m_OriginalConfig.getServletName(); } } 1.1 jakarta-commons/cactus/src/framework/servlet22/org/apache/commons/cactus/server/ServletContextWrapper.java Index: ServletContextWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>ServletContext</code> which overrides the * <code>getRequestDispatcher()</code> method to return our own wrapper around * <code>RequestDispatcher</code>. * * @version @version@ * @see RequestDispatcherWrapper */ public class ServletContextWrapper implements ServletContext { /** * The original servlet context object */ private ServletContext m_OriginalContext; /** * @param theOriginalContext the original servlet context object */ public ServletContextWrapper(ServletContext theOriginalContext) { m_OriginalContext = theOriginalContext; } public String getMimeType(String theFilename) { return m_OriginalContext.getMimeType(theFilename); } public URL getResource(String thePath) throws MalformedURLException { return m_OriginalContext.getResource(thePath); } public InputStream getResourceAsStream(String thePath) { return m_OriginalContext.getResourceAsStream(thePath); } /** * @return our request dispatcher wrapper */ public RequestDispatcher getRequestDispatcher(String thePath) { RequestDispatcher dispatcher = new RequestDispatcherWrapper( m_OriginalContext.getRequestDispatcher(thePath)); return dispatcher; } public RequestDispatcher getNamedDispatcher(String theName) { RequestDispatcher dispatcher = new RequestDispatcherWrapper( m_OriginalContext.getNamedDispatcher(theName)); return dispatcher; } public String getRealPath(String thePath) { return m_OriginalContext.getRealPath(thePath); } /** * @return our servlet context wrapper */ public ServletContext getContext(String theUripath) { ServletContext context = new ServletContextWrapper( m_OriginalContext.getContext(theUripath)); return context; } public String getServerInfo() { return m_OriginalContext.getServerInfo(); } public String getInitParameter(String theName) { return m_OriginalContext.getInitParameter(theName); } public Enumeration getInitParameterNames() { return m_OriginalContext.getInitParameterNames(); } public Object getAttribute(String theName) { return m_OriginalContext.getAttribute(theName); } public Enumeration getAttributeNames() { return m_OriginalContext.getAttributeNames(); } public void setAttribute(String theName, Object theAttribute) { m_OriginalContext.setAttribute(theName, theAttribute); } public void removeAttribute(String theName) { m_OriginalContext.removeAttribute(theName); } public int getMajorVersion() { return m_OriginalContext.getMajorVersion(); } public int getMinorVersion() { return m_OriginalContext.getMinorVersion(); } public void log(String theMessage) { m_OriginalContext.log(theMessage); } public void log(String theMessage, Throwable theCause) { m_OriginalContext.log(theMessage, theCause); } // deprecated methods public Servlet getServlet(String theName) throws ServletException { return m_OriginalContext.getServlet(theName); } public Enumeration getServlets() { return m_OriginalContext.getServlets(); } public Enumeration getServletNames() { return m_OriginalContext.getServletNames(); } public void log(Exception theException, String theMessage) { m_OriginalContext.log(theException, theMessage); } } 1.1 jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/HttpServletRequestWrapper.java Index: HttpServletRequestWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.commons.cactus.*; /** * Encapsulation class for the Servlet 2.3 API <code>HttpServletRequest</code>. * This is an implementation that delegates all the call to the * <code>HttpServletRequest</code> object passed in the constructor except for * some overiden methods which are use to simulate a URL. This is to be able to * simulate any URL that would have been used to call the test method : if this * was not done, the URL that would be returned (by calling the * <code>getRequestURI()</code> method or others alike) would be the URL of the * Cactus redirector servlet and not a URL that the test case want to simulate. * * @version @version@ */ public class HttpServletRequestWrapper implements HttpServletRequest { /** * The real HTTP request */ private HttpServletRequest m_Request; /** * The URL to simulate */ private ServletURL m_URL; /** * Construct an <code>HttpServletRequest</code> instance that delegates * it's method calls to the request object passed as parameter and that * uses the URL passed as parameter to simulate a URL from which the request * would come from. * * @param theRequest the real HTTP request * @param theURL the URL to simulate or <code>null</code> if none */ public HttpServletRequestWrapper(HttpServletRequest theRequest, ServletURL theURL) { m_Request = theRequest; m_URL = theURL; } public HttpServletRequest getOriginalRequest() { return m_Request; } public boolean isUserInRole(String theRole) { return m_Request.isUserInRole(theRole); } public boolean isRequestedSessionIdValid() { return m_Request.isRequestedSessionIdValid(); } public boolean isRequestedSessionIdFromUrl() { return m_Request.isRequestedSessionIdFromUrl(); } public boolean isRequestedSessionIdFromURL() { return m_Request.isRequestedSessionIdFromURL(); } public boolean isRequestedSessionIdFromCookie() { return m_Request.isRequestedSessionIdFromCookie(); } public Principal getUserPrincipal() { return m_Request.getUserPrincipal(); } public HttpSession getSession(boolean isCreate) { return m_Request.getSession(isCreate); } public HttpSession getSession() { return m_Request.getSession(); } /** * @return the servlet path from the simulated URL or the real servlet path * if a simulation URL has not been defined. */ public String getServletPath() { if (m_URL != null) { return m_URL.getServletPath(); } return m_Request.getServletPath(); } public String getRequestedSessionId() { return m_Request.getRequestedSessionId(); } public StringBuffer getRequestURL() { return m_Request.getRequestURL(); } /** * @return the URI from the simulated URL or the real URI * if a simulation URL has not been defined. */ public String getRequestURI() { if (m_URL != null) { return m_URL.getURL().getFile(); } return m_Request.getRequestURI(); } public String getRemoteUser() { return m_Request.getRemoteUser(); } /** * @return the query string from the simulated URL or the real query * string if a simulation URL has not been defined. */ public String getQueryString() { if (m_URL != null) { return m_URL.getQueryString(); } return m_Request.getQueryString(); } public String getPathTranslated() { return m_Request.getPathTranslated(); } /** * @return the path info from the simulated URL or the real path info * if a simulation URL has not been defined. */ public String getPathInfo() { if (m_URL != null) { return m_URL.getPathInfo(); } return m_Request.getPathInfo(); } public String getMethod() { return m_Request.getMethod(); } public int getIntHeader(String theName) { return m_Request.getIntHeader(theName); } public Enumeration getHeaders(String theName) { return m_Request.getHeaders(theName); } public Enumeration getHeaderNames() { return m_Request.getHeaderNames(); } public String getHeader(String theName) { return m_Request.getHeader(theName); } public long getDateHeader(String theName) { return m_Request.getDateHeader(theName); } public Cookie[] getCookies() { return m_Request.getCookies(); } /** * @return the context path from the simulated URL or the real context path * if a simulation URL has not been defined. */ public String getContextPath() { if (m_URL != null) { return m_URL.getContextPath(); } return m_Request.getContextPath(); } public String getAuthType() { return m_Request.getAuthType(); } public void setCharacterEncoding(String env) throws UnsupportedEncodingException { m_Request.setCharacterEncoding(env); } public void setAttribute(String theName, Object theAttribute) { m_Request.setAttribute(theName, theAttribute); } public void removeAttribute(String theName) { m_Request.removeAttribute(theName); } public boolean isSecure() { return m_Request.isSecure(); } /** * @return the server port number from the simulated URL or the real server * port number if a simulation URL has not been defined. If not * port is defined, then port 80 is returned. */ public int getServerPort() { if (m_URL != null) { if (m_URL.getURL().getPort() == -1) { return 80; } return m_URL.getURL().getPort(); } return m_Request.getServerPort(); } /** * @return the server name from the simulated URL or the real server name * if a simulation URL has not been defined. */ public String getServerName() { if (m_URL != null) { return m_URL.getURL().getHost(); } return m_Request.getServerName(); } public String getScheme() { return m_Request.getScheme(); } public RequestDispatcher getRequestDispatcher(String thePath) { return m_Request.getRequestDispatcher(thePath); } public String getRemoteHost() { return m_Request.getRemoteHost(); } public String getRemoteAddr() { return m_Request.getRemoteAddr(); } public String getRealPath(String thePath) { return m_Request.getRealPath(thePath); } public BufferedReader getReader() throws IOException { return m_Request.getReader(); } public String getProtocol() { return m_Request.getProtocol(); } public String[] getParameterValues(String theName) { return m_Request.getParameterValues(theName); } public Enumeration getParameterNames() { return m_Request.getParameterNames(); } public Map getParameterMap() { return m_Request.getParameterMap(); } public String getParameter(String theName) { return m_Request.getParameter(theName); } public Enumeration getLocales() { return m_Request.getLocales(); } public Locale getLocale() { return m_Request.getLocale(); } public ServletInputStream getInputStream() throws IOException { return m_Request.getInputStream(); } public String getContentType() { return m_Request.getContentType(); } public int getContentLength() { return m_Request.getContentLength(); } public String getCharacterEncoding() { return m_Request.getCharacterEncoding(); } public Enumeration getAttributeNames() { return m_Request.getAttributeNames(); } public Object getAttribute(String theName) { return m_Request.getAttribute(theName); } } 1.1 jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/RequestDispatcherWrapper.java Index: RequestDispatcherWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>RequestDispatcher</code> which overrides the * <code>forward()</code> and <code>include</code> methods to use the original * HTTP request object instead of the simulated one used by Cactus. * * @version @version@ */ public class RequestDispatcherWrapper implements RequestDispatcher { /** * The original request dispatcher object */ private RequestDispatcher m_OriginalDispatcher; /** * @param theOriginalDispatcher the original request dispatcher object */ public RequestDispatcherWrapper(RequestDispatcher theOriginalDispatcher) { m_OriginalDispatcher = theOriginalDispatcher; } /** * Call the original <code>RequestDispatcher</code> <code>forward()</code> * method but with the original HTTP request (not the simulation one which * would make the servlet engine choke !). * * @param theRequest the simulation HTTP request * @param theResponse the original HTTP response */ public void forward(ServletRequest theRequest, ServletResponse theResponse) throws IOException, ServletException { HttpServletRequestWrapper request = (HttpServletRequestWrapper)theRequest; m_OriginalDispatcher.forward(request.getOriginalRequest(), theResponse); } /** * Call the original <code>RequestDispatcher</code> <code>include()</code> * method but with the original HTTP request (not the simulation one which * would make the servlet engine choke !). * * @param theRequest the simulation HTTP request * @param theResponse the original HTTP response */ public void include(ServletRequest theRequest, ServletResponse theResponse) throws IOException, ServletException { HttpServletRequestWrapper request = (HttpServletRequestWrapper)theRequest; m_OriginalDispatcher.include(request.getOriginalRequest(), theResponse); } } 1.1 jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/ServletConfigWrapper.java Index: ServletConfigWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>ServletConfig</code> which overrides the * <code>getServletContext()</code> method to return our own wrapper around * <code>ServletContext</code>. * * @version @version@ * @see ServletContext */ public class ServletConfigWrapper implements ServletConfig { /** * The original servlet config object */ private ServletConfig m_OriginalConfig; /** * List of parameters set using the <code>setInitParameter()</code> method. */ private Hashtable m_InitParameters; /** * Simulated name of the servlet */ private String m_ServletName; /** * @param theOriginalConfig the original servlet config object */ public ServletConfigWrapper(ServletConfig theOriginalConfig) { m_OriginalConfig = theOriginalConfig; m_InitParameters = new Hashtable(); } /** * Sets a parameter as if it were set in the <code>web.xml</code> file. * * @param theName the parameter's name * @param theValue the parameter's value */ public void setInitParameter(String theName, String theValue) { m_InitParameters.put(theName, theValue); } /** * Sets the servlet name. That will be the value returned by the * <code>getServletName()</code> method. * * @param theServletName the servlet's name */ public void setServletName(String theServletName) { m_ServletName = theServletName; } //--Overridden methods ----------------------------------------------------- /** * @return the simulated servlet's name if defined or the redirector * servlet's name */ public String getServletName() { if (m_ServletName != null) { return m_ServletName; } return m_OriginalConfig.getServletName(); } /** * @return our own wrapped servlet context object */ public ServletContext getServletContext() { return new ServletContextWrapper(m_OriginalConfig.getServletContext()); } /** * @return the union of the parameters defined in the Redirector * <code>web.xml</code> file and the one set using the * <code>setInitParameter()</code> method. */ public Enumeration getInitParameterNames() { Vector names = new Vector(); Enumeration enum = m_InitParameters.keys(); while (enum.hasMoreElements()) { String value = (String)enum.nextElement(); names.add(value); } enum = m_OriginalConfig.getInitParameterNames(); while (enum.hasMoreElements()) { String value = (String)enum.nextElement(); names.add(value); } return names.elements(); } /** * @param theName the name of the parameter's value to return * @return the value of the parameter, looking for it first in the list of * parameters set using the <code>setInitParameter()</code> method * and then in those set in <code>web.xml</code>. */ public String getInitParameter(String theName) { // Look first in the list of parameters set using the // setInitParameter() method. String value = (String)m_InitParameters.get(theName); if (value == null) { value = m_OriginalConfig.getInitParameter(theName); } return value; } } 1.1 jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/ServletContextWrapper.java Index: ServletContextWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import java.lang.reflect.*; import javax.servlet.*; import javax.servlet.http.*; /** * Wrapper around <code>ServletContext</code> which overrides the * <code>getRequestDispatcher()</code> method to return our own wrapper around * <code>RequestDispatcher</code>. * * @version @version@ * @see RequestDispatcherWrapper */ public class ServletContextWrapper implements ServletContext { /** * The original servlet context object */ private ServletContext m_OriginalContext; /** * @param theOriginalContext the original servlet context object */ public ServletContextWrapper(ServletContext theOriginalContext) { m_OriginalContext = theOriginalContext; } public void setAttribute(String theName, Object theAttribute) { m_OriginalContext.setAttribute(theName, theAttribute); } public void removeAttribute(String theName) { m_OriginalContext.removeAttribute(theName); } public void log(String theMessage, Throwable theCause) { m_OriginalContext.log(theMessage, theCause); } public void log(String theMessage) { m_OriginalContext.log(theMessage); } public void log(Exception theException, String theMessage) { m_OriginalContext.log(theException, theMessage); } public Enumeration getServlets() { return m_OriginalContext.getServlets(); } public Enumeration getServletNames() { return m_OriginalContext.getServletNames(); } public String getServletContextName() { return m_OriginalContext.getServletContextName(); } public Servlet getServlet(String theName) throws ServletException { return m_OriginalContext.getServlet(theName); } public String getServerInfo() { return m_OriginalContext.getServerInfo(); } public Set getResourcePaths() { Set returnSet; // Use reflection because newest Servlet API 2.3 changes removed this // method try { Method method = m_OriginalContext.getClass().getMethod("getResourcePaths", null); if (method != null) { returnSet = (Set)method.invoke(m_OriginalContext, null); } else { throw new RuntimeException("Method ServletContext.getResourcePaths() no longer supported by your servlet engine !"); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Error getting/calling method getResourcePaths()"); } return returnSet; } /** * Added to support the changes of the Jakarta Servlet API 2.3 of the * 17/03/2001 (in anticipation of the upcoming draft of Servlet 2.3). Kept * the method without parameters for servlet engines that do have upgraded * yet to the new signature. */ public Set getResourcePaths(String thePath) { Set returnSet; // Check if the method exist (for servlet engines that do not have // upgraded yet) try { Method method = m_OriginalContext.getClass().getMethod("getResourcePaths", new Class[] { String.class }); if (method != null) { returnSet = (Set)method.invoke(m_OriginalContext, new Object[] { thePath }); } else { throw new RuntimeException("Method ServletContext.getResourcePaths(String path) not supported yet by your servlet engine !"); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Error getting/calling method getResourcePaths(String path)"); } return returnSet; } public InputStream getResourceAsStream(String thePath) { return m_OriginalContext.getResourceAsStream(thePath); } public URL getResource(String thePath) throws MalformedURLException { return m_OriginalContext.getResource(thePath); } /** * @return our request dispatcher wrapper */ public RequestDispatcher getRequestDispatcher(String thePath) { RequestDispatcher dispatcher = new RequestDispatcherWrapper( m_OriginalContext.getRequestDispatcher(thePath)); return dispatcher; } public String getRealPath(String thePath) { return m_OriginalContext.getRealPath(thePath); } /** * @return our request dispatcher wrapper */ public RequestDispatcher getNamedDispatcher(String theName) { RequestDispatcher dispatcher = new RequestDispatcherWrapper( m_OriginalContext.getNamedDispatcher(theName)); return dispatcher; } public int getMinorVersion() { return m_OriginalContext.getMinorVersion(); } public String getMimeType(String theFilename) { return m_OriginalContext.getMimeType(theFilename); } public int getMajorVersion() { return m_OriginalContext.getMajorVersion(); } public Enumeration getInitParameterNames() { return m_OriginalContext.getInitParameterNames(); } public String getInitParameter(String theName) { return m_OriginalContext.getInitParameter(theName); } /** * @return our servlet context wrapper */ public ServletContext getContext(String theUripath) { ServletContext context = new ServletContextWrapper( m_OriginalContext.getContext(theUripath)); return context; } public Enumeration getAttributeNames() { return m_OriginalContext.getAttributeNames(); } public Object getAttribute(String theName) { return m_OriginalContext.getAttribute(theName); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/JspTestCase.java Index: JspTestCase.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import javax.servlet.jsp.*; import org.apache.commons.cactus.client.*; /** * Test classes that need access to valid JSP implicit objects (such as the * page context, the output jsp writer, the HTTP request, ...) must subclass * this class. It also provides support for <code>beginXXX</code> and * <code>endXXX()</code> methods. * * @version @version@ */ public class JspTestCase extends ServletTestCase { /** * Valid <code>PageContext</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public PageContext pageContext; /** * Valid <code>JspWriter</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public JspWriter out; /** * Constructs a JUnit test case with the given name. * * @param theName the name of the test case */ public JspTestCase(String theName) { super(theName); } /** * Runs a test case. This method is overriden from the JUnit * <code>TestCase</code> class in order to seamlessly call the * Cactus redirection servlet. */ protected void runTest() throws Throwable { runGenericTest(new JspHttpClient()); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceDefinition.java Index: ServiceDefinition.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; /** * Constants that define HTTP parameters required for defining a service that * is performed by the <code>ServletTestRedirector</code> servlet. */ public class ServiceDefinition { /** * Name of the parameter in the HTTP request that represents the name of the * Test class to call. The name is voluntarily long so that it will not clash * with a user-defined parameter. */ public final static String CLASS_NAME_PARAM = "ServletTestRedirector_TestClass"; /** * Name of the parameter in the HTTP request that represents the name of the * Test method to call. The name is voluntarily long so that it will not clash * with a user-defined parameter. */ public final static String METHOD_NAME_PARAM = "ServletTestRedirector_TestMethod"; /** * Name of the parameter in the HTTP request that specify if a session * should be automatically created for the user or not. */ public final static String AUTOSESSION_NAME_PARAM = "ServletTestRedirector_AutomaticSession"; /** * Name of the parameter in the HTTP request that specify the service asked * to the Redirector Servlet. It can be either to ask the Redirector Servlet * to call the test method or to ask the Redirector Servlet to return the * result of the last test. * * @see ServiceEnumeration */ public final static String SERVICE_NAME_PARAM = "ServletTestRedirector_Service"; } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServiceEnumeration.java Index: ServiceEnumeration.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; /** * List of valid services that the <code>ServletTestRedirector</code> can perform. */ public class ServiceEnumeration { /** * Call test method Service. */ public static final ServiceEnumeration CALL_TEST_SERVICE = new ServiceEnumeration("CALL_TEST"); /** * Get the previous test results Service. */ public static final ServiceEnumeration GET_RESULTS_SERVICE = new ServiceEnumeration("GET_RESULTS"); /** * The service's name */ private String m_Name; public ServiceEnumeration(String theServiceName) { m_Name = theServiceName; } /** * Compares a string representing the name of the service with the Service enumerated type. * @return true if the string corresponds to the current Service */ public boolean equals(String theString) { return theString.equals(m_Name); } /** * @return the Service's name */ public String toString() { return m_Name; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestCase.java Index: ServletTestCase.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import java.lang.reflect.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import junit.framework.*; import org.apache.commons.cactus.client.*; import org.apache.commons.cactus.server.*; /** * Test classes that need access to valid Servlet implicit objects (such as the * the HTTP request, the HTTP response, the servlet config, ...) must subclass * this class. It also provides support for <code>beginXXX</code> and * <code>endXXX()</code> methods. * * @version @version@ */ public class ServletTestCase extends TestCase { /** * The prefix of a test method. */ protected final static String TEST_METHOD_PREFIX = "test"; /** * The prefix of a begin test method. */ protected final static String BEGIN_METHOD_PREFIX = "begin"; /** * The prefix of an end test method. */ protected final static String END_METHOD_PREFIX = "end"; /** * Valid <code>HttpServletRequest</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public org.apache.commons.cactus.server.HttpServletRequestWrapper request; /** * Valid <code>HttpServletResponse</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public HttpServletResponse response; /** * Valid <code>HttpSession</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public HttpSession session; /** * Valid <code>ServletConfig</code> object that you can access from * the <code>testXXX()</code>, <code>setUp</code> and <code>tearDown()</code> * methods. If you try to access it from either the * <code>beginXXX()</code> or <code>endXXX()</code> methods it will * have the <code>null</code> value. */ public ServletConfigWrapper config; /** * The name of the current test method being executed. This name is valid * both on the client side and on the server side, meaning you can call it * from a <code>testXXX()</code>, <code>setUp()</code> or * <code>tearDown()</code> method, as well as from <code>beginXXX()</code> * and <code>endXXX()</code> methods. */ public String currentTestMethod; /** * Constructs a JUnit test case with the given name. * * @param theName the name of the test case */ public ServletTestCase(String theName) { super(theName); currentTestMethod = name(); } /** * @return the name of the test method to call without the * TEST_METHOD_PREFIX prefix */ private String getBaseMethodName() { // Sanity check if (!name().startsWith(TEST_METHOD_PREFIX)) { // qqq throw new InvalidMethodNameException throw new RuntimeException("bad name [" + name() + "]. It should start with [" + TEST_METHOD_PREFIX + "]."); } return name().substring(TEST_METHOD_PREFIX.length()); } /** * @return the name of the test begin method to call that initialize the * test by initializing the <code>ServletTestRequest</code> object * for the test case. */ protected String getBeginMethodName() { return BEGIN_METHOD_PREFIX + getBaseMethodName(); } /** * @return the name of the test end method to call when the test has been * run on the server. It can be used to verify returned headers, * cookies, ... */ protected String getEndMethodName() { return END_METHOD_PREFIX + getBaseMethodName(); } /** * Call the test case begin method * * @param theRequest the <code>ServletTestRequest</code> object to * pass to the begin method. */ protected void callBeginMethod(ServletTestRequest theRequest) throws Throwable { // First, verify if a begin method exist. If one is found, verify if // it has the correct signature. If not, send a warning. Method[] methods = getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(getBeginMethodName())) { // Check return type if (!methods[i].getReturnType().getName().equals("void")) { fail("The begin method [" + methods[i].getName() + "] should return void and not [" + methods[i].getReturnType().getName() + "]"); } // Check if method is public if (!Modifier.isPublic(methods[i].getModifiers())) { fail("Method [" + methods[i].getName() + "] should be declared public"); } // Check parameters Class[] parameters = methods[i].getParameterTypes(); if ((parameters.length != 1) || (!parameters[0].equals(ServletTestRequest.class))) { fail("The begin method [" + methods[i].getName() + "] must accept a single parameter of type [" + ServletTestRequest.class.getName() + "]"); } try { methods[i].invoke(this, new Object[] { theRequest }); } catch (InvocationTargetException e) { e.fillInStackTrace(); throw e.getTargetException(); } catch (IllegalAccessException e) { e.fillInStackTrace(); throw e; } } } } /** * Call the test case end method * * @param theConnection the <code>HttpURLConnection</code> that was used * to open the connection to the redirection servlet. The response * codes, headers, cookies can be checked using the get methods of * this object. */ protected void callEndMethod(HttpURLConnection theConnection) throws Throwable { // First, verify if an end method exist. If one is found, verify if // it has the correct signature. If not, send a warning. Method[] methods = getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(getEndMethodName())) { // Check return type if (!methods[i].getReturnType().getName().equals("void")) { fail("The end method [" + methods[i].getName() + "] should return void and not [" + methods[i].getReturnType().getName() + "]"); } // Check if method is public if (!Modifier.isPublic(methods[i].getModifiers())) { fail("Method [" + methods[i].getName() + "] should be declared public"); } // Check parameters Class[] parameters = methods[i].getParameterTypes(); if ((parameters.length != 1) || (!parameters[0].equals(HttpURLConnection.class))) { fail("The end method [" + methods[i].getName() + "] must accept a single parameter of type [" + HttpURLConnection.class.getName() + "]"); } try { methods[i].invoke(this, new Object[] { theConnection }); } catch (InvocationTargetException e) { e.fillInStackTrace(); throw e.getTargetException(); } catch (IllegalAccessException e) { e.fillInStackTrace(); throw e; } } } } /** * Runs the bare test sequence. This method is overridden from the * JUnit <code>TestCase</code> class in order to prevent the latter * to call the <code>setUp()</code> and <code>tearDown()</code> methods * which, in our case, need to be ran in the servlet engine by the * servlet redirector class. * * @exception Throwable if any exception is thrown */ public void runBare() throws Throwable { runTest(); } /** * Runs a test case. This method is overriden from the JUnit * <code>TestCase</code> class in order to seamlessly call the * Cactus redirection servlet. */ protected void runTest() throws Throwable { runGenericTest(new ServletHttpClient()); } protected void runGenericTest(AbstractHttpClient theHttpClient) throws Throwable { // Call the begin method to fill the request object ServletTestRequest request = new ServletTestRequest(); callBeginMethod(request); // Add the class name, the method name, the URL to simulate and // automatic session creation flag to the request request.addParameter(ServiceDefinition.CLASS_NAME_PARAM, this.getClass().getName()); request.addParameter(ServiceDefinition.METHOD_NAME_PARAM, name()); request.addParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM, new Boolean(request.getAutomaticSession()).toString()); // Add the simulated URL (if one has been defined) if (request.getURL() != null) { request.getURL().saveToRequest(request); } // Open the HTTP connection to the servlet redirector // and manage errors that could be returned in the // HTTP response. HttpURLConnection connection = theHttpClient.doTest(request); // Call the end method callEndMethod(connection); // Close the intput stream (just in the case the user has not done it // in it's endXXX method (or if he has no endXXX method) .... connection.getInputStream().close(); //connection.disconnect(); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestRequest.java Index: ServletTestRequest.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import java.util.*; /** * Contains all HTTP request data for a test case. It is the data that * will be sent to the server redirector and that will be available to the test * methods through the <code>HttpServletRequest</code> object. * <br><br> * Namely, it is : * <ul> * <li>Request parameters that the test case can retrieve using * <code>HttpServletRequest.getParameters()</code>,</li> * <li>Cookies that the test case can retrieve using * <code>HttpServletRequest.getCookies()</code>,</li> * <li>HTTP headers that the test case can retrieve using the * <code>HttpServletRequest.getHeader(), getHeaders(), * ...</code> APIs,</li> * <li>URL data the the test case can retrieve using * <code>HttpServletRequest.getRequestURI(), ...</code></li> * <li>Whether you want the server redirector to automatically create a * session for you or not,</li> * <li>Whether you want the HTTP connection to the server redirector to * use a POST or GET method. Default is POST</li> * </ul> * * @version @version@ */ public class ServletTestRequest { /** * The request parameters. */ private Hashtable m_Parameters = new Hashtable(); /** * GET Method identifier. */ public static final String GET_METHOD = "GET"; /** * POST Method identifier. */ public static final String POST_METHOD = "POST"; /** * The Cookies */ private Hashtable m_Cookies = new Hashtable(); /** * HTTP Headers. */ private Hashtable m_Headers = new Hashtable(); /** * The URL to simulate */ private ServletURL m_URL; /** * Automatic session creation flag (default is true). */ private boolean m_isAutomaticSession = true; /** * The chosen method for posting data (GET or POST) */ private String m_Method = POST_METHOD; /** * @param theMethod the method to use to post data (GET or POST) */ public void setMethod(String theMethod) { if (theMethod.equalsIgnoreCase(GET_METHOD)) { m_Method = GET_METHOD; } else if (theMethod.equalsIgnoreCase(POST_METHOD)) { m_Method = POST_METHOD; } } /** * @return the method to use for posting data to the server redirector. */ public String getMethod() { return m_Method; } /** * @param isAutomaticSession whether the redirector servlet will automatically * create the HTTP session or not. Default is true. */ public void setAutomaticSession(boolean isAutomaticSession) { m_isAutomaticSession = isAutomaticSession; } /** * @return true if session will be automatically created for the user or * false otherwise. */ public boolean getAutomaticSession() { return m_isAutomaticSession; } /** * Sets the simulated URL. A URL is of the form :<br> * <code><pre><b> * URL = "http://" + serverName (including port) + requestURI ? queryString<br> * requestURI = contextPath + servletPath + pathInfo * </b></pre></code> * From the Servlet 2.2 specification :<br> * <code><pre><ul><li><b>Context Path</b>: The path prefix associated with the * ServletContext that this servlet is a part of. If this context is the * default context rooted at the base of the web server's URL namespace, this * path will be an empty string. Otherwise, this path starts with a character * but does not end with a character.</li> * <li><b>Servlet Path</b>: The path section that directly corresponds to the * mapping which activated this request. This path starts with a character.</li> * <li><b>PathInfo</b>: The part of the request path that is not part of the * Context Path or the Servlet Path.</li></ul></pre></code> * * @param theServerName the server name (and port) in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getServerName()</code> and * <code>HttpServletRequest.getServerPort()</code>. * @param theContextPath the webapp context path in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getContextPath()</code>. * Can be null. Format: "/" + name or an empty string * for the default context. * @param theServletPath the servlet path in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getServletPath()</code>. * Can be null. Format : "/" + name. * @param thePathInfo the path info in the URL to simulate, i.e. this is * the name that will be returned by the * <code>HttpServletRequest.getPathInfo()</code>. Can * be null. Format : "/" + name. * @param theQueryString the Query string in the URL to simulate, i.e. this * is the string that will be returned by the * <code>HttpServletResquest.getQueryString()</code>. * Can be null. */ public void setURL(String theServerName, String theContextPath, String theServletPath, String thePathInfo, String theQueryString) { m_URL = new ServletURL(theServerName, theContextPath, theServletPath, thePathInfo, theQueryString); } /** * @return the simulated URL */ public ServletURL getURL() { return m_URL; } /** * Adds a parameter to the request. It is possible to add several times the * the same parameter name (the same as for the <code>HttpServletRequest</code>). * * @param theName the parameter's name * @param theValue the parameter's value */ public void addParameter(String theName, String theValue) { // If there is already a parameter of the same name, add the // new value to the Vector. If not, create a Vector an add it to the // hashtable if (m_Parameters.containsKey(theName)) { Vector v = (Vector)m_Parameters.get(theName); v.addElement(theValue); } else { Vector v = new Vector(); v.addElement(theValue); m_Parameters.put(theName, v); } } /** * @return the parameter names */ public Enumeration getParameterNames() { return m_Parameters.keys(); } /** * Returns the first value corresponding to this parameter's name. * * @param theName the parameter's name * @return the first value corresponding to this parameter's name or null if not * found */ public String getParameter(String theName) { String[] values = getParameterValues(theName); if (values != null) { return values[0]; } return null; } /** * Returns all the values associated with this parameter's name. * * @param theName the parameter's name * @return the values corresponding to this parameter's name or null if not * found */ public String[] getParameterValues(String theName) { if (m_Parameters.containsKey(theName)) { Vector v = (Vector)m_Parameters.get(theName); Object[] objs = new Object[v.size()]; v.copyInto(objs); String[] result = new String[objs.length]; for (int i = 0; i < objs.length; i++) { result[i] = (String)objs[i]; } return result; } return null; } /** * Adds a cookie to the request. * * @param theName the cookie's name * @param theValue the cookie's value */ public void addCookie(String theName, String theValue) { m_Cookies.put(theName, theValue); } /** * @return the cookie names */ public Enumeration getCookieNames() { return m_Cookies.keys(); } /** * @param theName the cookie's name * @return the value corresponding to this cookie's name or null if not * found */ public String getCookieValue(String theName) { return (String)m_Cookies.get(theName); } /** * Adds a header to the request. * * @param theName the header's name * @param theValue the header's value */ public void addHeader(String theName, String theValue) { m_Headers.put(theName, theValue); } /** * @return the header names */ public Enumeration getHeaderNames() { return m_Headers.keys(); } /** * @param theName the header's name * @return the value corresponding to this header's name or null if not * found */ public String getHeaderValue(String theName) { return (String)m_Headers.get(theName); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletTestResult.java Index: ServletTestResult.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import java.io.*; /** * Represent the result of the execution of the Test class by the * server redirector.If any exception was raised during the test, it * is saved by this class. * * @version @version@ */ public class ServletTestResult implements Serializable { /** * Name of the exception class if an error occurred */ private String exceptionClassName; /** * Save the stack trace as text because otherwise it will not be * transmitted back to the client (the stack trac field in the * <code>Throwable</code> class is transient). */ private String exceptionStackTrace; /** * The exception message if an error occurred */ private String exceptionMessage; /** * Constructor to call when the test was ok and no error was raised. */ public ServletTestResult() { } /** * Constructor to call when an exception was raised during the test. * * @param theException the raised exception. */ public ServletTestResult(Throwable theException) { exceptionClassName = theException.getClass().getName(); exceptionMessage = theException.getMessage(); // Save the stack trace as text StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); theException.printStackTrace(pw); exceptionStackTrace = sw.toString(); } /** * @return the exception class name if an exception was raised or * <code>null</code> otherwise. */ public String getExceptionClassName() { return exceptionClassName; } /** * @return the exception message if an exception was raised or * <code>null</code> otherwise. */ public String getExceptionMessage() { return exceptionMessage; } /** * @return true if an exception was raised during the test, false otherwise. */ public boolean hasException() { return (exceptionClassName != null); } /** * @return the stack trace as a string */ public String getExceptionStackTrace() { return exceptionStackTrace; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/ServletURL.java Index: ServletURL.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import java.util.*; import java.io.*; import java.security.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; import junit.framework.*; /** * Simulate an HTTP URL by breaking it into its different parts :<br> * <code><pre><b> * URL = "http://" + serverName (including port) + requestURI ? queryString<br> * requestURI = contextPath + servletPath + pathInfo * </b></pre></code> * From the Servlet 2.2 specification :<br> * <code><pre><ul><li><b>Context Path</b>: The path prefix associated with the * ServletContext that this servlet is a part of. If this context is the * default context rooted at the base of the web server's URL namespace, this * path will be an empty string. Otherwise, this path starts with a character * but does not end with a character.</li> * <li><b>Servlet Path</b>: The path section that directly corresponds to the * mapping which activated this request. This path starts with a character.</li> * <li><b>PathInfo</b>: The part of the request path that is not part of the * Context Path or the Servlet Path.</li></ul></pre></code> * * @version @version@ */ public class ServletURL { /** * Name of the parameter in the HTTP request that represents the Server name * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ public final static String URL_SERVER_NAME_PARAM = "ServletTestCase_URL_Server"; /** * Name of the parameter in the HTTP request that represents the context path * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ public final static String URL_CONTEXT_PATH_PARAM = "ServletTestCase_URL_ContextPath"; /** * Name of the parameter in the HTTP request that represents the Servlet * Path in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ public final static String URL_SERVLET_PATH_PARAM = "ServletTestCase_URL_ServletPath"; /** * Name of the parameter in the HTTP request that represents the Path Info * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ public final static String URL_PATH_INFO_PARAM = "ServletTestCase_URL_PathInfo"; /** * Name of the parameter in the HTTP request that represents the Query String * in the URL to simulate. The name is voluntarily long so that it will not * clash with a user-defined parameter. */ public final static String URL_QUERY_STRING_PARAM = "ServletTestCase_URL_QueryString"; /** * The server name to simulate (including port number) */ private String m_URL_ServerName; /** * The context path to simulate */ private String m_URL_ContextPath; /** * The servlet path to simulate */ private String m_URL_ServletPath; /** * The Path Info to simulate */ private String m_URL_PathInfo; /** * The Query string */ private String m_URL_QueryString; /** * The full URL (useful later because we can benefit from the all * methods of the <code>URL</code> class. */ private URL m_FullURL; /** * Creates the URL to simulate. * * @param theServerName the server name (and port) in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getServerName()</code> and * <code>HttpServletRequest.getServerPort()</code>. * @param theContextPath the webapp context path in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getContextPath()</code>. * Can be null. Format: "/" + name or an empty string * for the default context. * @param theServletPath the servlet path in the URL to simulate, * i.e. this is the name that will be returned by the * <code>HttpServletRequest.getServletPath()</code>. * Can be null. Format : "/" + name. * @param thePathInfo the path info in the URL to simulate, i.e. this is * the name that will be returned by the * <code>HttpServletRequest.getPathInfo()</code>. Can * be null. Format : "/" + name. * @param theQueryString the Query string in the URL to simulate, i.e. this * is the string that will be returned by the * <code>HttpServletResquest.getQueryString()</code>. * Can be null. */ public ServletURL(String theServerName, String theContextPath, String theServletPath, String thePathInfo, String theQueryString) { if (theServerName == null) { throw new AssertionFailedError("Bad URL. The server name cannot be null"); } m_URL_ServerName = theServerName; m_URL_ContextPath = (theContextPath == null) ? "" : theContextPath; m_URL_ServletPath = theServletPath; m_URL_PathInfo = thePathInfo; m_URL_QueryString = theQueryString; // create a full URL String fullURL = "http://" + m_URL_ServerName; if (m_URL_ContextPath.length() != 0) { fullURL = fullURL + m_URL_ContextPath; } if ((m_URL_ServletPath != null) && (m_URL_ServletPath.length() != 0)) { fullURL = fullURL + m_URL_ServletPath; } if ((m_URL_PathInfo != null) && (m_URL_PathInfo.length() != 0)) { fullURL = fullURL + m_URL_PathInfo; } try { m_FullURL = new URL(fullURL); } catch (MalformedURLException e) { throw new AssertionFailedError("Bad URL [" + fullURL + "]"); } } /** * @return the full URL as a <code>URL</code> object. */ public URL getURL() { return m_FullURL; } /** * @return the simulated URL server name (including the port number) */ public String getServerName() { return m_URL_ServerName; } /** * @return the simulated URL context path */ public String getContextPath() { return m_URL_ContextPath; } /** * @return the simulated URL servlet path */ public String getServletPath() { return m_URL_ServletPath; } /** * @return the simulated URL path info */ public String getPathInfo() { return m_URL_PathInfo; } /** * @return the simulated Query String */ public String getQueryString() { return m_URL_QueryString; } /** * Saves the current URL to a <code>ServletTestRequest</code> object. * * @param theRequest the object to which the current URL should be saved to */ public void saveToRequest(ServletTestRequest theRequest) { if (m_URL_ServerName != null) { theRequest.addParameter(URL_SERVER_NAME_PARAM, getServerName()); } if (m_URL_ContextPath != null) { theRequest.addParameter(URL_CONTEXT_PATH_PARAM, getContextPath()); } if (m_URL_ServletPath != null) { theRequest.addParameter(URL_SERVLET_PATH_PARAM, getServletPath()); } if (m_URL_PathInfo != null) { theRequest.addParameter(URL_PATH_INFO_PARAM, getPathInfo()); } if (m_URL_QueryString != null) { theRequest.addParameter(URL_QUERY_STRING_PARAM, getQueryString()); } } /** * Creates a <code>ServletURL</code> object by loading it's values from the * HTTP request. * * @param theRequest the incoming HTTP request. */ public static ServletURL loadFromRequest(HttpServletRequest theRequest) { String serverName = theRequest.getParameter(URL_SERVER_NAME_PARAM); String contextPath = theRequest.getParameter(URL_CONTEXT_PATH_PARAM); String servletPath = theRequest.getParameter(URL_SERVLET_PATH_PARAM); String pathInfo = theRequest.getParameter(URL_PATH_INFO_PARAM); String queryString = theRequest.getParameter(URL_QUERY_STRING_PARAM); if (serverName != null) { return new ServletURL(serverName, contextPath, servletPath, pathInfo, queryString); } return null; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/overview.html Index: overview.html =================================================================== <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title></title> </head> <body> <p>Cactus is a JUnit extension to unit test server-side java code. A server- side java code is some code that is called either by a JSP or by a Servlet. Server-side code is also code that may need to have access to valid <code>HttpServletRequest</code>, <code>HttpServletResponse</code> and <code>HttpSession</code> objects.</p> <p>Go to the <a href="http://jakarta.apache.org/commons/cactus">Cactus web site</a> for all documentation and tutorials for installing and running Cactus</p> </body> </html> 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/package.html Index: package.html =================================================================== <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title></title> </head> <body> <p>Base package for the Cactus project. All the framework classes are located under subpackages of this package. </body> </html> 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/AbstractHttpClient.java Index: AbstractHttpClient.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.util.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Abstract class that all HTTP clients to the server redirector must extend. * It provides a common abstraction of the <code>doTest</code> method and * provides the URL to the server redirector servlet or JSP. * * @version @version@ */ public abstract class AbstractHttpClient { /** * Default URL to call the <code>jspRedirector</code> JSP. */ protected final static String m_JspRedirectorURL = PropertyResourceBundle.getBundle("cactus").getString("cactus.jspRedirectorURL"); /** * Default URL to call the <code>ServletRedirector</code> servlet. */ protected final static String m_ServletRedirectorURL = PropertyResourceBundle.getBundle("cactus").getString("cactus.servletRedirectorURL"); /** * Calls the test method indirectly by calling the Redirector servlet and * then open a second HTTP connection to retrieve the test results. * * @param theRequest the request containing all data to pass to the * redirector servlet. * * @return the <code>HttpURLConnection</code> that contains the HTTP * response when the test was called. * * @exception Throwable if an error occured in the test method or in the * redirector servlet. */ public abstract HttpURLConnection doTest(ServletTestRequest theRequest) throws Throwable; } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/AssertionFailedErrorWrapper.java Index: AssertionFailedErrorWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.io.*; import junit.framework.*; /** * Same as <code>ServletExceptionWrapper</code> except that this exception class * extends JUnit <code>AssertionFailedError</code> so that JUnit will * print a different message in it's runner console. * * @version @version@ */ public class AssertionFailedErrorWrapper extends AssertionFailedError { /** * The stack trace that was sent back from the servlet redirector as a * string. */ private String m_StackTrace; /** * The class name of the exception that was raised on the server side. */ private String m_ClassName; /** * Standard throwable constructor. * * @param theMessage the exception message */ public AssertionFailedErrorWrapper(String theMessage) { super(theMessage); } /** * Standard throwable constructor. */ public AssertionFailedErrorWrapper() { super(); } /** * The constructor to use to simulate a real exception. * * @param theMessage the server exception message * @param theClassName the server exception class name * @param theStackTrace the server exception stack trace */ public AssertionFailedErrorWrapper(String theMessage, String theClassName, String theStackTrace) { super(theMessage); m_ClassName = theClassName; m_StackTrace = theStackTrace; } /** * Simulates a printing of a stack trace by printing the string stack trace * * @param thePs the stream to which to output the stack trace */ public void printStackTrace(PrintStream thePs) { if (m_StackTrace == null) { thePs.print(getMessage()); } else { thePs.print(m_StackTrace); } } /** * Simulates a printing of a stack trace by printing the string stack trace * * @param thePw the writer to which to output the stack trace */ public void printStackTrace(PrintWriter thePw) { if (m_StackTrace == null) { thePw.print(getMessage()); } else { thePw.print(m_StackTrace); } } /** * As all the server exceptions are wrapped into this * <code>ServletExceptionWrapper</code> class, we need to be able to * know the original server exception class. * * @param theClass the class to compare with the server exception class */ public boolean instanceOf(Class theClass) { if (m_ClassName == null) { return false; } return theClass.getName().equals(m_ClassName); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/HttpClientHelper.java Index: HttpClientHelper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.util.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Helper class to open an HTTP connection to the server redirector and pass * to it HTTP parameters, Cookies and HTTP headers. * * @version @version@ */ class HttpClientHelper { /** * The URL that will be used for the HTTP connection. */ private String m_URL; /** * @param theURL the URL that will be used for the HTTP connection. */ public HttpClientHelper(String theURL) { m_URL = theURL; } /** * Add the parameters to the request using a GET method. * * @param theRequest the request containing all data to pass to the server * redirector. * @param theURL the URL used to connect to the server redirector. * @return the new URL */ private URL addParametersUsingGet(ServletTestRequest theRequest, URL theURL) throws Throwable { // If no parameters, then exit if (!theRequest.getParameterNames().hasMoreElements()) { return theURL; } StringBuffer queryString = new StringBuffer(); Enumeration keys = theRequest.getParameterNames(); if (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String[] values = theRequest.getParameterValues(key); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[0])); for (int i = 1; i < values.length; i++) { queryString.append('&'); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[i])); } } while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String[] values = theRequest.getParameterValues(key); for (int i = 0; i < values.length; i++) { queryString.append('&'); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[i])); } } String file; if (theURL.toString().indexOf("?") > 0) { file = theURL.getFile() + "&" + queryString.toString(); } else { file = theURL.getFile() + "?" + queryString.toString(); } return new URL(theURL.getProtocol(), theURL.getHost(), theURL.getPort(), file); } /** * Add the parameters to the request using a POST method. * * @param theRequest the request containing all data to pass to the server * redirector. * @param theConnection the HTTP connection */ private void addParametersUsingPost(ServletTestRequest theRequest, URLConnection theConnection) throws Throwable { // If no parameters, then exit if (!theRequest.getParameterNames().hasMoreElements()) { return; } PrintWriter out; try { out = new PrintWriter(theConnection.getOutputStream()); } catch (ConnectException e) { // Cannot connect to server, try to explain why ... String reason = "Cannot connect to URL [" + theConnection.getURL() + "]. Reason : [" + e.getMessage() + "]\r\n"; reason += "Possible reasons :\r\n"; reason += "\t- The server is not running,\r\n"; reason += "\t- The server redirector is not correctly mapped in web.xml,\r\n"; reason += "\t- Something else ... !"; throw new Exception(reason); } StringBuffer queryString = new StringBuffer(); Enumeration keys = theRequest.getParameterNames(); if (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String[] values = theRequest.getParameterValues(key); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[0])); for (int i = 1; i < values.length; i++) { queryString.append('&'); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[i])); } } while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String[] values = theRequest.getParameterValues(key); for (int i = 0; i < values.length; i++) { queryString.append('&'); queryString.append(key); queryString.append('='); queryString.append(URLEncoder.encode(values[i])); } } out.print(queryString.toString()); out.close(); } /** * Add the Cookies to the request. * * @param theRequest the request containing all data to pass to the server * redirector. * @param theConnection the HTTP connection */ private void addCookies(ServletTestRequest theRequest, URLConnection theConnection) { // If no Cookies, then exit if (!theRequest.getCookieNames().hasMoreElements()) { return; } Enumeration keys = theRequest.getCookieNames(); StringBuffer cookieString = new StringBuffer(); // Format of a Cookie string is (according to RFC 2109) : // cookie = "Cookie:" cookie-version // 1*((";" | ",") cookie-value) // cookie-value = NAME "=" VALUE [";" path] [";" domain] // cookie-version = "$Version" "=" value // NAME = attr // VALUE = value // path = "$Path" "=" value // domain = "$Domain" "=" value // Write the cookie version first cookieString.append("$Version=1"); // Possible improvement here: to add support for : // - path // - domain while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String value = (String)theRequest.getCookieValue(key); cookieString.append(';'); cookieString.append(URLEncoder.encode(key)); cookieString.append('='); cookieString.append(URLEncoder.encode(value)); } theConnection.setRequestProperty("Cookie", cookieString.toString()); } /** * Add the Headers to the request. * * @param theRequest the request containing all data to pass to the server * redirector. * @param theConnection the HTTP connection */ private void addHeaders(ServletTestRequest theRequest, URLConnection theConnection) { Enumeration keys = theRequest.getHeaderNames(); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String value = (String)theRequest.getHeaderValue(key); theConnection.setRequestProperty(key, value); } } /** * Calls the Servlet Redirector. * * @param theRequest the request containing all data to pass to the * server redirector. * * @exception Throwable if an unexpected error occured */ public HttpURLConnection connect(ServletTestRequest theRequest) throws Throwable { URL url = new URL(m_URL); // If the method is GET, add the parameters to the URL if (theRequest.getMethod().equals(theRequest.GET_METHOD)) { url = addParametersUsingGet(theRequest, url); } HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setDoInput(true); // Choose the method that we will use to post data if (theRequest.getMethod().equals(theRequest.POST_METHOD)) { connection.setDoOutput(true); } else { connection.setDoOutput(false); } connection.setUseCaches(false); // Add the other header fields addHeaders(theRequest, connection); // Add the cookies addCookies(theRequest, connection); // Add the POST parameters if (theRequest.getMethod().equals(theRequest.POST_METHOD)) { addParametersUsingPost(theRequest, connection); } // Open the connection and get the result connection.connect(); return connection; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/JspHttpClient.java Index: JspHttpClient.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.util.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Manage the logic for calling a test method (which need access to JSP * objects) located on the server side. First opens an HTTP connection to * the redirector JSP (which in trun calls the test) and get the test results * by opening a second HTTP connection but to the Servlet redirector (the tests * were saved in the application context scope). * * @version @version@ */ public class JspHttpClient extends AbstractHttpClient { /** * Calls the test method indirectly by calling the Redirector JSP and * then open a second HTTP connection to the Servlet Redirector to retrieve * the test results. * * @param theRequest the request containing all data to pass to the * redirector JSP. * * @return the <code>HttpURLConnection</code> object that contains the HTTP * response when the test was called. * * @exception Throwable if an error occured in the test method or in the * redirector servlet. */ public HttpURLConnection doTest(ServletTestRequest theRequest) throws Throwable { ServletTestResult result = null; HttpURLConnection connection = null; // Open the first connection to the redirector JSP HttpClientHelper helper1 = new HttpClientHelper(m_JspRedirectorURL); // Specify the service to call on the redirector side theRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM, ServiceEnumeration.CALL_TEST_SERVICE.toString()); connection = helper1.connect(theRequest); // Note: We need to get the input stream here to trigger the actual // call to the servlet ... Don't know why exactly ... :( connection.getInputStream(); // Open the second connection (to the Servlet redirector) to get the // test results HttpClientHelper helper2 = new HttpClientHelper(m_ServletRedirectorURL); ServletTestRequest resultsRequest = new ServletTestRequest(); resultsRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM, ServiceEnumeration.GET_RESULTS_SERVICE.toString()); HttpURLConnection resultConnection = helper2.connect(resultsRequest); // Read the results as a serialized object ObjectInputStream ois = new ObjectInputStream(resultConnection.getInputStream()); result = (ServletTestResult)ois.readObject(); ois.close(); // Check if the result object returned from the redirection servlet // contains an error or not. If yes, we need to raise an exception // for the JUnit framework to catch it. if (result.hasException()) { // Wrap the exception message and stack trace into a fake // class that extends Throwable (i.e. // <code>ServletExceptionWrapper</code>) with an overloaded // <code>printStackTrace()</code> methods so that when JUnit calls // this method it will print the stack trace that was set on the // <code>Throwable</code> is transient and thus cannot be // serialized ! throw new ServletExceptionWrapper( result.getExceptionMessage(), result.getExceptionClassName(), result.getExceptionStackTrace()); } return connection; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/ServletExceptionWrapper.java Index: ServletExceptionWrapper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.io.*; /** * Wrapper around a <code>Throwable</code> object. Whenever an exception occurs * in a test case executed on the server side, the text of this exception * along with the stack trace as a String are sent back in the HTTP response. * This is because some exceptions are not serializable and because the stack * trace is implemented as a <code>transient</code> variable by the JDK so it * cannot be transported in the response. However, we need to send a real * exception object to JUnit so that the exception stack trace will be printed * in the JUnit console. This class does this by being a <code>Throwable</code> * and overloading the <code>printStackTrace()</code> methods to print a * text stack trace. * * @version @version@ */ public class ServletExceptionWrapper extends Throwable { /** * The stack trace that was sent back from the servlet redirector as a * string. */ private String m_StackTrace; /** * The class name of the exception that was raised on the server side. */ private String m_ClassName; /** * Standard throwable constructor. * * @param theMessage the exception message */ public ServletExceptionWrapper(String theMessage) { super(theMessage); } /** * Standard throwable constructor. */ public ServletExceptionWrapper() { super(); } /** * The constructor to use to simulate a real exception. * * @param theMessage the server exception message * @param theClassName the server exception class name * @param theStackTrace the server exception stack trace */ public ServletExceptionWrapper(String theMessage, String theClassName, String theStackTrace) { super(theMessage); m_ClassName = theClassName; m_StackTrace = theStackTrace; } /** * Simulates a printing of a stack trace by printing the string stack trace * * @param thePs the stream to which to output the stack trace */ public void printStackTrace(PrintStream thePs) { if (m_StackTrace == null) { thePs.print(getMessage()); } else { thePs.print(m_StackTrace); } } /** * Simulates a printing of a stack trace by printing the string stack trace * * @param thePw the writer to which to output the stack trace */ public void printStackTrace(PrintWriter thePw) { if (m_StackTrace == null) { thePw.print(getMessage()); } else { thePw.print(m_StackTrace); } } /** * As all the server exceptions are wrapped into this * <code>ServletExceptionWrapper</code> class, we need to be able to * know the original server exception class. * * @param theClass the class to compare with the server exception class */ public boolean instanceOf(Class theClass) { if (m_ClassName == null) { return false; } return theClass.getName().equals(m_ClassName); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/client/ServletHttpClient.java Index: ServletHttpClient.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.client; import java.util.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Manage the logic for calling a test method (which need access to Servlet * objects) located on the server side. First opens an HTTP connection to * the redirector servlet (which in trun calls the test) and get the test results * by opening a second HTTP connection but to the redirector servlet (the tests * were saved in the application context scope). * * @version @version@ */ public class ServletHttpClient extends AbstractHttpClient { /** * Calls the test method indirectly by calling the Redirector servlet and * then open a second HTTP connection to retrieve the test results. * * @param theRequest the request containing all data to pass to the * redirector servlet. * * @return the <code>HttpURLConnection</code> that contains the HTTP * response when the test was called. * * @exception Throwable if an error occured in the test method or in the * redirector servlet. */ public HttpURLConnection doTest(ServletTestRequest theRequest) throws Throwable { ServletTestResult result = null; HttpURLConnection connection = null; // Open the first connection to the redirector servlet HttpClientHelper helper1 = new HttpClientHelper(m_ServletRedirectorURL); // Specify the service to call on the redirector side theRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM, ServiceEnumeration.CALL_TEST_SERVICE.toString()); connection = helper1.connect(theRequest); // Note: We need to get the input stream here to trigger the actual // call to the servlet ... Don't know why exactly ... :( connection.getInputStream(); // Open the second connection to get the test results HttpClientHelper helper2 = new HttpClientHelper(m_ServletRedirectorURL); ServletTestRequest resultsRequest = new ServletTestRequest(); resultsRequest.addParameter(ServiceDefinition.SERVICE_NAME_PARAM, ServiceEnumeration.GET_RESULTS_SERVICE.toString()); HttpURLConnection resultConnection = helper2.connect(resultsRequest); // Read the results as a serialized object ObjectInputStream ois = new ObjectInputStream(resultConnection.getInputStream()); result = (ServletTestResult)ois.readObject(); ois.close(); // Check if the result object returned from the redirection servlet // contains an error or not. If yes, we need to raise an exception // for the JUnit framework to catch it. if (result.hasException()) { // Wrap the exception message and stack trace into a fake // exception class with overloaded <code>printStackTrace()</code> // methods so that when JUnit calls this method it will print the // stack trace that was set on the server side. // If the error was an AssertionFailedError then we use an instance // of AssertionFailedErrorWrapper (so that JUnit recognize it is // an AssertionFailedError exception and print it differently in // it's runner console). Otherwise we use an instance of // ServletExceptionWrapper. if (result.getExceptionClassName().equals("junit.framework.AssertionFailedError")) { throw new AssertionFailedErrorWrapper( result.getExceptionMessage(), result.getExceptionClassName(), result.getExceptionStackTrace()); } else { throw new ServletExceptionWrapper( result.getExceptionMessage(), result.getExceptionClassName(), result.getExceptionStackTrace()); } } return connection; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/CallerHelper.java Index: CallerHelper.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.commons.cactus.*; /** * Helper class to call the <code>setUp()</code> and <code>tearDown()</code> * methods of the class to test on the server side. * * @version @version@ */ public class CallerHelper { /** * Call the <code>setUp</code> method if it exists. The <code>setUp()</code> * method is called for each test case. * * @param theTestCase the instance of the test case from which to call the * <code>setUp()</code> method. */ public static void callSetUpMethod(ServletTestCase theTestCase) throws Throwable { // Get the method to call Method method; try { method = theTestCase.getClass().getMethod("setUp", new Class[0]); } catch (NoSuchMethodException e) { // No set up method, do nothing return; } // ... and call it ! try { method.invoke(theTestCase, null); } catch (IllegalAccessException e) { throw new ServletException("Illegal access", e); } catch (InvocationTargetException e) { throw e.getTargetException(); } } /** * Call the <code>tearDown</code> method if it exists. The <code>tearDown()</code> * method is called for each test case. * * @param theTestCase the instance of the test case from which to call the * <code>tearDown()</code> method. */ public static void callTearDownMethod(ServletTestCase theTestCase) throws Throwable { // Get the method to call Method method; try { method = theTestCase.getClass().getMethod("tearDown", new Class[0]); } catch (NoSuchMethodException e) { // No tear down method, do nothing return; } // ... and call it ! try { method.invoke(theTestCase, null); } catch (IllegalAccessException e) { throw new ServletException("Illegal access", e); } catch (InvocationTargetException e) { throw e.getTargetException(); } } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/JspImplicitObjects.java Index: JspImplicitObjects.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import javax.servlet.jsp.*; /** * Holder class that contains the instances of the implicit objects that will * be accessible in the test classes (i.e. subclasses of * <code>JspTestCase</code>). * * @version @version@ */ public class JspImplicitObjects extends ServletImplicitObjects { /** * Correspond to the JSP <code>pageContext</code> implicit object that is * available in JSP pages. */ public PageContext m_PageContext; /** * Correspond to the JSP <code>out</code> implicit object that is * available in JSP pages. */ public JspWriter m_JspWriter; } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/JspTestCaller.java Index: JspTestCaller.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import org.apache.commons.cactus.*; /** * Call the test method on the server side after assigning the JSP implicit * objects using reflection. * * @version @version@ */ public class JspTestCaller { /** * Name of the attribute in the <code>application</code> scope that will * hold the results of the test. */ private final static String TEST_RESULTS = "ServletTestRedirector_TestResults"; /** * Call the method to test. * * @param theClassName the name of the test class to call * @param theMethod the name of the test method to call * @param theObjects the implicit objects that will be assigned by * reflection to the test class. */ private void callTestMethod(String theClassName, String theMethod, JspImplicitObjects theObjects) throws Throwable { // Get the class to call and build an instance of it. Class testClass = null; ServletTestCase testInstance = null; try { testClass = Class.forName(theClassName); Constructor constructor = testClass.getConstructor(new Class[] { String.class }); testInstance = (ServletTestCase)constructor.newInstance(new Object[] { theMethod }); } catch (Exception e) { throw new ServletException("Error instanciating class [" + theClassName + "]", e); } // Set the current method name field Field methodField = testClass.getField("currentTestMethod"); methodField.set(testInstance, theMethod); // Set the request field of the test case class // Extract from the HTTP request the URL to simulate (if any) ServletURL url = ServletURL.loadFromRequest(theObjects.m_Request); Field requestField = testClass.getField("request"); requestField.set(testInstance, new HttpServletRequestWrapper(theObjects.m_Request, url)); // Set the response field of the test case class Field responseField = testClass.getField("response"); responseField.set(testInstance, theObjects.m_Response); // Set the config field of the test case class Field configField = testClass.getField("config"); configField.set(testInstance, new ServletConfigWrapper(theObjects.m_Config)); // Set the page context field of the test case class Field pageContextField = testClass.getField("pageContext"); pageContextField.set(testInstance, theObjects.m_PageContext); // Set the JSP writer field of the test case class Field outField = testClass.getField("out"); outField.set(testInstance, theObjects.m_JspWriter); // Set the session field of the test case class // Get a valid session object if the auto session flag is on // Get the autologin flag from the request String autoSession = theObjects.m_Request.getParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM); boolean isAutomaticSession = new Boolean(autoSession).booleanValue(); if (isAutomaticSession) { theObjects.m_Session = theObjects.m_Request.getSession(true); Field sessionField = testClass.getField("session"); sessionField.set(testInstance, theObjects.m_Session); } // Call the setUp() method CallerHelper.callSetUpMethod(testInstance); // Get the method to call Method method; try { method = testClass.getMethod(theMethod, new Class[0]); } catch (Exception e) { throw new ServletException("Method " + theMethod + "() does not exist for class [" + theClassName + "].", e); } // Call the test method try { method.invoke(testInstance, null); } catch (IllegalAccessException e) { throw new ServletException("Illegal access", e); } catch (InvocationTargetException e) { throw e.getTargetException(); } // Call the tearDown() method CallerHelper.callTearDownMethod(testInstance); } /** * Calls a test method. The parameters needed to call this method are found * in the HTTP request. Save the results in the <code>application</code> * scope so that the Get Test Result service can find them. * * @param theObjects the implicit objects that will be assigned by * reflection to the test class. * @exception ServletException if an unexpected error occurred */ public void doTest(JspImplicitObjects theObjects) throws ServletException { ServletTestResult result = null; try { // Extract from the HTTP request the test class name and method to call. String testClassName = theObjects.m_Request.getParameter(ServiceDefinition.CLASS_NAME_PARAM); if (testClassName == null) { throw new ServletException("Missing parameter [" + ServiceDefinition.CLASS_NAME_PARAM + "] in HTTP request."); } String methodName = theObjects.m_Request.getParameter(ServiceDefinition.METHOD_NAME_PARAM); if (methodName == null) { throw new ServletException("Missing parameter [" + ServiceDefinition.METHOD_NAME_PARAM + "] in HTTP request."); } // Extract from the HTTP request the URL to simulate (if any) ServletURL url = ServletURL.loadFromRequest(theObjects.m_Request); // Call the method to test callTestMethod(testClassName, methodName, theObjects); // Return an instance of <code>ServletTestResult</code> with a // positive result. result = new ServletTestResult(); } catch (Throwable e) { // An error occurred, return an instance of // <code>ServletTestResult</code> with an exception. result = new ServletTestResult(e); } // Save the test result. theObjects.m_Config.getServletContext().setAttribute(TEST_RESULTS, result); } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/ServletImplicitObjects.java Index: ServletImplicitObjects.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import javax.servlet.*; import javax.servlet.http.*; /** * Holder class that contains the instances of the implicit objects that will * be accessible in the test classes (i.e. subclasses of * <code>ServletTestCase</code>). * * @version @version@ */ public class ServletImplicitObjects { /** * The HTTP request wrapper. */ public HttpServletRequest m_Request; /** * The original HTTP response object that is created by the servlet * container. */ public HttpServletResponse m_Response; /** * The HTTP session object. Can be <code>null</code> if no automatic * session creation has been asked by the user. */ public HttpSession m_Session; /** * The Servlet configuration object. */ public ServletConfig m_Config; } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/ServletTestCaller.java Index: ServletTestCaller.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.commons.cactus.*; /** * Call the test method on the server side after assigning the servlet implicit * objects using reflection and retri * * @version @version@ */ public class ServletTestCaller { /** * Name of the attribute in the <code>application</code> scope that will * hold the results of the test. */ private final static String TEST_RESULTS = "ServletTestRedirector_TestResults"; /** * Call the method to test. * * @param theClassName the name of the test class to call * @param theMethod the name of the test method to call * @param theObjects the implicit objects that will be assigned by * reflection to the test class. */ private void callTestMethod(String theClassName, String theMethod, ServletImplicitObjects theObjects) throws Throwable { // Get the class to call and build an instance of it. Class testClass = null; ServletTestCase testInstance = null; try { testClass = Class.forName(theClassName); Constructor constructor = testClass.getConstructor(new Class[] { String.class }); testInstance = (ServletTestCase)constructor.newInstance(new Object[] { theMethod }); } catch (Exception e) { throw new ServletException("Error instanciating class [" + theClassName + "]", e); } // Set the current method name field Field methodField = testClass.getField("currentTestMethod"); methodField.set(testInstance, theMethod); // Set the request field of the test case class // Extract from the HTTP request the URL to simulate (if any) ServletURL url = ServletURL.loadFromRequest(theObjects.m_Request); Field requestField = testClass.getField("request"); requestField.set(testInstance, new HttpServletRequestWrapper(theObjects.m_Request, url)); // Set the response field of the test case class Field responseField = testClass.getField("response"); responseField.set(testInstance, theObjects.m_Response); // Set the config field of the test case class Field configField = testClass.getField("config"); configField.set(testInstance, new ServletConfigWrapper(theObjects.m_Config)); // Set the session field of the test case class // Get a valid session object if the auto session flag is on // Get the autologin flag from the request String autoSession = theObjects.m_Request.getParameter(ServiceDefinition.AUTOSESSION_NAME_PARAM); boolean isAutomaticSession = new Boolean(autoSession).booleanValue(); if (isAutomaticSession) { theObjects.m_Session = theObjects.m_Request.getSession(true); Field sessionField = testClass.getField("session"); sessionField.set(testInstance, theObjects.m_Session); } // Call the setUp() method CallerHelper.callSetUpMethod(testInstance); // Get the method to call Method method; try { method = testClass.getMethod(theMethod, new Class[0]); } catch (Exception e) { throw new ServletException("Method " + theMethod + "() does not exist for class [" + theClassName + "].", e); } // Call the test method try { method.invoke(testInstance, null); } catch (IllegalAccessException e) { throw new ServletException("Illegal access", e); } catch (InvocationTargetException e) { throw e.getTargetException(); } // Call the tearDown() method CallerHelper.callTearDownMethod(testInstance); } /** * Calls a test method. The parameters needed to call this method are found * in the HTTP request. Save the results in the <code>application</code> * scope so that the Get Test Result service can find them. * * @param theObjects the implicit objects that will be assigned by * reflection to the test class. * @exception ServletException if an unexpected error occurred */ public void doTest(ServletImplicitObjects theObjects) throws ServletException { ServletTestResult result = null; try { // Extract from the HTTP request the test class name and method to call. String testClassName = theObjects.m_Request.getParameter(ServiceDefinition.CLASS_NAME_PARAM); if (testClassName == null) { throw new ServletException("Missing parameter [" + ServiceDefinition.CLASS_NAME_PARAM + "] in HTTP request."); } String methodName = theObjects.m_Request.getParameter(ServiceDefinition.METHOD_NAME_PARAM); if (methodName == null) { throw new ServletException("Missing parameter [" + ServiceDefinition.METHOD_NAME_PARAM + "] in HTTP request."); } // Call the method to test callTestMethod(testClassName, methodName, theObjects); // Return an instance of <code>ServletTestResult</code> with a // positive result. result = new ServletTestResult(); } catch (Throwable e) { // An error occurred, return an instance of // <code>ServletTestResult</code> with an exception. result = new ServletTestResult(e); } // Save the test result. theObjects.m_Config.getServletContext().setAttribute(TEST_RESULTS, result); } /** * Return the last test results as a serialized object in the HTTP response. * * @param theObjects the implicit objects that will be assigned by * reflection to the test class. * @exception ServletException if an unexpected error occurred */ public void doGetResults(ServletImplicitObjects theObjects) throws ServletException { ServletTestResult result = (ServletTestResult)theObjects.m_Config.getServletContext().getAttribute(TEST_RESULTS); if (result == null) { throw new ServletException("No test results found in the application scope"); } // Write back the results as a serialized object to the outgoing stream. try { OutputStream os = theObjects.m_Response.getOutputStream(); // Write back the result object as a serialized object ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(result); oos.flush(); oos.close(); } catch (IOException e) { throw new ServletException("Error writing ServletTestResult instance to output stream", e); } } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/server/ServletTestRedirector.java Index: ServletTestRedirector.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.server; import java.io.*; import java.lang.reflect.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.commons.cactus.*; /** * Generic Servlet redirector that calls a test method on the server side. * * @version @version@ * @see ServletTestCaller */ public class ServletTestRedirector extends HttpServlet { /** * Handle GET requests. * * @param theRequest the incoming HTTP client request * @param theResponse the outgoing HTTP client request to send back. * * @exception ServletException if an error occurred when sending back * the response to the client. */ public void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException { // Same handling than for a POST doPost(theRequest, theResponse); } /** * Handle POST request. Extract from the HTTP request parameter, the * Service to perform : call test method or return tests results. * * @param theRequest the incoming HTTP request. * @param theResponse the outgoing HTTP response. * * @exception ServletException if an unexpected error occurred */ public void doPost(HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException { // Call the correct Service method String serviceName = theRequest.getParameter(ServiceDefinition.SERVICE_NAME_PARAM); if (serviceName == null) { throw new ServletException("Missing parameter [" + ServiceDefinition.SERVICE_NAME_PARAM + "] in HTTP request."); } ServletTestCaller caller = new ServletTestCaller(); ServletImplicitObjects objects = new ServletImplicitObjects(); objects.m_Config = getServletConfig(); objects.m_Request = theRequest; objects.m_Response = theResponse; // Is it the call test method service ? if (ServiceEnumeration.CALL_TEST_SERVICE.equals(serviceName)) { caller.doTest(objects); // Is it the get test results service ? } else if (ServiceEnumeration.GET_RESULTS_SERVICE.equals(serviceName)) { caller.doGetResults(objects); } else { throw new ServletException("Unknown service [" + serviceName + "] in HTTP request."); } } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/util/AssertUtils.java Index: AssertUtils.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.util; import java.net.*; import java.util.*; import java.io.*; /** * Cactus utility classes to help assert returned results from server side * code. * * @version @version@ */ public class AssertUtils { /** * @param theConnection the connection object used to connect to the server * redirector. * @return the servlet output stream bytes as a string. */ public static String getResponseAsString(HttpURLConnection theConnection) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader input = new BufferedReader(new InputStreamReader(theConnection.getInputStream())); String str; while (null != ((str = input.readLine()))) { sb.append(str); } input.close (); return sb.toString(); } /** * Extract the cookies from a HTTP connection. * * @param theConnection the HTTP connection from which to extract server * returned cookies. * @return a hashtable of <code>ClientCookie</code> objects. */ public static Hashtable getCookies(HttpURLConnection theConnection) { // We conform to the RFC 2109 : // // The syntax for the Set-Cookie response header is // // set-cookie = "Set-Cookie:" cookies // cookies = 1#cookie // cookie = NAME "=" VALUE *(";" cookie-av) // NAME = attr // VALUE = value // cookie-av = "Comment" "=" value // | "Domain" "=" value // | "Max-Age" "=" value // | "Path" "=" value // | "Secure" // | "Version" "=" 1*DIGIT Hashtable cookies = new Hashtable(); // There can be several headers named "Set-Cookie", so loop through all // the headers, looking for cookies String headerName = theConnection.getHeaderFieldKey(0); String headerValue = theConnection.getHeaderField(0); for (int i = 1; (headerName != null) || (headerValue != null); i++) { if ((headerName != null) && headerName.equals("Set-Cookie")) { // Parse the cookie definition Vector clientCookies = parseSetCookieHeader(headerValue); if (clientCookies.isEmpty()) { continue; } // Check if the cookie name already exist in the hashtable. // If so, then add it to the vector of cookies for that name. String name = ((ClientCookie)clientCookies.elementAt(0)).getName(); if (cookies.containsKey(name)) { Vector cookieValues = (Vector)cookies.get(name); cookieValues.addAll(clientCookies); } else { Vector cookieValues = new Vector(); cookieValues.addAll(clientCookies); cookies.put(name, cookieValues); } } headerName = theConnection.getHeaderFieldKey(i); headerValue = theConnection.getHeaderField(i); } return cookies; } /** * Parse a single "Set-Cookie" header. * * @return a vector og <code>ClientCookie</code> objects containing the * parsed values from the "Set-Cookie" header. */ protected static Vector parseSetCookieHeader(String theHeaderValue) { String name; String value; String comment = null; String path = null; String domain = null; long maxAge = 0; boolean isSecure = false; float version = 1; Vector cookies = new Vector(); // Find all cookies, they are comma-separated StringTokenizer stCookies = new StringTokenizer(theHeaderValue, ","); while (stCookies.hasMoreTokens()) { String singleCookie = stCookies.nextToken(); singleCookie = singleCookie.trim(); // Parse a single cookie // Extract cookie values, they are semi-colon separated StringTokenizer stParams = new StringTokenizer(singleCookie, ";"); // The first parameter is always NAME = VALUE String param = stParams.nextToken(); param = param.trim(); int pos = param.indexOf("="); if (pos < 0) { System.err.println("Bad 'Set-Cookie' syntax, missing '=' [" + param + "]"); continue; } name = param.substring(0, pos).trim(); value = param.substring(pos + 1).trim(); while (stParams.hasMoreTokens()) { param = stParams.nextToken(); param = param.trim(); String left; String right; // Tokenize on "=" pos = param.indexOf("="); if (pos < 0) { left = param; right = ""; } else { left = param.substring(0, pos).trim(); right = param.substring(pos + 1).trim(); } // Is it a comment ? if (left.equalsIgnoreCase("comment")) { comment = right; } else if (left.equalsIgnoreCase("domain")) { domain = right; } else if (left.equalsIgnoreCase("max-age")) { maxAge = Long.parseLong(right); } else if (left.equalsIgnoreCase("path")) { path = right; } else if (left.equalsIgnoreCase("secure")) { isSecure = true; } else if (left.equalsIgnoreCase("version")) { version = Float.parseFloat(right); } else { System.err.println("Bad 'Set-Cookie' syntax, bad name [" + param + "]"); continue; } } // Create the client cookie ClientCookie cookie = new ClientCookie(name, value, comment, domain, maxAge, path, isSecure, version); cookies.add(cookie); } return cookies; } } 1.1 jakarta-commons/cactus/src/framework/share/org/apache/commons/cactus/util/ClientCookie.java Index: ClientCookie.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.util; /** * Contains cookie information for cookies returned from the server to the * client. * * @version @version@ */ public class ClientCookie { /** * The cookie's name. */ private String m_Name; /** * The cookie's value. */ private String m_Value; /** * The cookie's comment. */ private String m_Comment; /** * The cookie's domain. */ private String m_Domain; /** * The cookie's max age. */ private long m_MaxAge; /** * The cookie's path. */ private String m_Path; /** * Specify if the cookie is a secure cookie */ private boolean m_IsSecure; /** * The cookie's spec. version */ private float m_Version; /** * Construct a client cookie. * * @param theName the cookie's name * @param theValue the cookie's value * @param theComment the cookie's comment * @param theDomain the cookie's domain * @param theMaxAge the cookie's max age * @param thePath the cookie's path * @param isSecure true is the cookies is a secure cookie * @param theVersion the cookie's version */ public ClientCookie(String theName, String theValue, String theComment, String theDomain, long theMaxAge, String thePath, boolean isSecure, float theVersion) { m_Comment = theComment; m_Domain = theDomain; m_IsSecure = isSecure; m_MaxAge = theMaxAge; m_Name = theName; m_Path = thePath; m_Value = theValue; m_Version = theVersion; } /** * @return the cookie's name */ public String getName() { return m_Name; } /** * @return the cookie's value */ public String getValue() { return m_Value; } /** * @return the cookie's comment */ public String getComment() { return m_Comment; } /** * @return the cookie's domain */ public String getDomain() { return m_Domain; } /** * @return the cookie's max age */ public long getMaxAge() { return m_MaxAge; } /** * @return the cookie's path */ public String getPath() { return m_Path; } /** * @return true if the cookie is a secure cookie */ public boolean isSecure() { return m_IsSecure; } /** * @return the cookie's spec. version */ public float getVersion() { return m_Version; } } 1.1 jakarta-commons/cactus/src/sample/servlet22/org/apache/commons/cactus/sample/unit/TestServletTestCaseSpecific.java Index: TestServletTestCaseSpecific.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for testing <code>ServletTestCase</code>. These tests * are specific to Servlet API 2.2 only. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestServletTestCaseSpecific extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCaseSpecific(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCaseSpecific.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(); } // No specific tests for Servlet API 2.2 for the moment ! } 1.1 jakarta-commons/cactus/src/sample/servlet23/org/apache/commons/cactus/sample/unit/TestServletTestCaseSpecific.java Index: TestServletTestCaseSpecific.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for testing <code>ServletTestCase</code>. These tests * are specific to Servlet API 2.3 only. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestServletTestCaseSpecific extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCaseSpecific(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCaseSpecific.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(); } // No specific tests for Servlet API 2.3 for the moment ! } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/SampleServlet.java Index: SampleServlet.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; /** * Sample servlet that implement some very simple business logic. The goal is * to provide functional tests for Cactus, so we focus on providing as many * different test cases as possible rather than implementing a meaningful * business logic. * * @version @version@ */ public class SampleServlet extends HttpServlet { /** * Entry point for the servlet when a GET request is received. This will * be used to verify that we can test for the servlet output stream in * Cactus test cases. * * @param theRequest the HTTP request * @param theResponse the HTTP response */ public void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse) throws IOException { PrintWriter pw = theResponse.getWriter(); theResponse.setContentType("text/html"); pw.println("<html><head/><body>"); pw.println("A GET request"); pw.println("</body></html>"); } /** * Return the method used to send data from the client (POST or GET). This * will be used to verify that we can simulate POST or GET methods from * Cactus. This simulates a method which would test the method to * implement it's business logic. * * @param theRequest the HTTP request * @return the method used to post data */ public String checkMethod(HttpServletRequest theRequest) { return theRequest.getMethod(); } /** * Set some variable in the HTTP session. It verifies that a session object * has automatically been created by Cactus prior to calling this method. * * @param theRequest the HTTP request */ public void setSessionVariable(HttpServletRequest theRequest) { HttpSession session = theRequest.getSession(false); session.setAttribute("name_setSessionVariable", "value_setSessionVariable"); } /** * Set some attribute in the request. * * @param theRequest the HTTP request */ public void setRequestAttribute(HttpServletRequest theRequest) { theRequest.setAttribute("name_setRequestAttribute", "value_setRequestAttribute"); } /** * Get some parameters from the HTTP request. * * @param theRequest the HTTP request * @return a hashtable containing some parameters */ public Hashtable getRequestParameters(HttpServletRequest theRequest) { Hashtable params = new Hashtable(); params.put("param1", theRequest.getParameter("param1")); params.put("param2", theRequest.getParameter("param2")); return params; } /** * Get a header from the request. * * @param theRequest the HTTP request */ public String getRequestHeader(HttpServletRequest theRequest) { return theRequest.getHeader("testheader"); } /** * @return the cookies sent in the HTTP request * * @param theRequest the HTTP request */ public Hashtable getRequestCookies(HttpServletRequest theRequest) { Hashtable allCookies = new Hashtable(); Cookie[] cookies = theRequest.getCookies(); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; allCookies.put(cookie.getName(), cookie.getValue()); } return allCookies; } /** * Set a header in the HTTP response. This is to verify that Cactus tests * can assert the returned headers. * * @param theResponse the HTTP response */ public void setResponseHeader(HttpServletResponse theResponse) { theResponse.setHeader("responseheader", "this is a response header"); } /** * Set a cookie for sending back to the client. This is to verify that * it is possible with Cactus to assert the cookies returned to the client * * @param theResponse the HTTP response */ public void setResponseCookie(HttpServletResponse theResponse) { Cookie cookie = new Cookie("responsecookie", "this is a response cookie"); cookie.setDomain("jakarta.apache.org"); theResponse.addCookie(cookie); } /** * Use a <code>RequestDispatcher</code> to forward to a JSP page. This is * to verify that Cactus supports asserting the result, even in the case * of forwarding to another page. * * @param theRequest the HTTP request * @param theResponse the HTTP response * @param theConfig the servlet config object */ public void doForward(HttpServletRequest theRequest, HttpServletResponse theResponse, ServletConfig theConfig) throws IOException, ServletException { RequestDispatcher rd = theConfig.getServletContext().getRequestDispatcher("/test/test.jsp"); rd.forward(theRequest, theResponse); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/SampleServletConfig.java Index: SampleServletConfig.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; /** * Sample servlet to show how to unit test a servlet that makes calls to * <code>getServletConfig()</code>, <code>getServletContext()</code>, * <code>log()</code>, ... (i.e. methods inherited from * <code>GenericServlet</code>). * * @version @version@ */ public class SampleServletConfig extends HttpServlet { /** * Simulate a method that calls <code>getServletConfig()</code>. * * @return some data retrieved from the servlet configuration. */ public String getConfigData() { return getServletConfig().getInitParameter("param1"); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/TestSampleServlet.java Index: TestSampleServlet.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; import org.apache.commons.cactus.util.*; /** * Tests of the <code>SampleServlet</code> servlet class. * * @version @version@ */ public class TestSampleServlet extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestSampleServlet(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestSampleServlet.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestSampleServlet.class); } //------------------------------------------------------------------------- /** * Verify that we can assert the servlet output stream. */ public void testReadServletOutputStream() throws IOException { SampleServlet servlet = new SampleServlet(); servlet.doGet(request, response); } /** * Verify that we can assert the servlet output stream. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endReadServletOutputStream(HttpURLConnection theConnection) throws IOException { assertEquals("<html><head/><body>A GET request</body></html>", AssertUtils.getResponseAsString(theConnection)); } //------------------------------------------------------------------------- /** * Verify that we can simulate a POST request to a servlet. Note that * the POST method is the default method so we don't need to initialize * any parameter in <code>beginPostMethod()</code>. */ public void testPostMethod() { SampleServlet servlet = new SampleServlet(); assertEquals("POST", servlet.checkMethod(request)); } //------------------------------------------------------------------------- /** * Verify that we can simulate a GET request to a servlet. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginGetMethod(ServletTestRequest theRequest) { theRequest.setMethod(ServletTestRequest.GET_METHOD); } /** * Verify that we can simulate a GET request to a servlet */ public void testGetMethod() { SampleServlet servlet = new SampleServlet(); assertEquals("GET", servlet.checkMethod(request)); } //------------------------------------------------------------------------- /** * Verify that by default the session implicit object is available and can * be used. */ public void testSetAttribute() { SampleServlet servlet = new SampleServlet(); servlet.setSessionVariable(request); assert(session != null); assertEquals("value_setSessionVariable", session.getAttribute("name_setSessionVariable")); } /** * Verify that we can set an attribute in the request. */ public void testSetRequestAttribute() { SampleServlet servlet = new SampleServlet(); servlet.setRequestAttribute(request); assertEquals("value_setRequestAttribute", request.getAttribute("name_setRequestAttribute")); } //------------------------------------------------------------------------- /** * Verify that we can simulate HTTP parameters in the HTTP request. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSendParams(ServletTestRequest theRequest) { theRequest.addParameter("param1", "value1"); theRequest.addParameter("param2", "value2"); } /** * Verify that we can send several parameters in the HTTP request. */ public void testSendParams() { SampleServlet servlet = new SampleServlet(); Hashtable params = servlet.getRequestParameters(request); assert(params.get("param1") != null); assert(params.get("param2") != null); assertEquals("value1", params.get("param1")); assertEquals("value2", params.get("param2")); } //------------------------------------------------------------------------- /** * Verify that we can simulate HTTP headers in the HTTP request. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSendHeader(ServletTestRequest theRequest) { theRequest.addHeader("testheader", "this is a header test"); } /** * Verify that we can simulate HTTP headers in the HTTP request. */ public void testSendHeader() { SampleServlet servlet = new SampleServlet(); String headerValue = servlet.getRequestHeader(request); assertEquals("this is a header test", headerValue); } //------------------------------------------------------------------------- /** * Verify that we can simulate a single cookie sent in the HTTP request. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSendCookie(ServletTestRequest theRequest) { // Note: The cookie value that was chosen is a string without spaces // because there is a problem with Resin 1.2.1 which does not support // quoted cookies. It has been fixed since the 15/12/2000 release of // Resin. theRequest.addCookie("testcookie", "thisisacookie"); } /** * Verify that we can simulate a single cookie sent in the HTTP request. */ public void testSendCookie() { SampleServlet servlet = new SampleServlet(); Hashtable cookies = servlet.getRequestCookies(request); assert(cookies.get("testcookie") != null); assertEquals("thisisacookie", cookies.get("testcookie")); } /** * Verify that we can simulate multiple cookies sent in the HTTP request. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSendMultipleCookies(ServletTestRequest theRequest) { theRequest.addCookie("testcookie1", "cookie1"); theRequest.addCookie("testcookie2", "cookie2"); } /** * Verify that we can simulate multiple cookies sent in the HTTP request. */ public void testSendMultipleCookies() { SampleServlet servlet = new SampleServlet(); Hashtable cookies = servlet.getRequestCookies(request); assert(cookies.get("testcookie1") != null); assertEquals("cookie1", cookies.get("testcookie1")); assert(cookies.get("testcookie2") != null); assertEquals("cookie2", cookies.get("testcookie2")); } //------------------------------------------------------------------------- /** * Verify that it is possible to send back a header and verify it on the * client side. */ public void testReceiveHeader() { SampleServlet servlet = new SampleServlet(); servlet.setResponseHeader(response); } /** * Verify that it is possible to send back a header and verify it on the * client side. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endReceiveHeader(HttpURLConnection theConnection) { assertEquals("this is a response header", theConnection.getHeaderField("responseheader")); } //------------------------------------------------------------------------- /** * Test that it is possible to send back a Cookie and verify it on the * client side. */ public void testReceiveCookie() { SampleServlet servlet = new SampleServlet(); servlet.setResponseCookie(response); } /** * Test that it is possible to send back a Cookie and verify it on the * client side. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endReceiveCookie(HttpURLConnection theConnection) { Hashtable cookies = AssertUtils.getCookies(theConnection); Vector list = (Vector)cookies.get("responsecookie"); assert(list.size() == 1); ClientCookie cookie = (ClientCookie)list.elementAt(0); assertEquals("responsecookie", cookie.getName()); assertEquals("this is a response cookie", cookie.getValue()); assertEquals("jakarta.apache.org", cookie.getDomain()); } //------------------------------------------------------------------------- /** * Verify that we can use a <code>RequestDispatcher</code> in the class to * test and compare the result sent to the output stream on the client side. */ public void testRequestDispatcher() throws Exception { SampleServlet servlet = new SampleServlet(); servlet.doForward(request, response, config); } /** * Verify that we can use a <code>RequestDispatcher</code> in the class to * test and compare the result sent to the output stream on the client side. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endRequestDispatcher(HttpURLConnection theConnection) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader input = new BufferedReader(new InputStreamReader(theConnection.getInputStream())); String str; while (null != ((str = input.readLine()))) { sb.append(str); } input.close (); // We cannot test what is exactly returned by the called JSP between // different Servlet engine return different text ! For example some // return the JSP comment, other do not, ... // Thus, we only test for a match of "Hello !" assert(sb.toString().indexOf("Hello !") > 0); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/TestSampleServletConfig.java Index: TestSampleServletConfig.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; import org.apache.commons.cactus.util.*; /** * Tests of the <code>SampleServletConfig</code> servlet class. This to show * how servlet methods that makes calls to <code>getServletConfig()</code>, * <code>getServletContext()</code>, <code>log()</code>, ... (i.e. methods that * have been inherited from <code>GenericServlet</code>) can be unit-tested * with Cactus. * * @version @version@ */ public class TestSampleServletConfig extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestSampleServletConfig(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestSampleServletConfig.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestSampleServletConfig.class); } /** * Verify that we can unit test a servlet that makes calls to * <code>getServletConfig()</code>, <code>getServletContext()</code>, * <code>log()</code>, ... (i.e. methods inherited from * <code>GenericServlet</code>). * * @see TestSampleServletConfig_Helper */ public void testServletConfig() throws ServletException { SampleServletConfig servlet = new SampleServletConfig(); // VERY IMPORTANT : Call the init() method in order to initialize the // Servlet ServletConfig object. servlet.init(config); assertEquals("value1 used for testing", servlet.getConfigData()); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestJspTestCase.java Index: TestJspTestCase.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for testing <code>JspTestCase</code>. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestJspTestCase extends JspTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestJspTestCase(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestJspTestCase.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestJspTestCase.class); } //------------------------------------------------------------------------- /** * Verify that we write some text to the output Jsp writer. */ public void testOut() throws IOException { out.print("some text sent back using out"); } /** * Verify that we write some text to the output Jsp writer. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endOut(HttpURLConnection theConnection) throws IOException { StringBuffer sb = new StringBuffer(); BufferedReader input = new BufferedReader(new InputStreamReader(theConnection.getInputStream())); String str; while (null != ((str = input.readLine()))) { sb.append(str); } input.close (); assertEquals("some text sent back using out", sb.toString()); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase1.java Index: TestServletTestCase1.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for testing exception handling of * <code>ServletTestCase</code>. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * <br><br> * Note : This class extends * <code>TestServletTestCase1_InterceptorServletTestCase</code> (which itself * extends <code>ServletTestCase</code>) because we need to be able to verify * exception handling in our unit test cases so we must not let these exceptions * get through to JUnit (otherwise the test will appear as failed). * * @version @version@ */ public class TestServletTestCase1 extends TestServletTestCase1_InterceptorServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCase1(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCase1.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestServletTestCase1.class); } //------------------------------------------------------------------------- /** * Raises an <code>AssertionFailedError</code> exception. The exception is * caught in * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>. * This is to verify that <code>AssertionFailedError</code> raised on the * server side are properly propagated on the client side. */ public void testAssertionFailedError() { throw new AssertionFailedError("test assertion failed error"); } //------------------------------------------------------------------------- /** * Raises a non serializable exception. The exception is * caught in * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>. * This is to verify that non serializable exceptions raised on the * server side are properly propagated on the client side. * * @exception TestServletTestCaseHelper_ExceptionNotSerializable the non * serializable exception to thow */ public void testExceptionNotSerializable() throws TestServletTestCase1_ExceptionNotSerializable { throw new TestServletTestCase1_ExceptionNotSerializable("test non serializable exception"); } //------------------------------------------------------------------------- /** * Raises a serializable exception. The exception is * caught in * <code>TestServletTestCase_InterceptorServletTestCase.runTest()</code>. * This is to verify that serializable exceptions raised on the * server side are properly propagated on the client side. * * @exception TestServletTestCaseHelper_ExceptionSerializable the * serializable exception to throw */ public void testExceptionSerializable() throws TestServletTestCase1_ExceptionSerializable { throw new TestServletTestCase1_ExceptionSerializable("test serializable exception"); } //------------------------------------------------------------------------- /** * Test that when a begin method for a given test does not have the correct * return type (i.e. void), a <code>AssertionFailedError</code> exception * is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public String beginBeginMethodBadReturnType(ServletTestRequest theRequest) { // Return anything return ""; } /** * Test that when a begin method for a given test does not have the correct * return type (i.e. void), a <code>AssertionFailedError</code> exception * is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testBeginMethodBadReturnType() { // This method only exist so that a test exist and thus the begin // method for that test will be called. } //------------------------------------------------------------------------- /** * Test that when a begin method for a given test is not declared public * a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ private void beginBeginMethodNotPublic(ServletTestRequest theRequest) { } /** * Test that when a begin method for a given test is not declared public * a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testBeginMethodNotPublic() { } //------------------------------------------------------------------------- /** * Test that when a begin method for a given test has the wrong type of * parameters, a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void beginBeginMethodBadParams(String theDummy) { } /** * Test that when a begin method for a given test has the wrong type of * parameters, a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testBeginMethodBadParams() { } //------------------------------------------------------------------------- /** * Test that when an end method for a given test does not have the correct * return type (i.e. void), a <code>AssertionFailedError</code> exception * is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testEndMethodBadReturnType() { // This method only exist so that a test exist and thus the end // method for that test will be called. } /** * Test that when an end method for a given test does not have the correct * return type (i.e. void), a <code>AssertionFailedError</code> exception * is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public String endEndMethodBadReturnType(HttpURLConnection theConnection) { // Return anything return ""; } //------------------------------------------------------------------------- /** * Test that when an end method for a given test is not declared public * a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testEndMethodNotPublic() { } /** * Test that when an end method for a given test is not declared public * a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ private void endEndMethodNotPublic(HttpURLConnection theConnection) { } //------------------------------------------------------------------------- /** * Test that when an end method for a given test has the wrong type of * parameters, a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void testEndMethodBadParams() { } /** * Test that when an end method for a given test has the wrong type of * parameters, a <code>AssertionFailedError</code> exception is returned. * Note: the assert is done in the * <code>TestServletTestCase1_InterceptorServletTestCase</code> class. */ public void endEndMethodBadParams(String theDummy) { } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase1_ExceptionNotSerializable.java Index: TestServletTestCase1_ExceptionNotSerializable.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; /** * Used by <code>TestServletTestCase1</code> to test the case where * a non serializable exception is returned by a test method. * * @version @version@ * @see TestServletTestCase1 */ public class TestServletTestCase1_ExceptionNotSerializable extends Exception { /** * @param theMessage the exception message */ public TestServletTestCase1_ExceptionNotSerializable(String theMessage) { super(theMessage); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase1_ExceptionSerializable.java Index: TestServletTestCase1_ExceptionSerializable.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.io.*; /** * Used by <code>TestServletTestCase1</code> to test the case where * a serializable exception is raised by a test method. * * @version @version@ * @see TestServletTestCase1 */ public class TestServletTestCase1_ExceptionSerializable extends Exception implements Serializable { /** * @param theMessage the exception message. */ public TestServletTestCase1_ExceptionSerializable(String theMessage) { super(theMessage); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase1_InterceptorServletTestCase.java Index: TestServletTestCase1_InterceptorServletTestCase.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import junit.framework.*; import org.apache.commons.cactus.client.*; import org.apache.commons.cactus.*; /** * Helper class for the <code>TestServletTestCase1</code> tests. It is used to * intercept exceptions. Indeed, in order to verify excpetion handling in our * unit test cases we must not let these exceptions get through to JUnit * (otherwise the test will appear as failed). * * @version @version@ * @see TestServletTestCase1 */ public class TestServletTestCase1_InterceptorServletTestCase extends ServletTestCase { /** * Constructs a test case with the given name. * * @param theName the name of the test case */ public TestServletTestCase1_InterceptorServletTestCase(String theName) { super(theName); } /** * Intercepts running test cases to check for normal exceptions. */ protected void runTest() throws Throwable { try { super.runTest(); } catch (AssertionFailedErrorWrapper e) { // If the test case is "testAssertionFailedError" and the exception // is of type AssertionFailedError and contains the text // "test assertion failed error", then the test is ok. if (name().equals("testAssertionFailedError")) { if (e.instanceOf(AssertionFailedError.class)) { assertEquals("test assertion failed error", e.getMessage()); return; } } } catch (ServletExceptionWrapper e) { // If the test case is "testExceptionNotSerializable" and the exception // is of type TestServletTestCaseHelper1_ExceptionNotSerializable // and contains the text "test non serializable exception", then // the test is ok. if (name().equals("testExceptionNotSerializable")) { if (e.instanceOf(TestServletTestCase1_ExceptionNotSerializable.class)) { assertEquals("test non serializable exception", e.getMessage()); return; } } // If the test case is "testExceptionSerializable" and the exception // is of type TestServletTestCaseHelper1_ExceptionSerializable // and contains the text "test serializable exception", then // the test is ok. if (name().equals("testExceptionSerializable")) { assert(e.instanceOf(TestServletTestCase1_ExceptionSerializable.class)); assertEquals("test serializable exception", e.getMessage()); return; } throw e; } catch (Throwable e) { // Test that when a begin method for a given test does not have the correct // return type (i.e. void), a <code>AssertionFailedError</code> exception // is returned. if (name().equals("testBeginMethodBadReturnType")) { if (e instanceof AssertionFailedError) { assertEquals("The begin method [beginBeginMethodBadReturnType] should return void and not [java.lang.String]", e.getMessage()); return; } } // Test that when a begin method for a given test is not declared public // a <code>AssertionFailedError</code> exception is returned. // Note: the assert is done in the // <code>TestServletTestCase_InterceptorServletTestCase</code> class. if (name().equals("testBeginMethodNotPublic")) { if (e instanceof AssertionFailedError) { assertEquals("Method [beginBeginMethodNotPublic] should be declared public", e.getMessage()); return; } } // Test that when a begin method for a given test has the wrong // type of parameters, a <code>AssertionFailedError</code> exception // is returned. if (name().equals("testBeginMethodBadParams")) { if (e instanceof AssertionFailedError) { assertEquals("The begin method [beginBeginMethodBadParams] must accept a single parameter of type [org.apache.commons.cactus.ServletTestRequest]", e.getMessage()); return; } } // Test that when an end method for a given test does not have the correct // return type (i.e. void), a <code>AssertionFailedError</code> exception // is returned. if (name().equals("testEndMethodBadReturnType")) { if (e instanceof AssertionFailedError) { assertEquals("The end method [endEndMethodBadReturnType] should return void and not [java.lang.String]", e.getMessage()); return; } } // Test that when an end method for a given test is not declared public // a <code>AssertionFailedError</code> exception is returned. // Note: the assert is done in the // <code>TestServletTestCase_InterceptorServletTestCase</code> class. if (name().equals("testEndMethodNotPublic")) { if (e instanceof AssertionFailedError) { assertEquals("Method [endEndMethodNotPublic] should be declared public", e.getMessage()); return; } } // Test that when an end method for a given test has the wrong // type of parameters, a <code>AssertionFailedError</code> exception // is returned. if (name().equals("testEndMethodBadParams")) { if (e instanceof AssertionFailedError) { assertEquals("The end method [endEndMethodBadParams] must accept a single parameter of type [java.net.HttpURLConnection]", e.getMessage()); return; } } throw e; } } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase2.java Index: TestServletTestCase2.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Some Cactus unit tests for testing <code>ServletTestCase</code>. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestServletTestCase2 extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCase2(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCase2.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestServletTestCase2.class); } //------------------------------------------------------------------------- /** * Verify that it is possible to ask for no automatic session creation in * the <code>beginXXX()</code> method. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginNoAutomaticSessionCreation(ServletTestRequest theRequest) { theRequest.setAutomaticSession(false); } /** * Verify that it is possible to ask for no automatic session creation in * the <code>beginXXX()</code> method. */ public void testNoAutomaticSessionCreation() { assert("A valid session has been found when no session should exist", session == null); } //------------------------------------------------------------------------- /** * Verify that multi value parameters can be sent in the * <code>beingXXX()</code> method to the server redirector. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginMultiValueParameters(ServletTestRequest theRequest) { theRequest.addParameter("multivalue", "value 1"); theRequest.addParameter("multivalue", "value 2"); } /** * Verify that multi value parameters can be sent in the * <code>beingXXX()</code> method to the server redirector. */ public void testMultiValueParameters() { String[] values = request.getParameterValues("multivalue"); if (values[0].equals("value 1")) { assertEquals("value 2", values[1]); } else if (values[0].equals("value 2")) { assertEquals("value 1", values[1]); } else { fail("Shoud have returned a vector with the values \"value 1\" and \"value 2\""); } } //------------------------------------------------------------------------- /** * Verify that it is possible to write to the servlet output stream. */ public void testWriteOutputStream() throws IOException { PrintWriter pw = response.getWriter(); pw.println("should not result in an error"); } /** * Verify that it is possible to write to the servlet output stream. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endWriteOutputStream(HttpURLConnection theConnection) throws IOException { DataInputStream dis = new DataInputStream(theConnection.getInputStream()); assertEquals("should not result in an error", dis.readLine()); } //------------------------------------------------------------------------- /** * Verify that we can add parameters to the config list of parameters * programatically, without having to define them in <code>web.xml</code>. */ public void testSetConfigParameter() { config.setInitParameter("testparam", "test value"); assertEquals("test value", config.getInitParameter("testparam")); boolean found = false; Enumeration enum = config.getInitParameterNames(); while(enum.hasMoreElements()) { String name = (String)enum.nextElement(); if (name.equals("testparam")) { found = true; break; } } assert("[testparam] not found in parameter names", found); } //------------------------------------------------------------------------- /** * Verify that we can override the * <code>ServletConfig.getServletName()</code> method. */ public void testGetServletName() { config.setServletName("MyServlet"); assertEquals("MyServlet", config.getServletName()); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase3.java Index: TestServletTestCase3.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.io.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for verifying that <code>setUp()</code> and * <code>tearDown()</code> methods are called and can access implicit objects * in <code>ServletTestCase</code>. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestServletTestCase3 extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCase3(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCase3.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestServletTestCase3.class); } //------------------------------------------------------------------------- /** * Put a value in the session to verify that this method is called prior * to the test, and that it can access servlet implicit objects. */ public void setUp() { session.putValue("setUpFlag", "a setUp test flag"); } /** * Verify that <code>setUp()</code> has been called and that it put a * value in the session object. */ public void testSetUp() { assertEquals("a setUp test flag", session.getValue("setUpFlag")); } //------------------------------------------------------------------------- /** * Set an HTTP response header to verify that this method is called after * the test, and that it can access servlet implicit objects. */ public void tearDown() { response.setHeader("teardownheader", "tear down header"); } /** * Verify that <code>tearDown()</code> has been called and that it created * an HTTP reponse header. */ public void testTearDown() { } /** * Verify that <code>tearDown()</code> has been called and that it created * an HTTP reponse header. * * @param theConnection the HTTP connection that was used to call the * server redirector. It contains the returned HTTP * response. */ public void endTearDown(HttpURLConnection theConnection) { assertEquals("tear down header", theConnection.getHeaderField("teardownheader")); } } 1.1 jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase4.java Index: TestServletTestCase4.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.sample.unit; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import junit.framework.*; import org.apache.commons.cactus.*; /** * Cactus unit tests for testing simulation URL for * <code>ServletTestCase</code>. * * These tests should not really be part of the sample application functional * tests as they are unit tests for Cactus. However, they are unit tests that * need a servlet environment running for their execution, so they have been * package here for convenience. They can also be read by end-users to * understand how Cactus work. * * @version @version@ */ public class TestServletTestCase4 extends ServletTestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestServletTestCase4(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestServletTestCase4.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestServletTestCase4.class); } //------------------------------------------------------------------------- /** * Verify that we can simulate the basic parts of the URL : server name, * default server port of 80, no servlet context, URI. * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURLBasics(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", null, "/test/test.jsp", null, null); } /** * Verify that we can simulate the basic parts of the URL : server name, * default server port of 80, no servlet context, servlet path. */ public void testSimulatedURLBasics() { // Verify URI assertEquals("/test/test.jsp", request.getRequestURI()); // Verify server name assertEquals("jakarta.apache.org", request.getServerName()); // Returns 80 when no port is specified assertEquals(80, request.getServerPort()); // Return "" when no context path is defined assertEquals("", request.getContextPath()); } //------------------------------------------------------------------------- /** * Verify that we can simulate different parts of the URL. * Set 1 of test values (taken from Sun's Servlet API spec) * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURL1(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", "/mywebapp", "/test/test.jsp", null, null); } /** * Verify that we can simulate different parts of the URL. * Set 1 of test values (taken from Sun's Servlet API spec) */ public void testSimulatedURL1() { assertEquals("/mywebapp/test/test.jsp", request.getRequestURI()); assertEquals("jakarta.apache.org", request.getServerName()); assertEquals(80, request.getServerPort()); assertEquals("/mywebapp", request.getContextPath()); } //------------------------------------------------------------------------- /** * Verify that we can simulate different parts of the URL. * Set 2 of test values (taken from Sun's Servlet API spec) * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURL2(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", "/catalog", "/lawn", "/index.html", null); } /** * Verify that we can simulate different parts of the URL. * Set 2 of test values (taken from Sun's Servlet API spec) */ public void testSimulatedURL2() { assertEquals("jakarta.apache.org", request.getServerName()); assertEquals("/catalog/lawn/index.html", request.getRequestURI()); assertEquals(80, request.getServerPort()); assertEquals("/catalog", request.getContextPath()); assertEquals("/lawn", request.getServletPath()); assertEquals("/index.html", request.getPathInfo()); } //------------------------------------------------------------------------- /** * Verify that we can simulate different parts of the URL. * Set 3 of test values (taken from Sun's Servlet API spec) * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURL3(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", "/catalog", "/garden", "/implements/", null); } /** * Verify that we can simulate different parts of the URL. * Set 3 of test values (taken from Sun's Servlet API spec) */ public void testSimulatedURL3() { assertEquals("jakarta.apache.org", request.getServerName()); assertEquals("/catalog/garden/implements/", request.getRequestURI()); assertEquals(80, request.getServerPort()); assertEquals("/catalog", request.getContextPath()); assertEquals("/garden", request.getServletPath()); assertEquals("/implements/", request.getPathInfo()); } //------------------------------------------------------------------------- /** * Verify that we can simulate different parts of the URL. * Set 4 of test values (taken from Sun's Servlet API spec) * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURL4(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", "/catalog", "/help/feedback.jsp", null, null); } /** * Verify that we can simulate different parts of the URL. * Set 4 of test values (taken from Sun's Servlet API spec) */ public void testSimulatedURL4() { assertEquals("jakarta.apache.org", request.getServerName()); assertEquals("/catalog/help/feedback.jsp", request.getRequestURI()); assertEquals(80, request.getServerPort()); assertEquals("/catalog", request.getContextPath()); assertEquals("/help/feedback.jsp", request.getServletPath()); assert(request.getPathInfo() == null); } //------------------------------------------------------------------------- /** * Verify that we can simulate different parts of the URL. * Set 5 of test values (taken from Sun's Servlet API spec) * * @param theRequest the request object that serves to initialize the * HTTP connection to the server redirector. */ public void beginSimulatedURL5(ServletTestRequest theRequest) { theRequest.setURL("jakarta.apache.org", "/catalog", "/help/feedback.jsp", null, "PARAM1=param1&PARAM2=param2"); } /** * Verify that we can simulate different parts of the URL. * Set 5 of test values (taken from Sun's Servlet API spec) */ public void testSimulatedURL5() { assertEquals("jakarta.apache.org", request.getServerName()); assertEquals("/catalog/help/feedback.jsp", request.getRequestURI()); assertEquals(80, request.getServerPort()); assertEquals("/catalog", request.getContextPath()); assertEquals("/help/feedback.jsp", request.getServletPath()); assert(request.getPathInfo() == null); assertEquals("PARAM1=param1&PARAM2=param2", request.getQueryString()); } } 1.1 jakarta-commons/cactus/src/test/share/org/apache/commons/cactus/TestAll.java Index: TestAll.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus; import junit.framework.*; /** * Run all the unit tests of Cactus that do not need a servlet * environment to run. These other tests will be exercised in the sample * application. * * @version @version@ */ public class TestAll extends TestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestAll(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestAll.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { TestSuite suite = new TestSuite("Cactus unit tests not needing servlet engine"); suite.addTest(org.apache.commons.cactus.util.TestAssertUtils.suite()); return suite; } } 1.1 jakarta-commons/cactus/src/test/share/org/apache/commons/cactus/util/TestAssertUtils.java Index: TestAssertUtils.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.cactus.util; import java.util.*; import junit.framework.*; /** * Unit tests of the <code>AssertUtils</code> class. * * @version @version@ */ public class TestAssertUtils extends TestCase { /** * Defines the testcase name for JUnit. * * @param theName the testcase's name. */ public TestAssertUtils(String theName) { super(theName); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.ui.TestRunner.main(new String[] {TestAssertUtils.class.getName()}); } /** * @return a test suite (<code>TestSuite</code>) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestAssertUtils.class); } public void testParseSetCookieHeader1() { Vector cookies = AssertUtils.parseSetCookieHeader("testcookie=value;Domain=jakarta.apache.org"); assert(cookies.size() == 1); ClientCookie cookie = (ClientCookie)cookies.elementAt(0); assertEquals("testcookie", cookie.getName()); assertEquals("value", cookie.getValue()); assertEquals("jakarta.apache.org", cookie.getDomain()); assert(cookie.getComment() == null); assert(cookie.getMaxAge() == 0); assert(cookie.getPath() == null); assert(cookie.isSecure() == false); assert(cookie.getVersion() == 1); } public void testParseSetCookieHeader2() { Vector cookies = AssertUtils.parseSetCookieHeader("testcookie=value; domain=jakarta.apache.org"); assert(cookies.size() == 1); ClientCookie cookie = (ClientCookie)cookies.elementAt(0); assertEquals("testcookie", cookie.getName()); assertEquals("value", cookie.getValue()); assertEquals("jakarta.apache.org", cookie.getDomain()); assert(cookie.getComment() == null); assert(cookie.getMaxAge() == 0); assert(cookie.getPath() == null); assert(cookie.isSecure() == false); assert(cookie.getVersion() == 1); } } 1.1 jakarta-commons/cactus/web/redirector.jsp Index: redirector.jsp =================================================================== <%@page import="org.apache.commons.cactus.server.*" session="false" %><% /** * * Note: * It is very important not to put any character between the end * of the page tag and the beginning of the java code expression, otherwise, * the generated servlet containss a 'out.println("\r\n");' and this breaks * our mechanism ! */ /** * This JSP is used as a proxy to call your server-side unit tests. We use * a JSP rather than a servlet because for testing custom JSP tags for * example we need access to JSP implicit objects (PageContext and * JspWriter). */ JspTestCaller caller = new JspTestCaller(); JspImplicitObjects objects = new JspImplicitObjects(); objects.m_Config = config; objects.m_Request = request; objects.m_Response = response; objects.m_PageContext = pageContext; objects.m_JspWriter = out; caller.doTest(objects); %> 1.1 jakarta-commons/cactus/web/sample/test/test.jsp Index: test.jsp =================================================================== <%-- Test JSP used by the TestServletTestCase test class to test --%> <%-- RequestDispatcher call. --%> <html> <body> Hello ! </body> </html>