2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 117   Methods: 3
NCLOC: 52   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ServletTestCaller.java 50% 94.4% 100% 88%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2001-2004 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus.internal.server;
 21   
 
 22   
 import java.io.IOException;
 23   
 import java.io.Writer;
 24   
 
 25   
 import java.lang.reflect.Field;
 26   
 
 27   
 import javax.servlet.http.HttpServletRequest;
 28   
 import javax.servlet.http.HttpSession;
 29   
 
 30   
 import junit.framework.TestCase;
 31   
 
 32   
 import org.apache.cactus.ServletTestCase;
 33   
 import org.apache.cactus.ServletURL;
 34   
 import org.apache.cactus.server.HttpServletRequestWrapper;
 35   
 import org.apache.cactus.server.ServletConfigWrapper;
 36   
 
 37   
 /**
 38   
  * Responsible for instanciating the <code>TestCase</code> class on the server
 39   
  * side, set up the implicit objects and call the test method.
 40   
  *
 41   
  * @version $Id: ServletTestCaller.java 238991 2004-05-22 11:34:50Z vmassol $
 42   
  */
 43   
 public class ServletTestCaller extends AbstractWebTestCaller
 44   
 {
 45   
     /**
 46   
      * @param theObjects the implicit objects coming from the redirector
 47   
      */
 48  38
     public ServletTestCaller(ServletImplicitObjects theObjects)
 49   
     {
 50  38
         super(theObjects);
 51   
     }
 52   
 
 53   
     /**
 54   
      * @see AbstractWebTestCaller#setTestCaseFields(TestCase)
 55   
      */
 56  19
     protected void setTestCaseFields(TestCase theTestInstance)
 57   
         throws Exception
 58   
     {
 59  19
         if (!(theTestInstance instanceof ServletTestCase))
 60   
         {
 61  0
             return; 
 62   
         }
 63   
         
 64  19
         ServletTestCase servletInstance = (ServletTestCase) theTestInstance;
 65  19
         ServletImplicitObjects servletImplicitObjects = 
 66   
             (ServletImplicitObjects) this.webImplicitObjects;
 67   
 
 68   
         // Sets the request field of the test case class
 69   
         // ---------------------------------------------
 70   
         // Extract from the HTTP request the URL to simulate (if any)
 71  19
         HttpServletRequest request = 
 72   
             servletImplicitObjects.getHttpServletRequest();
 73   
 
 74  19
         ServletURL url = ServletURL.loadFromRequest(request);
 75   
 
 76  19
         Field requestField = servletInstance.getClass().getField("request");
 77   
 
 78  19
         requestField.set(servletInstance, 
 79   
             new HttpServletRequestWrapper(request, url));
 80   
 
 81   
         // Set the response field of the test case class
 82   
         // ---------------------------------------------
 83  19
         Field responseField = servletInstance.getClass().getField("response");
 84   
 
 85  19
         responseField.set(servletInstance, 
 86   
             servletImplicitObjects.getHttpServletResponse());
 87   
 
 88   
         // Set the config field of the test case class
 89   
         // -------------------------------------------
 90  19
         Field configField = servletInstance.getClass().getField("config");
 91   
 
 92  19
         configField.set(servletInstance, new ServletConfigWrapper(
 93   
             servletImplicitObjects.getServletConfig()));
 94   
 
 95   
         // Set the session field of the test case class
 96   
         // --------------------------------------------
 97   
         // Create a Session object if the auto session flag is on
 98  19
         if (isAutoSession())
 99   
         {
 100  19
             HttpSession session = servletImplicitObjects.getHttpServletRequest()
 101   
                 .getSession(true);
 102   
 
 103  19
             Field sessionField = servletInstance.getClass().getField("session");
 104   
 
 105  19
             sessionField.set(servletInstance, session);
 106   
         }
 107   
     }
 108   
 
 109   
     /**
 110   
      * @see AbstractWebTestCaller#getResponseWriter()
 111   
      */
 112  14
     protected Writer getResponseWriter() throws IOException
 113   
     {
 114  14
         return this.webImplicitObjects.getHttpServletResponse().getWriter();
 115   
     }
 116   
 }
 117