vmassol     01/09/07 09:05:37

  Added:       cactus/src/framework/servlet23/org/apache/commons/cactus
                        FilterTestCase.java
               cactus/src/framework/servlet23/org/apache/commons/cactus/client
                        FilterHttpClient.java
               cactus/src/framework/servlet23/org/apache/commons/cactus/server
                        FilterChainWrapper.java FilterConfigWrapper.java
                        FilterImplicitObjects.java FilterTestCaller.java
                        FilterTestController.java FilterTestRedirector.java
  Log:
  added support for Filter unit testing
  
  Revision  Changes    Path
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/FilterTestCase.java
  
  Index: FilterTestCase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus;
  
  import java.lang.reflect.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.net.*;
  
  import junit.framework.*;
  
  import org.apache.commons.cactus.client.*;
  import org.apache.commons.cactus.server.*;
  
  /**
   * Test classes that need access to valid Filter implicit objects (such as the
   * <code>FilterConfig</code> and <code>FilterChain</code> objects) must
   * subclass this class.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterTestCase.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterTestCase extends AbstractTestCase
  {
      /**
       * Valid <code>HttpServletRequest</code> object that you can access from
       * the <code>testXXX()</code>, <code>setUp</code> and
       * <code>tearDown()</code> methods. If you try to access it from either the
       * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
       * have the <code>null</code> value.
       */
      public org.apache.commons.cactus.server.HttpServletRequestWrapper request;
  
      /**
       * Valid <code>HttpServletResponse</code> object that you can access from
       * the <code>testXXX()</code>, <code>setUp</code> and
       * <code>tearDown()</code> methods. If you try to access it from either the
       * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
       * have the <code>null</code> value.
       */
      public HttpServletResponse response;
  
      /**
       * Valid <code>FilterConfig</code> object that you can access from
       * the <code>testXXX()</code>, <code>setUp</code> and
       * <code>tearDown()</code> methods. If you try to access it from either the
       * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
       * have the <code>null</code> value.
       */
      public FilterConfigWrapper config;
  
      /**
       * Valid <code>FilterChain</code> object that you can access from
       * the <code>testXXX()</code>, <code>setUp</code> and
       * <code>tearDown()</code> methods. If you try to access it from either the
       * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
       * have the <code>null</code> value.
       */
      public FilterChainWrapper filterChain;
  
      /**
       * Constructs a JUnit test case with the given name.
       *
       * @param theName the name of the test case
       */
      public FilterTestCase(String theName)
      {
          super(theName);
      }
  
      /**
       * Runs a test case. This method is overriden from the JUnit
       * <code>TestCase</code> class in order to seamlessly call the
       * Cactus redirection servlet.
       */
      protected void runTest() throws Throwable
      {
          runGenericTest(new FilterHttpClient());
      }
  }
  
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/client/FilterHttpClient.java
  
  Index: FilterHttpClient.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.client;
  
  /**
   * Manage the logic for calling the Servlet redirector for executing a test on
   * the server side.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterHttpClient.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterHttpClient extends AbstractHttpClient
  {
      /**
       * Default URL to call the <code>ServletRedirector</code> servlet.
       */
      protected final static String FILTER_REDIRECTOR_URL =
          CONFIG.getString("cactus.filterRedirectorURL");
  
      /**
       * @return the URL to call the redirector
       */
      protected String getRedirectorURL()
      {
          return FILTER_REDIRECTOR_URL;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterChainWrapper.java
  
  Index: FilterChainWrapper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import java.io.*;
  import javax.servlet.*;
  
  /**
   * Wrapper around <code>javax.servlet.FilterChain</code> in order to provide
   * additional features useful for writing unit tests.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterChainWrapper.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterChainWrapper implements FilterChain
  {
      /**
       * The mock <code>FilterChain</code> object that will be used in the
       * test case for simulating a response as if it were coming from the
       * next filter in the chain.
       *
       * @see #setMockFilterChain(FilterChain)
       * @see #doFilter(ServletRequest, ServletResponse)
       */
      private FilterChain mockFilterChain;
  
  
      /**
       * The original <code>FilterChain</code> from the Filter Redirector.
       */
      private FilterChain originalFilterChain;
  
      // Constructor -----------------------------------------------------------
  
      /**
       * Construct a wrapped filter chain object that delegates almost all its
       * calls to the original filter chain from the Filter Redirector.
       *
       * @param theChain the original filter chain from the Filter Redirector
       */
      public FilterChainWrapper(FilterChain theChain)
      {
          this.originalFilterChain = theChain;
      }
  
      // Additional Methods ----------------------------------------------------
  
      /**
       * Sets a mock filter chain, which is used to simplify writing unit
       * tests for a filter.
       * <pre><code>
       * [...]
       * filterChain.setMockFilterChain(new FilterChain() {
       *     public void doFilter(ServletRequest theRequest,
       *         ServletResponse theResponse) throws IOException, ServletException
       *     {
       *         PrintWriter writer = theResponse.getWriter();
       *         writer.print("<p>some content</p>");
       *         writer.close();
       *     }
       * });
       * [...]
       * </code></pre>
       *
       * @param theMockFilterChain the mock filter chain that will be called
       *        to simulate the next filter in the chain
       *
       * @see #doFilter(ServletRequest, ServletResponse)
       */
      public void setMockFilterChain(FilterChain theMockFilterChain)
      {
          this.mockFilterChain = theMockFilterChain;
      }
  
      // Overriden Methods -----------------------------------------------------
  
      /**
       * Invoke the next filter in this chain, passing the specified request
       * and response. If there are no more filters in this chain, invoke
       * the <code>service()</code> method of the servlet itself. If a mock
       * filter chain has been specified using <code>setMockFilterChain()</code>
       * then call this mock filter instead of the next filter in the chain;
       * this is to help write unit test (see
       * {@link #setMockFilter(FilterChain) setMockFilter}).
       *
       * @param request The servlet request we are processing
       * @param response The servlet response we are creating
       *
       * @exception IOException if an input/output error occurs
       * @exception ServletException if a servlet exception occurs
       */
      public void doFilter(ServletRequest theRequest,
          ServletResponse theResponse) throws IOException, ServletException
      {
          if (this.mockFilterChain != null) {
              this.mockFilterChain.doFilter(theRequest, theResponse);
          } else {
              this.originalFilterChain.doFilter(theRequest, theResponse);
          }
      }
  
  }
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterConfigWrapper.java
  
  Index: FilterConfigWrapper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import java.util.*;
  import java.io.*;
  import java.security.*;
  import java.net.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Wrapper around <code>FilterConfig</code> which overrides the
   * <code>getServletContext()</code> method to return our own wrapper around
   * <code>ServletContext</code>.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterConfigWrapper.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   * @see ServletContext
   */
  public class FilterConfigWrapper implements FilterConfig
  {
      /**
       * The original filter config object
       */
      private FilterConfig originalConfig;
  
      /**
       * List of parameters set using the <code>setInitParameter()</code> method.
       */
      private Hashtable initParameters;
  
      /**
       * Simulated name of the filter
       */
      private String filterName;
  
      /**
       * @param theOriginalConfig the original filter config object
       */
      public FilterConfigWrapper(FilterConfig theOriginalConfig)
      {
          this.originalConfig = theOriginalConfig;
          this.initParameters = new Hashtable();
      }
  
      /**
       * Sets a parameter as if it were set in the <code>web.xml</code> file.
       *
       * @param theName the parameter's name
       * @param theValue the parameter's value
       */
      public void setInitParameter(String theName, String theValue)
      {
          this.initParameters.put(theName, theValue);
      }
  
      /**
       * Sets the filter name. That will be the value returned by the
       * <code>getFilterName()</code> method.
       *
       * @param theFilterName the filter name
       */
      public void setFilterName(String theFilterName)
      {
          this.filterName = theFilterName;
      }
  
      //--Overridden methods ----------------------------------------------------
  
      /**
       * @return the simulated filter's name if defined or the redirector
       *         filter's name
       */
      public String getFilterName()
      {
          if (this.filterName != null) {
              return this.filterName;
          }
  
          return this.originalConfig.getFilterName();
      }
  
      /**
       * @return our own wrapped servlet context object
       */
      public ServletContext getServletContext()
      {
          return new ServletContextWrapper(
              this.originalConfig.getServletContext());
      }
  
      /**
       * @return the union of the parameters defined in the Redirector
       *         <code>web.xml</code> file and the one set using the
       *         <code>setInitParameter()</code> method.
       */
      public Enumeration getInitParameterNames()
      {
          Vector names = new Vector();
  
          Enumeration enum = this.initParameters.keys();
          while (enum.hasMoreElements()) {
              String value = (String)enum.nextElement();
              names.add(value);
          }
  
          enum = this.originalConfig.getInitParameterNames();
          while (enum.hasMoreElements()) {
              String value = (String)enum.nextElement();
              names.add(value);
          }
  
          return names.elements();
      }
  
      /**
       * @param theName the name of the parameter's value to return
       * @return the value of the parameter, looking for it first in the list of
       *         parameters set using the <code>setInitParameter()</code> method
       *         and then in those set in <code>web.xml</code>.
       */
      public String getInitParameter(String theName)
      {
          // Look first in the list of parameters set using the
          // setInitParameter() method.
          String value = (String)this.initParameters.get(theName);
          if (value == null) {
              value = this.originalConfig.getInitParameter(theName);
          }
  
          return value;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterImplicitObjects.java
  
  Index: FilterImplicitObjects.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Holder class that contains the instances of the implicit objects that will
   * be accessible in the test classes (i.e. subclasses of
   * <code>FilterTestCase</code>).
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterImplicitObjects.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterImplicitObjects extends WebImplicitObjects
  {
      /**
       * The Filter configuration object.
       */
      protected FilterConfig config;
  
      /**
       * The Filter chain object.
       */
      protected FilterChain filterChain;
  
      /**
       * @return the <code>FilterConfig</code> implicit object
       */
      public FilterConfig getFilterConfig()
      {
          return this.config;
      }
  
      /**
       * @param theConfig the <code>FilterConfig</code> implicit object
       */
      public void setFilterConfig(FilterConfig theConfig)
      {
          this.config = theConfig;
      }
  
      /**
       * @return the <code>FilterChain</code> implicit object
       */
      public FilterChain getFilterChain()
      {
          return this.filterChain;
      }
  
      /**
       * @param theRequest the <code>FilterChain</code> implicit object
       */
      public void setFilterChain(FilterChain theFilterChain)
      {
          this.filterChain = theFilterChain;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterTestCaller.java
  
  Index: FilterTestCaller.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import java.io.*;
  import java.lang.reflect.*;
  import java.net.*;
  import java.util.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  import org.apache.commons.cactus.*;
  import org.apache.commons.cactus.util.log.*;
  
  /**
   * Responsible for instanciating the <code>TestCase</code> class on the server
   * side, set up the implicit objects and call the test method.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterTestCaller.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterTestCaller extends AbstractTestCaller
  {
      /**
       * The logger
       */
      protected static Log logger =
          LogService.getInstance().getLog(FilterTestCaller.class.getName());
  
      /**
       * @param theObjects the implicit objects coming from the redirector
       */
      public FilterTestCaller(FilterImplicitObjects theObjects)
      {
          super(theObjects);
      }
  
      /**
       * Sets the test case fields using the implicit objects (using reflection).
       * @param theTestInstance the test class instance
       */
      protected void setTestCaseFields(AbstractTestCase theTestInstance)
          throws Exception
      {
          logger.entry("setTestCaseFields([" + theTestInstance + "])");
  
          FilterTestCase filterInstance = (FilterTestCase)theTestInstance;
          FilterImplicitObjects filterImplicitObjects =
              (FilterImplicitObjects)this.webImplicitObjects;
  
          // Sets the request field of the test case class
          // ---------------------------------------------
  
          // Extract from the HTTP request the URL to simulate (if any)
          HttpServletRequest request =
              filterImplicitObjects.getHttpServletRequest();
  
          ServletURL url = ServletURL.loadFromRequest(request);
  
          Field requestField = filterInstance.getClass().getField("request");
          requestField.set(filterInstance,
              new HttpServletRequestWrapper(request, url));
  
          // Set the response field of the test case class
          // ---------------------------------------------
  
          Field responseField = filterInstance.getClass().getField("response");
          responseField.set(filterInstance,
              filterImplicitObjects.getHttpServletResponse());
  
          // Set the config field of the test case class
          // -------------------------------------------
  
          Field configField = filterInstance.getClass().getField("config");
          configField.set(filterInstance,
              new FilterConfigWrapper(filterImplicitObjects.getFilterConfig()));
  
          // Set the filter chain of the test case class
          // -------------------------------------------
  
          Field chainField = filterInstance.getClass().getField("filterChain");
          chainField.set(filterInstance,
              new FilterChainWrapper(filterImplicitObjects.getFilterChain()));
  
          logger.exit("setTestCaseFields");
      }
  
  }
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterTestController.java
  
  Index: FilterTestController.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import java.io.*;
  import java.lang.reflect.*;
  import java.net.*;
  import java.util.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  import org.apache.commons.cactus.*;
  import org.apache.commons.cactus.util.log.*;
  
  /**
   * Filter Controller that extracts the requested service from the
   * HTTP request and executes the request by calling a
   * <code>FilterTestCaller</code>. There are 2 services available : one for
   * executing the test and one for returning the test result.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterTestController.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   */
  public class FilterTestController extends AbstractTestController
  {
      /**
       * @return the test caller that will be used to execute the test
       */
      protected AbstractTestCaller getTestCaller(
              WebImplicitObjects theObjects)
      {
          return new FilterTestCaller((FilterImplicitObjects)theObjects);
      }
  
  }
  
  
  1.1                  
jakarta-commons/cactus/src/framework/servlet23/org/apache/commons/cactus/server/FilterTestRedirector.java
  
  Index: FilterTestRedirector.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.cactus.server;
  
  import java.io.*;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  import org.apache.commons.cactus.*;
  import org.apache.commons.cactus.util.log.*;
  
  /**
   * Generic Filter redirector that calls a test method on the server side.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
   *
   * @version $Id: FilterTestRedirector.java,v 1.1 2001/09/07 16:05:36 vmassol Exp $
   * @see FilterTestCaller
   */
  public class FilterTestRedirector implements Filter
  {
      /**
       * Initialize the logging subsystem so that it can get it's configuration
       * details from the correct properties file. Initialization is done here
       * as this servlet is the first point of entry to the server code.
       */
      static {
          LogService.getInstance().init("/log_server.properties");
      }
  
      /**
       * The logger
       */
      private static Log logger =
          LogService.getInstance().getLog(FilterTestRedirector.class.getName());
  
      /**
       * The filter configuration object passed by the container when it calls
       * <code>init(FilterConfig)</code>
       */
      private FilterConfig config;
  
      /**
       * Handle the request. Extract from the HTTP request paramete the
       * Service to perform : call test method or return tests results.
       *
       * @param theRequest the incoming HTTP request which contains all needed
       *                   information on the test case and method to call
       * @param theResponse the response to send back to the client side
       * @param theFilterChain contains the chain of filters.
       */
      public void doFilter(ServletRequest theRequest,
          ServletResponse theResponse, FilterChain theFilterChain)
          throws IOException, ServletException
      {
          this.logger.entry("doFilter(...)");
  
          // Create implicit object holder
          FilterImplicitObjects objects = new FilterImplicitObjects();
          objects.setHttpServletRequest((HttpServletRequest)theRequest);
          objects.setHttpServletResponse((HttpServletResponse)theResponse);
          objects.setFilterConfig(this.config);
          objects.setServletContext(this.config.getServletContext());
          objects.setFilterChain(theFilterChain);
  
          FilterTestController controller = new FilterTestController();
          controller.handleRequest(objects);
  
          this.logger.exit("doFilter");
      }
  
      /**
       * Initialise this filter redirector. Called by the container.
       *
       * @param theConfig the filter config containing initialisation
       *                  parameters from web.xml
       */
      public void init(FilterConfig theConfig)
      {
          // Save the config to pass it to the test case later on
          this.config = theConfig;
      }
  
      /**
       * Destroy the filter. Called by the container.
       */
      public void destroy()
      {
      }
  
  }
  
  

Reply via email to