craigmcc    00/12/17 21:06:16

  Added:       tester   build.bat build.sh build.xml
               tester/src/bin tester.bat tester.sh tester.xml
               tester/src/tester/org/apache/tester Authentication01.java
                        Authentication02.java GetInputStream01.java
                        GetParameter01.java GetParameterMap00.java
                        GetQueryString01.java TestClient.java
               tester/web/WEB-INF web.xml
  Log:
  Add the initial version of a unit testing suite for Tomcat 4.0.  The test
  client is a custom Ant task modelled after the GTest task used by the
  Watchdog tests, but which uses HttpURLConnection instead of a low level
  socket connection for processing.
  
  The intent of this suite is to host unit tests for Tomcat-specific
  functionality, rather than the spec compliance that is checked by
  Watchdog.  As such, the tests rely on specifics of the way that a default
  Tomcat 4.0 installation is laid out.
  
  Currently, the tester suite is *not* integrated in the top-level build
  scripts for Tomcat 4.0.  To build and deploy it to the "build" version,
  execute the following commands from the top level directory of the source:
  
        cd tester
        ./build.sh deploy-main
  
  and then restart Tomcat 4.0.  To execute the tests, execute:
  
        $CATALINA_HOME/bin/tester.sh
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/tester/build.bat
  
  Index: build.bat
  ===================================================================
  @echo off
  rem ---------------------------------------------------------------------------
  rem build.bat - Build Script for Tester
  rem
  rem Environment Variable Prerequisites:
  rem
  rem   ANT_HOME         Must point at your Ant installation [../jakarta-ant]
  rem
  rem   ANT_OPTS         Command line options to the Java runtime
  rem                    that executes Ant [NONE]
  rem
  rem   JAVA_HOME        Must point at your Java Development Kit [REQUIRED]
  rem
  rem $Id: build.bat,v 1.1 2000/12/18 05:06:11 craigmcc Exp $
  rem ---------------------------------------------------------------------------
  
  
  rem ----- Save Environment Variables ------------------------------------------
  
  set _CLASSPATH=%CLASSPATH%
  set _ANT_HOME=%ANT_HOME%
  
  
  rem ----- Verify and Set Required Environment Variables -----------------------
  
  
  if not "%JAVA_HOME%" == "" goto gotJavaHome
  echo You must set JAVA_HOME to point at your Java Development Kit installation
  goto cleanup
  :gotJavaHome
  
  if not "%ANT_HOME%" == "" goto gotAntHome
  set ANT_HOME=../jakarta-ant
  :gotAntHome
  
  
  rem ----- Set Up The Runtime Classpath ----------------------------------------
  
  if not "%CLASSPATH%" == "" set CLASSPATH=%CLASSPATH%;
  set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar;%JAVA_HOME%\lib\tools.jar
  
  
  rem ----- Execute The Requested Build -----------------------------------------
  
  %JAVA_HOME%\bin\java %ANT_OPTS% org.apache.tools.ant.Main -Dant.home="%ANT_HOME%" 
-Djava.home="%JAVA_HOME%" %1 %2 %3 %4 %5 %6 %7 %8 %9
  
  
  rem ----- Restore Environment Variables ---------------------------------------
  
  :cleanup
  set CLASSPATH=%_CLASSPATH%
  set _CLASSPATH=
  set ANT_HOME=%_ANT_HOME%
  set _ANT_HOME=
  :finish
  
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/build.sh
  
  Index: build.sh
  ===================================================================
  #!/bin/sh
  # -----------------------------------------------------------------------------
  # build.sh - Build Script for Tester
  #
  # Environment Variable Prerequisites:
  #
  #   ANT_HOME         Must point at your Ant installation [../jakarta-ant]
  #
  #   ANT_OPTS         Command line options to the Java runtime
  #                    that executes Ant [NONE]
  #
  #   JAVA_HOME        Must point at your Java Development Kit [REQUIRED]
  #
  # $Id: build.sh,v 1.1 2000/12/18 05:06:12 craigmcc Exp $
  # -----------------------------------------------------------------------------
  
  
  # ----- Verify and Set Required Environment Variables -------------------------
  
  if [ "$JAVA_HOME" = "" ] ; then
    echo You must set JAVA_HOME to point at your Java Development Kit install
    exit 1
  fi
  
  if [ "$ANT_HOME" = "" ] ; then
    ANT_HOME=../jakarta-ant
  fi
  
  if [ "$ANT_OPTS" = "" ] ; then
    ANT_OPTS=""
  fi
  
  # ----- Set Up The Runtime Classpath ------------------------------------------
  
  CP=$ANT_HOME/lib/ant.jar:$JAVA_HOME/lib/tools.jar
  
  if [ "$CLASSPATH" != "" ] ; then
    CP=$CLASSPATH:$CP
  fi
  
  # ----- Execute The Requested Build -------------------------------------------
  
  $JAVA_HOME/bin/java $ANT_OPTS -classpath $CP org.apache.tools.ant.Main \
   -Dant.home=$ANT_HOME \
   -Djava.home=$JAVA_HOME \
   "$@"
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="Tester" default="build-main" basedir=".">
  
  
    <!-- ===================== Initialize Property Values =================== -->
    <property name="build.compiler"  value="classic"/>
    <property name="servletapi.home" value="../../jakarta-servletapi"/>
    <property name="tester.build"    value="../../build/tester"/>
    <property name="tester.deploy"   value="../../build/tomcat-4.0"/>
    <property name="tester.dist"     value="../../dist/tester"/>
  
    <!-- ================== Derived Property Values ========================= -->
    <property name="ant.jar"         value="${ant.home}/lib/ant.jar"/>
    <property name="servlet.jar"     value="${servletapi.home}/lib/servlet.jar"/>
  
    <!-- =================== BUILD: Create Directories ====================== -->
    <target name="build-prepare">
      <mkdir dir="${tester.build}"/>
      <mkdir dir="${tester.build}/bin"/>
      <mkdir dir="${tester.build}/classes"/>
      <mkdir dir="${tester.build}/lib"/>
    </target>
  
  
    <!-- =================== BUILD: Copy Static Files ======================= -->
    <target name="build-static" depends="build-prepare">
  
      <!-- Executable Commands -->
      <mkdir  dir="${tester.build}/bin"/>
      <copy todir="${tester.build}/bin">
        <fileset dir="src/bin" />
      </copy>
      <fixcrlf srcdir="${tester.build}/bin" includes="*.sh" cr="remove"/>
      <fixcrlf srcdir="${tester.build}/bin" includes="*.bat" cr="add"/>
      <chmod perm="+x" file="${tester.build}/bin/tester.sh"/>
  
      <!-- Compiled Classes -->
      <mkdir  dir="${tester.build}/classes"/>
  
      <!-- Web Application -->
      <mkdir  dir="${tester.build}/web"/>
      <copy todir="${tester.build}/web">
        <fileset dir="web"/>
      </copy>
  
    </target>
  
  
    <!-- ================= BUILD: Compile Server Components ================= -->
    <target name="build-main" depends="build-static">
  
      <!-- Compile tester components and tools -->
      <javac srcdir="src/tester" destdir="${tester.build}/classes"
       classpath="${ant.jar}:${servlet.jar}"
       deprecation="off" debug="on" optimize="off"
       excludes="**/CVS/**"/>
  
      <!-- Copy static resource files -->
      <copy todir="${tester.build}/classes">
        <fileset dir="src/tester">
          <include name="**/*.properties"/>
        </fileset>
      </copy>
  
      <!-- Create and install tester library -->
      <mkdir   dir="${tester.build}/web/WEB-INF/lib"/>
      <jar jarfile="${tester.build}/web/WEB-INF/lib/tester.jar"
           basedir="${tester.build}/classes"/>
  
    </target>
  
  
    <!-- ================ BUILD: Create Tester Javadocs ===================== -->
    <target name="javadoc" depends="build-main">
      <delete dir="${tester.build}/javadoc"/>
      <mkdir dir="${tester.build}/javadoc"/>
      <javadoc packagenames="org.apache.tester.*"
       classpath="${ant.jar}:${tester.build}/classes"
       sourcepath="src/tester"
       destdir="${tester.build}/javadoc"
       author="true"
       version="true"
       windowtitle="Tester Internal API Documentation"
       doctitle="Tester Tools and Tests API"
       bottom="Copyright &#169; 2000 Apache Software Foundation.  All Rights Reserved."
      />
    </target>
  
  
    <!-- ======================= BUILD: Clean Directory ===================== -->
    <target name="build-clean">
      <delete dir="${tester.build}"/>
    </target>
  
  
    <!-- ==================== BUILD: Rebuild Everything ===================== -->
    <target name="all" depends="build-clean,build-main"/>
  
  
    <!-- ====================== DEPLOY: Create Directories ================== -->
    <target name="deploy-prepare">
      <mkdir dir="${tester.deploy}"/>
      <mkdir dir="${tester.deploy}/bin"/>
    </target>
  
  
    <!-- ====================== DEPLOY: Copy Static Files =================== -->
    <target name="deploy-static" depends="build-main,deploy-prepare">
  
      <!-- Executable Commands -->
      <copy todir="${tester.deploy}/bin">
        <fileset dir="${tester.build}/bin" />
      </copy>
      <fixcrlf srcdir="${tester.deploy}/bin" includes="*.sh" cr="remove"/>
      <fixcrlf srcdir="${tester.deploy}/bin" includes="*.bat" cr="add"/>
      <chmod perm="+x" file="${tester.deploy}/bin/tester.sh"/>
  
      <!-- Web Application -->
      <mkdir  dir="${tester.deploy}/webapps/tester"/>
      <copy todir="${tester.deploy}/webapps/tester">
        <fileset dir="${tester.build}/web"/>
      </copy>
  
    </target>
  
  
    <!-- ====================== DEPLOY: Create Tester JAR =================== -->
    <target name="deploy-main" depends="deploy-static"/>
  
  
    <!-- ====================== DEPLOY: Deploy Tester Build ================= -->
    <target name="deploy" depends="deploy-main"/>
  
  
    <!-- ====================== DEPLOY: Clean Directories =================== -->
    <target name="deploy-clean">
      <delete dir="${tester.deploy}/webapps/tester"/>
    </target>
  
  
    <!-- ================ DIST: Create Distribution ========================= -->
    <target name="dist" depends="build-main">
  
      <mkdir dir="${tester.dist}/bin"/>
      <copy dest="${tester.dist}/bin">
        <fileset dir="${tester.build}/bin" />
      </copy>
      <fixcrlf srcdir="${tester.dist}/bin" includes="*.sh" cr="remove"/>
      <fixcrlf srcdir="${tester.dist}/bin" includes="*.bat" cr="add"/>
      <chmod perm="+x" file="${tester.dist}/bin/tester.sh"/>
  
      <mkdir   dir="${tester.dist}/webapps"/>
      <jar jarfile="${tester.dist}/webapps/tester.war"
           basedir="${tester.build}/web"/>
  
    </target>
  
  
    <!-- ======================== DIST: Clean Directory ===================== -->
    <target name="dist-clean">
      <delete dir="${tester.dist}"/>
    </target>
  
  
    <!-- ====================== Convenient Synonyms ========================= -->
    <target name="clean" depends="build-clean, dist-clean"/>
  
  
  </project>
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/bin/tester.bat
  
  Index: tester.bat
  ===================================================================
  @echo off
  rem ---------------------------------------------------------------------------
  rem tester.bat - Execute Test Application Client
  rem
  rem Environment Variable Prequisites:
  rem
  rem   CATALINA_HOME (Optional) May point at your Catalina "build" directory.
  rem                 If not present, the current working directory is assumed.
  rem
  rem   CATALINA_OPTS (Optional) Java runtime options used when the "start",
  rem                 "stop", or "run" command is executed.
  rem
  rem   JAVA_HOME     Must point at your Java Development Kit installation.
  rem
  rem $Id: tester.bat,v 1.1 2000/12/18 05:06:12 craigmcc Exp $
  rem ---------------------------------------------------------------------------
  
  
  rem ----- Save Environment Variables That May Change --------------------------
  
  set _CATALINA_HOME=%CATALINA_HOME%
  set _CLASSPATH=%CLASSPATH%
  set _CP=%CP%
  
  
  rem ----- Verify and Set Required Environment Variables -----------------------
  
  if not "%JAVA_HOME%" == "" goto gotJavaHome
  echo You must set JAVA_HOME to point at your Java Development Kit installation
  goto cleanup
  :gotJavaHome
  
  if not "%CATALINA_HOME%" == "" goto gotCatalinaHome
  set CATALINA_HOME=.
  if exist "%CATALINA_HOME%\bin\catalina.bat" goto okCatalinaHome
  set CATALINA_HOME=..
  :gotCatalinaHome
  if exist "%CATALINA_HOME%\bin\catalina.bat" goto okCatalinaHome
  echo Unable to determine the value of CATALINA_HOME
  goto cleanup
  :okCatalinaHome
  
  
  rem ----- Prepare Appropriate Java Execution Commands -------------------------
  
  if not "%OS%" == "Windows_NT" goto noTitle
  set _RUNJAVA="%JAVA_HOME%\bin\java"
  goto gotTitle
  :noTitle
  set _RUNJAVA="%JAVA_HOME%\bin\java"
  :gotTitle
  
  rem ----- Set Up The Runtime Classpath ----------------------------------------
  
  set 
CP=%CATALINA_HOME%\webapps\tester\WEB-INF\lib\tester.jar;%CATALINA_HOME%\lib\jaxp.jar;%CATALINA_HOME%\lib\crimson.jar;%ANT_HOME%\lib\ant.jar
  set CLASSPATH=%CP%
  echo Using CLASSPATH: %CLASSPATH%
  
  
  rem ----- Execute The Requested Command ---------------------------------------
  
  %_RUNJAVA% %CATALINA_OPTS% org.apache.tools.ant.Main -Dant.home="%ANT_HOME%" 
-Dcatalina.home="%CATALINA_HOME%" -buildfile "%CATALINA_HOME%\bin\tester.xml" %1 %2 %3 
%4 %5 %6 %7 %8 %9
  
  :cleanup
  set CATALINA_HOME=%_CATALINA_HOME%
  set _CATALINA_HOME=
  set CLASSPATH=%_CLASSPATH%
  set _CLASSPATH=
  set CP=%_CP%
  set _RUNJAVA=
  :finish
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/bin/tester.sh
  
  Index: tester.sh
  ===================================================================
  #!/bin/sh
  # -----------------------------------------------------------------------------
  # tester.sh - Execute Test Application Client
  #
  # Environment Variable Prequisites
  #
  #   CATALINA_HOME (Optional) May point at your Catalina "build" directory.
  #                 If not present, the current working directory is assumed.
  #
  #   CATALINA_OPTS (Optional) Java runtime options used when the "start",
  #                 "stop", or "run" command is executed.
  #
  #   JAVA_HOME     Must point at your Java Development Kit installation.
  #
  # $Id: tester.sh,v 1.1 2000/12/18 05:06:12 craigmcc Exp $
  # -----------------------------------------------------------------------------
  
  
  # ----- Verify and Set Required Environment Variables -------------------------
  
  if [ "$CATALINA_HOME" = "" ] ; then
    CATALINA_HOME=`pwd`
  fi
  
  if [ "$CATALINA_OPTS" = "" ] ; then
    CATALINA_OPTS=""
  fi
  
  if [ "$ANT_HOME" = "" ] ; then
    ANT_HOME=../jakarta-ant
  fi
  
  if [ "$JAVA_HOME" = "" ] ; then
    echo You must set JAVA_HOME to point at your Java Development Kit installation
    exit 1
  fi
  
  # ----- Set Up The System Classpath -------------------------------------------
  
  
CP=$CATALINA_HOME/webapps/tester/WEB-INF/lib/tester.jar:$CATALINA_HOME/lib/jaxp.jar:$CATALINA_HOME/lib/crimson.jar:$ANT_HOME/lib/ant.jar
  
  echo Using CLASSPATH: $CP
  
  
  # ----- Execute The Requested Command -----------------------------------------
  
  $JAVA_HOME/bin/java $CATALINA_OPTS -classpath $CP org.apache.tools.ant.Main \
   -Dant.home=$ANT_HOME \
   -Dcatalina.home=$CATALINA_HOME \
   -buildfile $CATALINA_HOME/bin/tester.xml \
   "$@"
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/bin/tester.xml
  
  Index: tester.xml
  ===================================================================
  <project name="Tester" default="all">
  
    <!-- ========== Global Properties ======================================= -->
    <property name="catalina.home"  value="../../build/tomcat-4.0"/>
    <property name="host"           value="localhost"/>
    <property name="port"           value="8080"/>
    <property name="context.path"   value="/tester"/>
    <taskdef  name="tester"     classname="org.apache.tester.TestClient"/>
  
  
    <target name="all" depends="ROOT,CaseSensitive,ServletRequest"/>
  
  
    <target name="ROOT">
  
      <!-- ========== Basic Run State ======================================= -->
  
      <!-- Should be able to see the home page -->
      <tester host="${host}" port="${port}"
           request="/index.html"
            status="200"/>
  
    </target>
  
  
    <target name="CaseSensitive">
  
      <!-- ========== Case Sensitive Request URI Matching =================== -->
  
      <!-- Make sure that static resources are matched case sensitively -->
      <tester host="${host}" port="${port}"
           request="/index.HTML"
            status="404"/>
  
      <!-- Should be able to execute the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/examples/jsp/dates/date.jsp"
            status="200"/>
  
      <!-- Should not be able to view the source of the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/examples/jsp/dates/date.Jsp"
            status="404"/>
  
      <!-- Should not be able to view the source of the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/examples/jsp/dates/Date.jsp"
            status="404"/>
  
      <!-- Should not be able to view the source of the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/examples/jsp/Dates/date.jsp"
            status="404"/>
  
      <!-- Should not be able to view the source of the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/examples/Jsp/dates/date.jsp"
            status="404"/>
  
      <!-- Should not be able to view the source of the Date example -->
      <touch  file="${catalina.home}/webapps/examples/jsp/dates/date.jsp"/>
      <tester host="${host}" port="${port}"
           request="/Examples/jsp/dates/date.jsp"
            status="404"/>
  
      <!-- Should be able to execute the HelloWorld servlet example -->
      <tester host="${host}" port="${port}"
           request="/examples/servlet/HelloWorldExample"
            status="200"/>
  
      <!-- Should not be able to execute HelloWorld with different cases -->
      <tester host="${host}" port="${port}"
           request="/examples/servlet/helloWorldExample"
            status="404"/>
  
      <!-- Should not be able to execute HelloWorld with different cases -->
      <tester host="${host}" port="${port}"
           request="/examples/Servlet/HelloWorldExample"
            status="404"/>
  
      <!-- Should not be able to execute HelloWorld with different cases -->
      <tester host="${host}" port="${port}"
           request="/Examples/servlet/HelloWorldExample"
            status="404"/>
  
    </target>
  
  
    <target name="ServletRequest">
  
      <!-- ========== Parameters and Query Strings ========================== -->
  
      <tester host="${host}" port="${port}"
           request="${context.path}/GetParameter01?foo=1"
        outContent="GetParameter01 PASSED"/>
  
      <tester host="${host}" port="${port}"
           request="${context.path}/GetQueryString01?foo=1"
        outContent="GetQueryString01 PASSED"/>
  
  
      <!-- ========== Other ServletRequest Tests ============================ -->
  
      <!-- Servlet compliance tests, until equivalent tests are included
           in jakarta-watchdog-4.0.  -->
  
      <tester host="${host}" port="${port}"
           request="${context.path}/GetInputStream01"
        outContent="GetInputStream01 PASSED"/>
  
      <tester host="${host}" port="${port}"
           
request="${context.path}/GetParameterMap00?BestLanguage=Java&amp;BestJSP=Java2"
        outContent="GetParameterMap00 PASSED"/>
  
  
      <!-- ========== Authentication ======================================== -->
  
      <!-- Once a user has been authenticated, the corresponding user identity
           should be visible to all other requests in this web application, even
           for URIs that are not protected by security constraints.  This is
           tested by invoking a protected URI followed by a non-protected URI
      -->
  
      <tester host="${host}" port="${port}"
           request="${context.path}/protected/Authentication01"
         inHeaders="Authorization:Basic dG9tY2F0OnRvbWNhdA=="
        outContent="Authentication01 PASSED"/>
  
      <tester host="${host}" port="${port}"
           request="${context.path}/protected/Authentication02"
         inHeaders="Authorization:Basic dG9tY2F0OnRvbWNhdA=="
        outContent="Authentication02 PASSED"/>
  
  
    </target>
  
  
  </project>
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Authentication01.java
  
  Index: Authentication01.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import java.security.Principal;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Ensure that the "tomcat" user has been successfully authenticated.  This
   * should be guaranteed by the fact that this URI is protected by a security
   * constraint in the deployment descriptor.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class Authentication01 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          String remoteUser = request.getRemoteUser();
          Principal userPrincipal = request.getUserPrincipal();
          String errors = "";
          if (remoteUser == null)
              errors += "  getRemoteUser() returned NULL.";
          else if (!remoteUser.equals("tomcat"))
              errors += "  remoteUser=" + remoteUser + ".";
          if (userPrincipal == null)
              errors += "  getUserPrincpal() returned NULL.";
          else if (!userPrincipal.getName().equals("tomcat"))
              errors += "  userPrincipal=" + userPrincipal.getName() + ".";
          if ((remoteUser != null) &&
              (userPrincipal != null) &&
              !remoteUser.equals(userPrincipal.getName()))
              errors += "  remoteUser=" + remoteUser + " userPrincipal=" +
                  userPrincipal.getName();
          if (errors.length() > 0)
              writer.println("Authentication01 FAILED:" + errors);
          else
              writer.println("Authentication01 PASSED");
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Authentication02.java
  
  Index: Authentication02.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import java.security.Principal;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Ensure that the "tomcat" user has been successfully authenticated.  Although
   * this URI is not protected by a security constraint, the test client will
   * have authenticated a user previously by calling "/Authentication01".
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class Authentication02 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          String remoteUser = request.getRemoteUser();
          Principal userPrincipal = request.getUserPrincipal();
          String errors = "";
          if (remoteUser == null)
              errors += "  getRemoteUser() returned NULL.";
          else if (!remoteUser.equals("tomcat"))
              errors += "  remoteUser=" + remoteUser + ".";
          if (userPrincipal == null)
              errors += "  getUserPrincpal() returned NULL.";
          else if (!userPrincipal.getName().equals("tomcat"))
              errors += "  userPrincipal=" + userPrincipal.getName() + ".";
          if ((remoteUser != null) &&
              (userPrincipal != null) &&
              !remoteUser.equals(userPrincipal.getName()))
              errors += "  remoteUser=" + remoteUser + " userPrincipal=" +
                  userPrincipal.getName();
          if (errors.length() > 0)
              writer.println("Authentication02 FAILED:" + errors);
          else
              writer.println("Authentication02 PASSED");
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/GetInputStream01.java
  
  Index: GetInputStream01.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test getting the servlet input stream after we have retrieved the reader.
   * This should throw an IllegalStateException.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class GetInputStream01 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          BufferedReader reader = request.getReader();
          try {
              ServletInputStream sis = request.getInputStream();
              writer.println("GetInputStream01 FAILED - Did not throw " +
                             "IllegalStateException");
          } catch (IllegalStateException e) {
              writer.println("GetInputStream01 PASSED");
          }
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/GetParameter01.java
  
  Index: GetParameter01.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test retrieval of parameters.  The client is expected to send a request
   * URI like "/tester/GetParameter01?foo=1".
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class GetParameter01 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          String expected = "1";
          String result = request.getParameter("foo");
          if (expected.equals(result)) {
              writer.println("GetParameter01 PASSED");
          } else {
              writer.println("GetParameter01 FAILED - Received '" + result +
                             "' instead of '" + expected + "'");
          }
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/GetParameterMap00.java
  
  Index: GetParameterMap00.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import java.util.Map;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test getting the servlet input stream after we have retrieved the reader.
   * This should throw an IllegalStateException.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class GetParameterMap00 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          String errors = "";
          Map map = request.getParameterMap();
          if (map == null)
              errors += "  getParameterMap() returned null.";
          else {
              if (map.size() != 2)
                  errors += "  map size is " + map.size() + ".";
              String value1[] = (String[]) map.get("BestLanguage");
              if (value1 == null)
                  errors += "  BestLanguage is NULL.";
              else if (value1.length != 1)
                  errors += "  BestLanguage has " + value1.length + " values.";
              else if (!value1[0].equals("Java"))
                  errors += "  BestLanguage is " + value1 + ".";
              String value2[] = (String[]) map.get("BestJSP");
              if (value2 == null)
                  errors += "  BestJSP is NULL.";
              else if (value2.length != 1)
                  errors += "  BestJSP has " + value2.length + " values.";
              else if (!value2[0].equals("Java2"))
                  errors += "  BestJSP is " + value2 + ".";
              try {
                  map.put("ABC", "XYZ");
                  errors += "   map.put() was allowed.";
                  if (map.get("ABC") != null)
                      errors += "  map is not immutable.";
              } catch (Throwable t) {
                  ;
              }
          }
  
          if (errors.equals(""))
              writer.println("GetParameterMap00 PASSED");
          else {
              writer.println("GetParameterMap00 FAILED:" + errors);
          }
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/GetQueryString01.java
  
  Index: GetQueryString01.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Test retrieval of query string.  The client is expected to send a request
   * URI like "/tester/GetQueryString01?foo=1".
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class GetQueryString01 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          PrintWriter writer = response.getWriter();
          String expected = "foo=1";
          String result = request.getQueryString();
          if (expected.equals(result)) {
              writer.println("GetQueryString01 PASSED");
          } else {
              writer.println("GetQueryString01 FAILED - Received '" + result +
                             "' instead of '" + expected + "'");
          }
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/TestClient.java
  
  Index: TestClient.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  The Apache Software Foundation.         *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    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",  "Tomcat",  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 Software Foundation.                                            *
   *                                                                           *
   * 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 indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  package org.apache.tester;
  
  
  import java.io.FileNotFoundException;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.net.ConnectException;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Task;
  
  
  /**
   * <p>This class contains a <strong>Task</strong> for Ant that is used to
   * send HTTP requests to a servlet container, and examine the responses.
   * It is similar in purpose to the <code>GTest</code> task in Watchdog,
   * but uses the JDK's HttpURLConnection for underlying connectivity.</p>
   *
   * <p>The task is registered with Ant using a <code>taskdef</code> directive:
   * <pre>
   *   &lt;taskdef name="tester" classname="org.apache.tester.TestClient"&gt;
   * </pre>
   * and accepts the following configuration properties:</p>
   * <ul>
   * <li><strong>host</strong> - The server name to which this request will be
   *     sent.  Defaults to <code>localhost</code> if not specified.</li>
   * <li><strong>inContent</strong> - The data content that will be submitted
   *     with this request.  The test client will transparently add a carriage
   *     return and line feed, and set the content length header, if this is
   *     specified.  Otherwise, no content will be included in the request.</li>
   * <li><strong>inHeaders</strong> - The set of one or more HTTP headers that
   *     will be included on the request.</li>
   * <li><strong>message</strong> - The HTTP response message that is expected
   *     in the response from the server.  No check is made if no message
   *     is specified.</li>
   * <li><strong>method</strong> - The HTTP request method to be used on this
   *     request.  Defaults to <ocde>GET</code> if not specified.</li>
   * <li><strong>outContent</strong> - The first line of the response data
   *     content that we expect to receive.  No check is made if no content is
   *     specified.</li>
   * <li><strong>outHeaders</strong> - The set of one or more HTTP headers that
   *     are expected in the response (order independent).</li>
   * <li><strong>port</strong> - The port number to which this request will be
   *     sent.  Defaults to <code>8080</code> if not specified.</li>
   * <li><strong>request</strong> - The request URI to be transmitted for this
   *     request.  This value should start with a slash character ("/"), and
   *     be the server-relative URI of the requested resource.</li>
   * <li><strong>status</strong> - The HTTP status code that is expected in the
   *     response from the server.  Defaults to <code>200</code> if not
   *     specified.</li>
   * </ul>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/12/18 05:06:13 $
   */
  
  public class TestClient extends Task {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The debugging detail level for this execution.
       */
      protected int debug = 0;
  
      public int getDebug() {
          return (this.debug);
      }
  
      public void setDebug(int debug) {
          this.debug = debug;
      }
  
  
      /**
       * The host name to which we will connect.
       */
      protected String host = "localhost";
  
      public String getHost() {
          return (this.host);
      }
  
      public void setHost(String host) {
          this.host = host;
      }
  
  
      /**
       * The first line of the request data that will be included on this
       * request.
       */
      protected String inContent = null;
  
      public String getInContent() {
          return (this.inContent);
      }
  
      public void setInContent(String inContent) {
          this.inContent = inContent;
      }
  
  
      /**
       * The HTTP headers to be included on the request.  Syntax is
       * <code>{name}:{value}[##{name}:{value}] ...</code>.
       */
      protected String inHeaders = null;
  
      public String getInHeaders() {
          return (this.inHeaders);
      }
  
      public void setInHeaders(String inHeaders) {
          this.inHeaders = inHeaders;
      }
  
  
      /**
       * The HTTP response message to be expected in the response.
       */
      protected String message = null;
  
      public String getMessage() {
          return (this.message);
      }
  
      public void setMessage(String message) {
          this.message = message;
      }
  
  
      /**
       * The HTTP request method that will be used.
       */
      protected String method = "GET";
  
      public String getMethod() {
          return (this.method);
      }
  
      public void setMethod(String method) {
          this.method = method;
      }
  
  
      /**
       * The first line of the response data content that we expect to receive.
       */
      protected String outContent = null;
  
      public String getOutContent() {
          return (this.outContent);
      }
  
      public void setOutContent(String outContent) {
          this.outContent = outContent;
      }
  
  
      /**
       * The HTTP headers to be checked on the response.  Syntax is
       * <code>{name}:{value}[##{name}:{value}] ...</code>.
       */
      protected String outHeaders = null;
  
      public String getOutHeaders() {
          return (this.outHeaders);
      }
  
      public void setOutHeaders(String outHeaders) {
          this.outHeaders = outHeaders;
      }
  
  
      /**
       * The port number to which we will connect.
       */
      protected int port = 8080;
  
      public int getPort() {
          return (this.port);
      }
  
      public void setPort(int port) {
          this.port = port;
      }
  
  
      /**
       * The request URI to be sent to the server.  This value is required.
       */
      protected String request = null;
  
      public String getRequest() {
          return (this.request);
      }
  
      public void setRequest(String request) {
          this.request = request;
      }
  
  
      /**
       * The HTTP status code expected on the response.
       */
      protected int status = 200;
  
      public int getStatus() {
          return (this.status);
      }
  
      public void setStatus(int status) {
          this.status = status;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Execute the test that has been configured by our property settings.
       */
      public void execute() throws BuildException {
  
          // Construct a summary of the request we will be sending
          String summary = "[" + method + " " + request + "]";
          if (debug >= 1)
              System.out.println("RQST: " + summary);
          boolean success = true;
          String result = null;
          Throwable throwable = null;
          HttpURLConnection conn = null;
  
          try {
  
              // Configure an HttpURLConnection for this request
              URL url = new URL("http", host, port, request);
              conn = (HttpURLConnection) url.openConnection();
              conn.setAllowUserInteraction(false);
              conn.setDoInput(true);
              if (inContent != null) {
                  conn.setDoOutput(true);
                  inContent += "\r\n";
                  conn.setRequestProperty("Content-Length",
                                          "" + inContent.length());
              } else {
                  conn.setDoOutput(false);
              }
              conn.setFollowRedirects(false);
              conn.setRequestMethod(method);
              if (inHeaders != null) {
                  String headers = inHeaders;
                  while (headers.length() > 0) {
                      int delimiter = headers.indexOf("##");
                      String header = null;
                      if (delimiter < 0) {
                          header = headers;
                          headers = "";
                      } else {
                          header = headers.substring(0, delimiter);
                          headers = headers.substring(delimiter + 2);
                      }
                      int colon = header.indexOf(":");
                      if (colon < 0)
                          break;
                      String name = header.substring(0, colon).trim();
                      String value = header.substring(colon + 1).trim();
                      conn.setRequestProperty(name, value);
                  }
              }
  
              // Connect to the server and send our output if necessary
              conn.connect();
              if (inContent != null) {
                  OutputStream os = conn.getOutputStream();
                  for (int i = 0; i < inContent.length(); i++)
                      os.write(inContent.charAt(i));
                  os.close();
              }
  
              // Acquire the response data, if there is any
              String outData = "";
              boolean eol = false;
              InputStream is = conn.getInputStream();
              if (is != null) {
                  while (true) {
                      int b = is.read();
                      if (b < 0)
                          break;
                      char ch = (char) b;
                      if ((ch == '\r') || (ch == '\n'))
                          eol = true;
                      if (!eol)
                          outData += ch;
                  }
                  is.close();
              }
  
              // Dump out the response stuff
              if (debug >= 1) {
                  System.out.println("RESP: " + conn.getResponseCode() + " " +
                                     conn.getResponseMessage());
                  for (int i = 0; i < 1000; i++) {
                      String name = conn.getHeaderFieldKey(i);
                      String value = conn.getHeaderField(i);
                      if ((name == null) || (value == null))
                          break;
                      System.out.println("HEAD: " + name + ": " + value);
                  }
                  System.out.println("DATA: " + outData);
              }
  
              // Validate the response against our criteria
              if (status != conn.getResponseCode()) {
                  success = false;
                  result = "Expected status=" + status + ", got status=" +
                      conn.getResponseCode();
              } else if ((message != null) &&
                         !message.equals(conn.getResponseMessage())) {
                  success = false;
                  result = "Expected message='" + message + "', got message='" +
                      conn.getResponseMessage() + "'";
              } else if ((outContent != null) &&
                         !outData.startsWith(outContent)) {
                  success = false;
                  result = outData;
              }
  
          } catch (Throwable t) {
              if (t instanceof FileNotFoundException) {
                  if (status == 404) {
                      success = true;
                      result = "Not Found";
                      throwable = null;
                  } else {
                      success = false;
                      try {
                          result = "Status=" + conn.getResponseCode() +
                              ", Message=" + conn.getResponseMessage();
                      } catch (IOException e) {
                          result = e.toString();
                      }
                      throwable = null;
                  }
              } else if (t instanceof ConnectException) {
                  success = false;
                  result = t.getMessage();
                  throwable = null;
              } else {
                  success = false;
                  result = t.getMessage();
                  throwable = t;
              }
          }
  
          // Log the results of executing this request
          if (success)
              System.out.println("OK " + summary);
          else {
              System.out.println("FAIL " + summary + " " + result);
              if (throwable != null)
                  throwable.printStackTrace(System.out);
          }
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
  
  <!-- Deployment Descriptor for the Tester Web Application -->
  
  <web-app>
  
      <!-- ========== Servlet Definitions =================================== -->
  
      <servlet>
          <servlet-name>Authentication01</servlet-name>
          <servlet-class>org.apache.tester.Authentication01</servlet-class>
      </servlet>
  
      <servlet>
          <servlet-name>Authentication02</servlet-name>
          <servlet-class>org.apache.tester.Authentication02</servlet-class>
      </servlet>
  
      <servlet>
          <servlet-name>GetInputStream01</servlet-name>
          <servlet-class>org.apache.tester.GetInputStream01</servlet-class>
      </servlet>
  
      <servlet>
          <servlet-name>GetParameter01</servlet-name>
          <servlet-class>org.apache.tester.GetParameter01</servlet-class>
      </servlet>
  
      <servlet>
          <servlet-name>GetParameterMap00</servlet-name>
          <servlet-class>org.apache.tester.GetParameterMap00</servlet-class>
      </servlet>
  
      <servlet>
          <servlet-name>GetQueryString01</servlet-name>
          <servlet-class>org.apache.tester.GetQueryString01</servlet-class>
      </servlet>
  
  
      <!-- ========== Servlet Mappings ====================================== -->
  
      <servlet-mapping>
          <servlet-name>Authentication01</servlet-name>
          <url-pattern>/protected/Authentication01</url-pattern>
      </servlet-mapping>
  
      <servlet-mapping>
          <servlet-name>Authentication02</servlet-name>
          <url-pattern>/protected/Authentication02</url-pattern>
      </servlet-mapping>
  
      <servlet-mapping>
          <servlet-name>GetInputStream01</servlet-name>
          <url-pattern>/GetInputStream01</url-pattern>
      </servlet-mapping>
  
      <servlet-mapping>
          <servlet-name>GetParameter01</servlet-name>
          <url-pattern>/GetParameter01</url-pattern>
      </servlet-mapping>
  
      <servlet-mapping>
          <servlet-name>GetParameterMap00</servlet-name>
          <url-pattern>/GetParameterMap00</url-pattern>
      </servlet-mapping>
  
      <servlet-mapping>
          <servlet-name>GetQueryString01</servlet-name>
          <url-pattern>/GetQueryString01</url-pattern>
      </servlet-mapping>
  
  
      <!-- ========== Security Constraints ================================== -->
  
      <security-constraint>
          <web-resource-collection>
              <web-resource-name>Authentication Servlet</web-resource-name>
              <url-pattern>/protected/*</url-pattern>
          </web-resource-collection>
          <auth-constraint>
              <role-name>tomcat</role-name>
          </auth-constraint>
      </security-constraint>
  
      <login-config>
          <auth-method>BASIC</auth-method>
          <realm-name>Authentication Servlet</realm-name>
      </login-config>
  
  
  </web-app>
  
  
  

Reply via email to