Clover coverage report - Cactus 1.4 for J2EE API 13
Coverage timestamp: Sun Aug 25 2002 18:02:10 BST
file stats: LOC: 128   Methods: 4
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractHttpClient.java 100% 96% 100% 97%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.client;
 3   
 import java.net.HttpURLConnection;
 4   
 import org.apache.cactus.HttpServiceDefinition;
 5   
 import org.apache.cactus.ServiceEnumeration;
 6   
 import org.apache.cactus.WebRequest;
 7   
 import org.apache.cactus.WebTestResult;
 8   
 import org.apache.cactus.WebResponse;
 9   
 import org.apache.cactus.util.IoUtil;
 10   
 import org.apache.cactus.util.ChainedRuntimeException;
 11   
 import org.apache.cactus.client.authentication.AbstractAuthentication;
 12   
 
 13   
 /** 
 14   
  * Abstract class for performing the steps necessary to run a test. It involves 
 15   
  * opening a first HTTP connection to a server redirector, reading the output 
 16   
  * stream and then opening a second HTTP connection to retrieve the test result. 
 17   
  * 
 18   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 19   
  * @author <a href="mailto:Jason.Robertson@acs-inc.com">Jason Robertson</a> 
 20   
  * 
 21   
  * @version $Id: AbstractHttpClient.java,v 1.10 2002/07/24 20:46:48 vmassol Exp $ 
 22   
  */
 23   
 public abstract class AbstractHttpClient {
 24   
   /** 
 25   
        * Return the redirector URL to connect to. 
 26   
        * 
 27   
        * @param theRequest Request data from the user. We need it here as the user 
 28   
        *        may have chosen to override the default redirector. 
 29   
        * @return the URL to call the redirector 
 30   
        */
 31   
   protected abstract String getRedirectorURL(WebRequest theRequest);
 32   
 
 33   
   /** 
 34   
        * Calls the test method indirectly by calling the Redirector servlet and 
 35   
        * then open a second HTTP connection to retrieve the test results. 
 36   
        * 
 37   
        * @param theRequest the request containing all data to pass to the 
 38   
        *                   redirector servlet. 
 39   
        * 
 40   
        * @return the <code>HttpURLConnection</code> that contains the HTTP 
 41   
        *         response when the test was called. 
 42   
        * 
 43   
        * @exception Throwable if an error occured in the test method or in the 
 44   
        *                      redirector servlet. 
 45   
        */
 46  64
   public HttpURLConnection doTest(WebRequest theRequest) throws Throwable {
 47  64
     HttpURLConnection connection = this.callRunTest(theRequest);
 48  64
     WebTestResult result = null;
 49  64
     try {
 50  64
       result = this.callGetResult(theRequest.getAuthentication());
 51   
     } catch (ParsingException e) {
 52  0
       throw new ChainedRuntimeException(
 53   
           "Failed to get the test results. This is probably due to an error that happened on the server side when trying to execute the tests. Here is what was returned by the server : [" 
 54   
           + new WebResponse(theRequest, connection).getText() + "]", e);
 55   
     } 
 56  64
     if (result.hasException()) {
 57  4
       if (result.getExceptionClassName().equals("junit.framework.AssertionFailedError")) {
 58  2
         throw new AssertionFailedErrorWrapper(result.getExceptionMessage(), 
 59   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 60   
       } else {
 61  2
         throw new ServletExceptionWrapper(result.getExceptionMessage(), 
 62   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 63   
       } 
 64   
     } 
 65  60
     return connection;
 66   
   } 
 67   
 
 68   
   /** 
 69   
        * Execute the test by calling the redirector. 
 70   
        * 
 71   
        * @param theRequest the request containing all data to pass to the 
 72   
        *                   redirector servlet. 
 73   
        * @return the <code>HttpURLConnection</code> that contains the HTTP 
 74   
        *         response when the test was called. 
 75   
        * 
 76   
        * @exception Throwable if an error occured in the test method or in the 
 77   
        *                      redirector servlet. 
 78   
        */
 79  64
   private HttpURLConnection callRunTest(WebRequest theRequest) throws Throwable {
 80  64
     theRequest.addParameter("Cactus_Service", ServiceEnumeration.CALL_TEST_SERVICE.toString(), 
 81   
         "GET");
 82  64
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 83   
         theRequest));
 84  64
     HttpURLConnection connection = helper.connect(theRequest);
 85  64
     connection = new AutoReadHttpURLConnection(connection);
 86  64
     connection.getInputStream();
 87  64
     return connection;
 88   
   } 
 89   
 
 90   
   /** 
 91   
        * Get the test result from the redirector. 
 92   
        * 
 93   
        * @param theAuthentication Authentication object used to authenticate 
 94   
        *        the user when securing Redirectors for testing security / 
 95   
        *        authentication code. Can be null if security is not enabled for 
 96   
        *        the redirector. 
 97   
        * @return the result that was returned by the redirector. 
 98   
        * 
 99   
        * @exception Throwable if an error occured in the test method or in the 
 100   
        *                      redirector servlet. 
 101   
        */
 102  64
   private WebTestResult callGetResult(AbstractAuthentication theAuthentication) throws Throwable {
 103  64
     WebRequest resultsRequest = new WebRequest();
 104  64
     resultsRequest.addParameter("Cactus_Service", 
 105   
         ServiceEnumeration.GET_RESULTS_SERVICE.toString(), "GET");
 106  64
     resultsRequest.setAuthentication(theAuthentication);
 107  64
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 108   
         resultsRequest));
 109  64
     HttpURLConnection resultConnection = helper.connect(resultsRequest);
 110  64
     WebTestResultParser parser = new WebTestResultParser();
 111  64
     WebTestResult result = parser.parse(IoUtil.getText(resultConnection.getInputStream()));
 112  64
     return result;
 113   
   } 
 114   
 
 115   
   /** 
 116   
    * Abstract class for performing the steps necessary to run a test. It involves 
 117   
    * opening a first HTTP connection to a server redirector, reading the output 
 118   
    * stream and then opening a second HTTP connection to retrieve the test result. 
 119   
    * 
 120   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 121   
    * @author <a href="mailto:Jason.Robertson@acs-inc.com">Jason Robertson</a> 
 122   
    * 
 123   
    * @version $Id: AbstractHttpClient.java,v 1.10 2002/07/24 20:46:48 vmassol Exp $ 
 124   
    */
 125  64
   public AbstractHttpClient() {
 126  64
     super();
 127   
   } 
 128   
 }