vmassol     01/05/06 05:07:32

  Modified:    .        build.properties.sample build.xml
  Added:       .        build-tests.xml
               conf/test cactus.properties struts-config.xml web.xml
               conf/test/tomcat32 server.xml
               conf/test/tomcat40 server.xml
               src/test/org/apache/struts/action TestActionServlet.java
  Log:
  modified build mechanism for enabling run of cactus unit tests on both Tomcat 3.2 
and Tomcat 4.0 servlet engines
  
  Revision  Changes    Path
  1.4       +22 -1     jakarta-struts/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/build.properties.sample,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.properties.sample   2001/04/29 00:37:00     1.3
  +++ build.properties.sample   2001/05/06 12:07:31     1.4
  @@ -6,7 +6,7 @@
   # to "build.properties" in the same directory that contains the Struts
   # "build.xml" file.
   #
  -# $Id: build.properties.sample,v 1.3 2001/04/29 00:37:00 craigmcc Exp $
  +# $Id: build.properties.sample,v 1.4 2001/05/06 12:07:31 vmassol Exp $
   # -----------------------------------------------------------------------------
   
   # WARNING:  The relative paths below assume that the build.xml file is in the
  @@ -38,3 +38,24 @@
   # going to execute the "deploy.catalina" target.
   xerces.jar=../xml-xerces/xerces.jar
   
  +# Properties related to Struts unit testing
  +# -----------------------------------------
  +
  +# Cactus jar for the Servlet API corresponding to the servlet.jar file
  +# selected above (either 2.2 or 2.3)
  +cactus.jar = ../jakarta-commons/cactus/out/servlet22/dist/lib/commons-cactus.jar 
  +
  +# Cactus Ant custom tasks jar
  +cactus.ant.jar = 
../jakarta-commons/cactus/out/servlet22/dist/lib/commons-cactus-ant.jar
  +
  +# JUnit jar file
  +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 Tomcat 4.0, comment the "tomcat.home.40" property.
  +
  +tomcat.home.32 = f:/applis/jakarta-tomcat-3.2.1
  +tomcat.home.40 = f:/applis/jakarta-tomcat-4.0-b1
  
  
  
  1.52      +62 -3     jakarta-struts/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/build.xml,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- build.xml 2001/05/04 19:12:13     1.51
  +++ build.xml 2001/05/06 12:07:31     1.52
  @@ -169,9 +169,9 @@
        description="Compile Struts library files">
           <javac srcdir="${src.share.dir}"
               destdir="${build.home}/library/classes"
  -            debug="${debug}"
  -            optimize="${optimize}"
  -            deprecation="${deprecation}">
  +            debug="${compile.debug}"
  +            optimize="${compile.optimize}"
  +            deprecation="${compile.deprecation}">
             <classpath refid="compile.classpath"/>
           </javac>
           <copy todir="${build.home}/library/classes">
  @@ -364,5 +364,64 @@
   -->
       <target name="all" depends="clean,compile.library,compile.webapps"
        description="Clean and build library and web applications"/>
  +
  +<!--
  +        Run tests on all servers not commented out in the build.properties file.
  +-->
  +    <target name="test.all" depends="test.tomcat.32,test.tomcat.40"
  +     description="Run unit tests on all servlet engines">
  +    </target>
  +
  +<!-- 
  +        Display a warning message if the needed servlet engine home property
  +        is not set (for Tomcat 3.2)
  +-->
  +    <target name="check.tests.tomcat.32" depends="compile.library" 
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>
  +
  +<!--
  +        Run the Struts unit tests in the Tomcat 3.2 servlet engine
  +-->
  +    <target name="test.tomcat.32" depends="check.tests.tomcat.32,compile.library"
  +     if="tomcat.home.32" description="Run unit tests on Tomcat 3.2">
  +
  +        <echo message="tomcat.home.32 = ${tomcat.home.32}"/>
  +        <ant antfile="build-tests.xml" target="test.tomcat.32"/>
  +    
  +    </target>
  +
  +<!-- 
  +        Display a warning message if the needed servlet engine home property
  +        is not set (for Tomcat 4)
  +-->
  +    <target name="check.tests.tomcat.40" depends="compile.library" 
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>
  +
  +<!--
  +        Run the Struts unit tests in the Tomcat 4.0 servlet engine
  +-->    
  +    <target name="test.tomcat.40" depends="check.tests.tomcat.40,compile.library"
  +     if="tomcat.home.40" description="Run unit tests on Tomcat 4.0">
  +
  +        <echo message="tomcat.home.40 = ${tomcat.home.40}"/>        
  +        <ant antfile="build-tests.xml" target="test.tomcat.40"/>
  +    
  +    </target>
   
   </project>
  
  
  
  1.1                  jakarta-struts/build-tests.xml
  
  Index: build-tests.xml
  ===================================================================
  <project name="Struts Unit Tests" default="test.tomcat.32" basedir=".">
  
  <!--
          This is a generic build.xml file for Ant that is used to run the
          Struts unit tests. This build file *must* be called from the
          build.xml file in order to inherit most of it's needed properties
          (See below for the list of these properties).
  -->
  
  <!-- ========== Prerequisite Properties =================================== -->
  
  
  <!--
          These properties MUST be set on the "ant" command line, the "antrc"
          properties file in your home directory, or from settings in a superior
          build.xml script.
  
          build.home                    Base directory into which we are building
                                        the Struts components.
  
          servlet.jar                   The servlet jar (either 2.2 or 2.3)
  
          cactus.jar                    The Cactus jar (either for Servlet API
                                        2.2 or 2.3)
  
          cactus.ant.jar                The Cactus custom Ant tasks jar
  
          junit.jar                     The JUnit jar
  
          tomcat.home.32                The home directory of where Tomcat 3.2
                                        is installed
  
          tomcat.home.40                The home directory of where Tomcat 4.0
                                        is installed
  
          compile.debug                 The debug mode for compilation
  
          compile.deprecation           The deprecation mode for compilation
  
          compile.optimize              The optimization mode for compilation
  
          src.dir                       The location of the source directory
  
          app.name                      The name of the Struts jar (without the
                                        '.jar' suffix
  
  -->
  
  <!-- ========== Initialization Properties ================================= -->
  
  <!--
          These property values may optionally be overridden with property
          settings from an "ant" command line, the "build.properties" file
          in this directory, the "build.properties" file in your home
          directory, or from settings in a superior build.xml script.
  -->
  
  
  <!-- ========== Derived Properties ======================================== -->
  
  <!--
          These property values are derived from values defined above, and
          generally should NOT be overridden by command line settings
  -->
  
      <!-- Source directory for tests -->
      <property name="src.test.dir" value="${src.dir}/test"/>
  
      <!-- Configuration directory for tests -->
      <property name="conf.test.dir" value="conf/test"/>
  
      <!-- Output directory for tests -->
      <property name="out.test.dir" value="${build.home}/test"/>
  
      <!-- Compilation Classpath -->
      <path id="compile.classpath">
        <pathelement location="${build.home}/library/${app.name}.jar"/>
        <pathelement location="${servlet.jar}"/>
        <pathelement location="${cactus.jar}"/>
        <pathelement location="${junit.jar}"/>
      </path>
  
  <!-- ========== Executable Targets ======================================== -->
  
  
  <!--
          Initialization of custom Ant tasks
  -->
      <target name="init">
  
          <taskdef name="runservertests"
              classname="org.apache.commons.cactus.ant.RunServerTestsTask">
  
              <classpath>
                  <pathelement location="${cactus.ant.jar}"/>
                  <pathelement path="${java.class.path}"/>
              </classpath>
          </taskdef>
  
      </target>
  
  <!-- 
          Create directories and copy files for the struts tests
  -->
      <target name="prepare.test" depends="init">
  
          <!-- Create target directories for classes -->
          <mkdir dir="${out.test.dir}/classes"/>
  
          <!-- Create directory where servlet engines will run -->
          <mkdir dir="${out.test.dir}/servers"/>
  
          <!-- Create a lib directory where needed libs for the test war will
               be put -->
          <mkdir dir="${out.test.dir}/lib"/>
  
      </target>
  
  <!-- 
          Compile unit tests
  -->
      <target name="compile.test" depends="prepare.test">
  
          <javac srcdir="${src.test.dir}"
              destdir="${out.test.dir}/classes"
              debug="${compile.debug}"
              optimize="${compile.optimize}"
              deprecation="${compile.deprecation}">
  
              <classpath refid="compile.classpath"/>
          </javac>
          <copy todir="${out.test.dir}/classes">
              <fileset dir="${src.test.dir}" includes="**/*.properties"/>
          </copy>
  
      </target>
  
  <!--
          Prepare test war (for all servlet engines)
  -->
      <target name="prepare.test.war" depends="compile.test" if="tomcat.home.32">
  
          <!-- Copy needed libs in /lib -->
          <copy file="${build.home}/library/${app.name}.jar"
              todir="${out.test.dir}/lib"/>
          <copy file="${junit.jar}" todir="${out.test.dir}/lib"/>
          <copy file="${cactus.jar}" todir="${out.test.dir}/lib"/>
  
          <war warfile="${out.test.dir}/test.war"
               webxml="${conf.test.dir}/web.xml">
  
              <classes dir="${out.test.dir}/classes"/>
  
              <!-- We need to copy the Cactus, JUnit and Struts 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 the test classes are loaded
                   by the war classloader. This will depend on servlet engines -->
  
              <lib dir="${out.test.dir}/lib"/>
  
              <webinf dir="${conf.test.dir}">
                  <include name="struts-config.xml"/>
              </webinf>
  
          </war>
  
      </target>
  
  <!--
          Start the Cactus test using JUnit test runner.
  -->
      <target name="run.test">
  
          <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
  
              <classpath>
                  <pathelement path="${java.class.path}"/>
                  <pathelement location="${out.test.dir}/classes"/>
                  <!-- For cactus.properties -->
                  <pathelement location="${conf.test.dir}"/>
              </classpath>
              <classpath refid="compile.classpath"/>
  
              <formatter type="plain" usefile="false"/>
  
              <!-- Suite of tests -->
              <test name="org.apache.struts.action.TestActionServlet"/>
  
          </junit>
  
      </target>
  
  <!--
          Prepare test directory structure for Tomcat 3.2 servlet engine
  -->
      <target name="prepare.test.tomcat.32" depends="prepare.test.war" 
if="tomcat.home.32">
  
          <property name="out.tomcat.32.dir" value="${out.test.dir}/servers/tomcat32"/>
          <filter token="out.tomcat.32.dir" value="${out.tomcat.32.dir}"/>
  
          <mkdir dir="${out.tomcat.32.dir}/webapps"/>
          <mkdir dir="${out.tomcat.32.dir}/conf"/>
  
          <!-- Copy war file -->
          <copy file="${out.test.dir}/test.war" todir="${out.tomcat.32.dir}/webapps"/>
      
          <!-- Copy configuration files -->
          <copy file="${conf.test.dir}/tomcat32/server.xml"
              todir="${out.tomcat.32.dir}/conf" filtering="on"/>
  
      </target>
  
  <!--
          Run unit tests on Tomcat 3.2 servlet engine
  -->
      <target name="test.tomcat.32" depends="prepare.test.tomcat.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 automatically stopped if the tests fail for
               any reason.-->
  
          <runservertests testURL="http://localhost:8080/test";
              startTarget="start.tomcat.32"
              stopTarget="stop.tomcat.32"
              testTarget="run.test"/>
  
      </target>
  
  <!--
          Start Tomcat 3.2 servlet engine
  -->
      <target name="start.tomcat.32">
  
          <java classname="org.apache.tomcat.startup.Tomcat" fork="yes">
              <arg value="-config"/>
              <arg value="${out.tomcat.32.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 servlet engine
  -->
      <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>
  
  <!--
          Prepare test directory structure for Tomcat 4.0 servlet engine
  -->
      <target name="prepare.test.tomcat.40" depends="prepare.test.war" 
if="tomcat.home.40">
  
          <property name="out.tomcat.40.dir" value="${out.test.dir}/servers/tomcat40"/>
          <filter token="out.tomcat.40.full.dir" 
value="${basedir}/${out.tomcat.40.dir}"/>
  
          <mkdir dir="${out.tomcat.40.dir}/webapps"/>
          <mkdir dir="${out.tomcat.40.dir}/conf"/>
  
          <!-- Copy war file -->
          <copy file="${out.test.dir}/test.war" todir="${out.tomcat.40.dir}/webapps"/>
      
          <!-- Copy configuration files -->
          <copy file="${conf.test.dir}/tomcat40/server.xml"
              todir="${out.tomcat.40.dir}/conf" filtering="on"/>
  
      </target>
  
  <!--
          Run unit tests on Tomcat 4.0 servlet engine
  -->
      <target name="test.tomcat.40" depends="prepare.test.tomcat.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 automatically stopped if the tests fail for
               any reason.-->
  
          <runservertests testURL="http://localhost:8080/test";
              startTarget="start.tomcat.40"
              stopTarget="stop.tomcat.40"
              testTarget="run.test"/>
  
      </target>
  
  <!--
          Start Tomcat 4.0 servlet engine
  -->
      <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="${basedir}/${out.tomcat.40.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 servlet engine
  -->
      <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>
  
  </project>
  
  
  
  1.1                  jakarta-struts/conf/test/cactus.properties
  
  Index: cactus.properties
  ===================================================================
  # Configuration file for J2EEUnit.
  
  # Each project using J2EEUnit 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 J2EEUnit 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-struts/conf/test/struts-config.xml
  
  Index: struts-config.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  
  <!DOCTYPE struts-config PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
            "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";>
  
  <!--
       This is a test Struts configuration file
  -->
  
  
  <struts-config>
  
  
    <!-- ========== Data Source Configuration =============================== -->
  <!--
    <data-sources>
      <data-source
         autoCommit="false"
        description="Example Data Source Configuration"
        driverClass="org.postgresql.Driver"
           maxCount="4"
           minCount="2"
           password="mypassword"
                url="jdbc:postgresql://localhost/mydatabase"
               user="myusername"
      />
    </data-sources>
  -->
  
    <!-- ========== Form Bean Definitions =================================== -->
    <form-beans>
  
      <!-- Example logon form bean 
      <form-bean      name="logonForm"
                      type="org.apache.struts.example.LogonForm"/>
       -->
  
    </form-beans>
  
  
    <!-- ========== Global Forward Definitions ============================== -->
    <global-forwards>
  
      <!-- Example logon forward 
       <forward   name="logon"                path="/logon.jsp"/>
       -->
  
    </global-forwards>
  
  
    <!-- ========== Action Mapping Definitions ============================== -->
    <action-mappings>
  
      <!-- Example logon action 
      <action    path="/logon"
                 type="org.apache.struts.example.LogonAction"
                 name="logonForm"
                scope="request"
                input="/logon.jsp">
      </action>
      -->
  
      <!-- Example logoff action 
      <action    path="/logoff"
                 type="org.apache.struts.example.LogoffAction">
        <forward name="success"              path="/index.jsp"/>
      </action>
      -->
  
  
      <!-- The standard administrative actions available with Struts -->
      <!-- These would be either omitted or protected by security -->
      <!-- in a real application deployment -->
      <action    path="/admin/addFormBean"
                 type="org.apache.struts.actions.AddFormBeanAction"/>
      <action    path="/admin/addForward"
                 type="org.apache.struts.actions.AddForwardAction"/>
      <action    path="/admin/addMapping"
                 type="org.apache.struts.actions.AddMappingAction"/>
      <action    path="/admin/reload"
                 type="org.apache.struts.actions.ReloadAction"/>
      <action    path="/admin/removeFormBean"
                 type="org.apache.struts.actions.RemoveFormBeanAction"/>
      <action    path="/admin/removeForward"
                 type="org.apache.struts.actions.RemoveForwardAction"/>
      <action    path="/admin/removeMapping"
                 type="org.apache.struts.actions.RemoveMappingAction"/>
  
  
    </action-mappings>
  
  </struts-config>
  
  
  
  1.1                  jakarta-struts/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>
      </servlet>
  
      <servlet-mapping>
          <servlet-name>ServletRedirector</servlet-name>
          <url-pattern>/ServletRedirector</url-pattern>
      </servlet-mapping>
  
  </web-app>
  
  
  
  1.1                  jakarta-struts/conf/test/tomcat32/server.xml
  
  Index: server.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <Server>
  
    <ContextManager home="@out.tomcat.32.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-struts/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.tomcat.40.full.dir@/webapps">
        </Host>
  
      </Engine>
  
    </Service>
  
  </Server>
  
  
  
  1.1                  
jakarta-struts/src/test/org/apache/struts/action/TestActionServlet.java
  
  Index: TestActionServlet.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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", "Struts", 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.struts.action;
  
  import javax.servlet.*;
  
  import junit.framework.*;
  import org.apache.commons.cactus.*;
  
  /**
   * Suite of unit tests for the
   * <code>org.apache.struts.action.ActionServlet</code> class.
   */
  public class TestActionServlet extends ServletTestCase
  {
      /**
       * Defines the testcase name for JUnit.
       *
       * @param theName the testcase's name.
       */
      public TestActionServlet(String theName)
      {
          super(theName);
      }
  
      /**
       * Start the tests.
       *
       * @param theArgs the arguments. Not used
       */
      public static void main(String[] theArgs)
      {
          junit.awtui.TestRunner.main(new String[] 
{TestActionServlet.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(TestActionServlet.class);
      }
  
      //----- Test initApplication() method --------------------------------------
  
      /**
       * Verify that nothing happens if no "application" property is defined in
       * the servlet configuration.
       */
      public void testInitApplicationNull() throws ServletException
      {
          ActionServlet servlet = new ActionServlet();
          servlet.init(config);        
  
          // Test the initApplication() method
          servlet.initApplication();
  
          // As no "application" object is found in the servlet config, no
          // attribute should be set in the context
          assert(config.getServletContext().getAttribute(Action.MESSAGES_KEY) == null);
      }
  
      /**
       * Verify that eveything is fine when only a "application" parameter is
       * defined in the servlet configuration.
       */
      public void testInitApplicationOk1() throws ServletException
      {
          // initialize config
          config.setInitParameter("application", 
"org.apache.struts.example.ApplicationResources");
  
          ActionServlet servlet = new ActionServlet();
          servlet.init(config);        
  
          // Test the initApplication() method
          servlet.initApplication();
  
          assert(servlet.application != null);
          assert(servlet.application.getReturnNull() == true);
  
          assert(config.getServletContext().getAttribute(Action.MESSAGES_KEY) != null);
          assertEquals(servlet.application, 
config.getServletContext().getAttribute(Action.MESSAGES_KEY));
  
      }
  
      // [...]
  }
  
  
  

Reply via email to