horwat      2002/08/08 19:12:14

  Modified:    tester/web/WEB-INF web.xml
               tester/src/bin tester.xml
  Added:       tester/src/tester/org/apache/tester Request01.java
                        RequestListener01.java
  Log:
  Add test case for new servlet request events.
  
  Revision  Changes    Path
  1.2       +24 -0     jakarta-tomcat-catalina/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/tester/web/WEB-INF/web.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- web.xml   18 Jul 2002 16:47:25 -0000      1.1
  +++ web.xml   9 Aug 2002 02:12:13 -0000       1.2
  @@ -344,6 +344,11 @@
       </filter-mapping>
   
       <filter-mapping>
  +        <filter-name>HttpFilter</filter-name>
  +        <url-pattern>/WrappedRequest01</url-pattern>
  +    </filter-mapping>
  +
  +    <filter-mapping>
           <filter-name>GenericFilter</filter-name>
           <url-pattern>/WrappedReset01</url-pattern>
       </filter-mapping>
  @@ -449,6 +454,10 @@
   -->
   
       <listener>
  +        <listener-class>org.apache.tester.RequestListener01</listener-class>
  +    </listener>
  +
  +    <listener>
           <listener-class>org.apache.tester.SessionListener01</listener-class>
       </listener>
   
  @@ -906,6 +915,11 @@
       </servlet>
   
       <servlet>
  +        <servlet-name>Request01</servlet-name>
  +        <servlet-class>org.apache.tester.Request01</servlet-class>
  +    </servlet>
  +
  +    <servlet>
           <servlet-name>Reset01</servlet-name>
           <servlet-class>org.apache.tester.Reset01</servlet-class>
       </servlet>
  @@ -1690,6 +1704,16 @@
       <servlet-mapping>
           <servlet-name>Reflection01</servlet-name>
           <url-pattern>/WrappedReflection01</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Request01</servlet-name>
  +        <url-pattern>/Request01</url-pattern>
  +    </servlet-mapping>
  +
  +    <servlet-mapping>
  +        <servlet-name>Request01</servlet-name>
  +        <url-pattern>/WrappedRequest01</url-pattern>
       </servlet-mapping>
   
       <servlet-mapping>
  
  
  
  1.2       +10 -0     jakarta-tomcat-catalina/tester/src/bin/tester.xml
  
  Index: tester.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/tester/src/bin/tester.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tester.xml        18 Jul 2002 16:47:30 -0000      1.1
  +++ tester.xml        9 Aug 2002 02:12:13 -0000       1.2
  @@ -1504,6 +1504,16 @@
            request="${context.path}/WrappedAggregate02?a=1"
         outContent="Aggregate02 PASSED"/>
   
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +           debug="${debug}"
  +         request="${context.path}/Request01"
  +      outContent="Request01 PASSED"/>
  +
  +    <tester host="${host}" port="${port}" protocol="${protocol}"
  +           debug="${debug}"
  +         request="${context.path}/WrappedRequest01"
  +      outContent="Request01 PASSED"/>
  +
       <!-- ========== Other ServletRequest Tests ============================ -->
   
       <!-- Servlet compliance tests, until equivalent tests are included
  
  
  
  1.1                  
jakarta-tomcat-catalina/tester/src/tester/org/apache/tester/Request01.java
  
  Index: Request01.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.*;
  
  
  /**
   * Request listener test.  Exercise various methods for dealing with
   * servlet request attributes.  Leave an attribute named "request01"
   * present, which should be erased after a web application restart.
   *
   * @author Justyna Horwat
   * @version $Revision: 1.1 $ $Date: 2002/08/09 02:12:14 $
   */
  
  public class Request01 extends HttpServlet {
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
  
          response.setContentType("text/plain");
          boolean ok = true;
          PrintWriter writer = response.getWriter();
          ServletContext context = getServletContext();
  
          // Ensure that there is no existing attribute
          if (ok) {
              if (request.getAttribute("request01") != null) {
                  writer.println("Request01 FAILED - Attribute already exists");
                  ok = false;
              }
          }
  
          // Create and stash a request attribute
          if (ok) {
              ContextBean bean = new ContextBean();
              bean.setStringProperty("Request01");
              request.setAttribute("request01", bean);
          }
  
          // Ensure that we can retrieve the attribute successfully
          if (ok) {
              Object bean = request.getAttribute("request01");
              if (bean == null) {
                  writer.println("Request01 FAILED - Cannot retrieve attribute");
                  ok = false;
              }
              if (ok) {
                  if (!(bean instanceof ContextBean)) {
                      writer.println("Request01 FAILED - Bean instance of " +
                                     bean.getClass().getName());
                      ok = false;
                  }
              }
              if (ok) {
                  String value = ((ContextBean) bean).getStringProperty();
                  if (!"Request01".equals(value)) {
                      writer.println("Request01 FAILED - Value = " + value);
                      ok = false;
                  }
              }
              if (ok) {
                  String lifecycle = ((ContextBean) bean).getLifecycle();
                  if (!"/add".equals(lifecycle)) {
                      writer.println("Request01 FAILED - Bean lifecycle is " +
                                     lifecycle);
                      ok = false;
                  }
              }
          }
  
          // Ensure that we can update this attribute and check its lifecycle
          if (ok) {
              ContextBean bean = (ContextBean) request.getAttribute("request01");
              request.setAttribute("request01", bean);
              String lifecycle = bean.getLifecycle();
              if (!"/add/rep".equals(lifecycle)) {
                  writer.println("Request01 FAILED - Bean lifecycle is " +
                                 lifecycle);
                  ok = false;
              }
          }
  
          // Ensure that we can remove this attribute and check its lifecycle
          if (ok) {
              ContextBean bean = (ContextBean) request.getAttribute("request01");
              request.removeAttribute("request01");
              String lifecycle = bean.getLifecycle();
              if (!"/add/rep/rem".equals(lifecycle)) {
                  writer.println("Request01 FAILED - Bean lifecycle is " +
                                 lifecycle);
                  ok = false;
              }
          }
  
          // Add a bean back for the restart application test
          request.setAttribute("request01", new ContextBean());
  
          // Ensure that setAttribute("name", null) works correctly
          if (ok) {
              request.setAttribute("FOO", "BAR");
              request.setAttribute("FOO", null);
              if (request.getAttribute("FOO") != null) {
                  writer.println("Request01 FAILED - setAttribute(name,null)");
                  ok = false;
              }
          }
  
          // Report success if everything is still ok
          if (ok)
              writer.println("Request01 PASSED");
          while (true) {
              String message = StaticLogger.read();
              if (message == null)
                  break;
              writer.println(message);
          }
          StaticLogger.reset();
  
      }
  
  }
  
  
  
  1.1                  
jakarta-tomcat-catalina/tester/src/tester/org/apache/tester/RequestListener01.java
  
  Index: RequestListener01.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *      Copyright (c) 1999, 2000, 2001  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.*;
  
  /**
   * Application event listener for request events.  All events that occur
   * are logged appropriately to the static logger..
   *
   * @author Justyna Horwat
   * @version $Revision: 1.1 $ $Date: 2002/08/09 02:12:14 $
   */
  
  public class RequestListener01
      implements ServletRequestAttributeListener, ServletRequestListener {
  
  
      public void attributeAdded(ServletRequestAttributeEvent event) {
          StaticLogger.write("RequestListener01: attributeAdded(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("RequestListener01: attributeAdded(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/add");
          }
      }
  
      public void attributeRemoved(ServletRequestAttributeEvent event) {
          StaticLogger.write("RequestListener01: attributeRemoved(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("RequestListener01: attributeRemoved(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/rem");
          }
      }
  
      public void attributeReplaced(ServletRequestAttributeEvent event) {
          StaticLogger.write("RequestListener01: attributeReplaced(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("RequestListener01: attributeReplaced(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/rep");
          }
      }
  
      public void requestDestroyed(ServletRequestEvent event) {
          StaticLogger.write("RequestListener01: requestDestroyed() -- probably cached 
from previous request");
          ServletContext context = (ServletContext) event.getSource();
          context.log("RequestListener01: requestDestroyed()");
      }
  
      public void requestInitialized(ServletRequestEvent event) {
          StaticLogger.write("RequestListener01: requestInitialized()");
          ServletContext context = (ServletContext) event.getSource();
          context.log("RequestListener01: requestInitialized()");
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to