tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml
Date Sun, 24 Jun 2001 00:00:07 GMT
craigmcc    01/06/23 17:00:07

  Modified:    tester/src/tester/org/apache/tester Context01.java
                        ContextBean.java
               tester/web/WEB-INF web.xml
  Added:       tester/src/tester/org/apache/tester ContextListener01.java
  Log:
  Extend the new context tests so that they check for correct calls to the
  appropriate context event listeners as well.
  
  Revision  Changes    Path
  1.2       +50 -9     jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Context01.java
  
  Index: Context01.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Context01.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Context01.java	2001/06/23 19:27:24	1.1
  +++ Context01.java	2001/06/24 00:00:05	1.2
  @@ -71,7 +71,7 @@
    * present, which should be erased after a web application restart.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/06/23 19:27:24 $
  + * @version $Revision: 1.2 $ $Date: 2001/06/24 00:00:05 $
    */
   
   public class Context01 extends HttpServlet {
  @@ -94,7 +94,9 @@
   
           // Create and stash a context attribute
           if (ok) {
  -            context.setAttribute("context01", "This is Context01");
  +            ContextBean bean = new ContextBean();
  +            bean.setStringProperty("Context01");
  +            context.setAttribute("context01", bean);
           }
   
           // Ensure that we can retrieve the attribute successfully
  @@ -103,18 +105,57 @@
               if (bean == null) {
                   writer.println("Context01 FAILED - Cannot retrieve attribute");
                   ok = false;
  -            } else if (!(bean instanceof String)) {
  -                writer.println("Context01 FAILED - Attribute instance of " +
  -                               bean.getClass().getName());
  -                ok = false;
  -            } else {
  -                String value = (String) bean;
  -                if (!"This is Context01".equals(value)) {
  +            }
  +            if (ok) {
  +                if (!(bean instanceof ContextBean)) {
  +                    writer.println("Context01 FAILED - Bean instance of " +
  +                                   bean.getClass().getName());
  +                    ok = false;
  +                }
  +            }
  +            if (ok) {
  +                String value = ((ContextBean) bean).getStringProperty();
  +                if (!"Context01".equals(value)) {
                       writer.println("Context01 FAILED - Value = " + value);
                       ok = false;
                   }
               }
  +            if (ok) {
  +                String lifecycle = ((ContextBean) bean).getLifecycle();
  +                if (!"/add".equals(lifecycle)) {
  +                    writer.println("Context01 FAILED - Bean lifecycle is " +
  +                                   lifecycle);
  +                    ok = false;
  +                }
  +            }
           }
  +
  +        // Ensure that we can update this attribute and check its lifecycle
  +        if (ok) {
  +            ContextBean bean = (ContextBean) context.getAttribute("context01");
  +            context.setAttribute("context01", bean);
  +            String lifecycle = bean.getLifecycle();
  +            if (!"/add/rep".equals(lifecycle)) {
  +                writer.println("Context01 FAILED - Bean lifecycle is " +
  +                               lifecycle);
  +                ok = false;
  +            }
  +        }
  +
  +        // Ensure that we can remove this attribute and check its lifecycle
  +        if (ok) {
  +            ContextBean bean = (ContextBean) context.getAttribute("context01");
  +            context.removeAttribute("context01");
  +            String lifecycle = bean.getLifecycle();
  +            if (!"/add/rep/rem".equals(lifecycle)) {
  +                writer.println("Context01 FAILED - Bean lifecycle is " +
  +                               lifecycle);
  +                ok = false;
  +            }
  +        }
  +
  +        // Add a bean back for the restart application test
  +        context.setAttribute("context01", new ContextBean());
   
           // Ensure that setAttribute("name", null) works correctly
           if (ok) {
  
  
  
  1.2       +18 -2     jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ContextBean.java
  
  Index: ContextBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ContextBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContextBean.java	2001/06/23 19:27:24	1.1
  +++ ContextBean.java	2001/06/24 00:00:05	1.2
  @@ -65,7 +65,7 @@
    * Simple JavaBean to use for context attribute tests.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/06/23 19:27:24 $
  + * @version $Revision: 1.2 $ $Date: 2001/06/24 00:00:05 $
    */
   
   public class ContextBean implements Serializable {
  @@ -75,6 +75,20 @@
   
   
       /**
  +     * The lifecycle events that have happened on this bean instance.
  +     */
  +    protected String lifecycle = "";
  +
  +    public String getLifecycle() {
  +        return (this.lifecycle);
  +    }
  +
  +    public void setLifecycle(String lifecycle) {
  +        this.lifecycle = lifecycle;
  +    }
  +
  +
  +    /**
        * A string property.
        */
       protected String stringProperty = "Default String Property Value";
  @@ -96,7 +110,9 @@
        */
       public String toString() {
   
  -        StringBuffer sb = new StringBuffer("ContextBean[stringProperty=");
  +        StringBuffer sb = new StringBuffer("ContextBean[lifecycle=");
  +        sb.append(lifecycle);
  +        sb.append(", stringProperty=");
           sb.append(this.stringProperty);
           sb.append("]");
           return (sb.toString());
  
  
  
  1.1                  jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/ContextListener01.java
  
  Index: ContextListener01.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 <apache@apache.org>.                        *
   *                                                                           *
   * 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 context events.  All events that occur
   * are logged appropriately to the static logger..
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/06/24 00:00:05 $
   */
  
  public class ContextListener01
      implements ServletContextAttributeListener, ServletContextListener {
  
  
      public void attributeAdded(ServletContextAttributeEvent event) {
          StaticLogger.write("ContextListener01: attributeAdded(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("ContextListener01: attributeAdded(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/add");
          }
      }
  
      public void attributeRemoved(ServletContextAttributeEvent event) {
          StaticLogger.write("ContextListener01: attributeRemoved(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("ContextListener01: attributeRemoved(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/rem");
          }
      }
  
      public void attributeReplaced(ServletContextAttributeEvent event) {
          StaticLogger.write("ContextListener01: attributeReplaced(" +
                             event.getName() + "," + event.getValue() + ")");
          ServletContext context = (ServletContext) event.getSource();
          context.log("ContextListener01: attributeReplaced(" +
                      event.getName() + "," + event.getValue() + ")");
          if (event.getValue() instanceof ContextBean) {
              ContextBean bean = (ContextBean) event.getValue();
              bean.setLifecycle(bean.getLifecycle() + "/rep");
          }
      }
  
      public void contextDestroyed(ServletContextEvent event) {
          StaticLogger.write("ContextListener01: contextDestroyed()");
          ServletContext context = (ServletContext) event.getSource();
          context.log("ContextListener01: contextDestroyed()");
          context.removeAttribute("contextListener01");
      }
  
      public void contextInitialized(ServletContextEvent event) {
          StaticLogger.write("ContextListener01: contextInitialized()");
          ServletContext context = (ServletContext) event.getSource();
          context.log("ContextListener01: contextInitialized()");
          ContextBean bean = new ContextBean();
          bean.setStringProperty("ContextListener01");
          context.setAttribute("contextListener01", bean);
      }
  
  
  }
  
  
  
  1.39      +4 -0      jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- web.xml	2001/06/23 19:27:24	1.38
  +++ web.xml	2001/06/24 00:00:06	1.39
  @@ -378,6 +378,10 @@
   
   
       <listener>
  +        <listener-class>org.apache.tester.ContextListener01</listener-class>
  +    </listener>
  +
  +    <listener>
           <listener-class>org.apache.tester.SessionListener01</listener-class>
       </listener>
   
  
  
  

Mime
View raw message