Clover coverage report - Cactus 1.4 for J2EE API 12
Coverage timestamp: Sun Aug 25 2002 18:00:03 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  177
   public HttpURLConnection doTest(WebRequest theRequest) throws Throwable {
 47  177
     HttpURLConnection connection = this.callRunTest(theRequest);
 48  177
     WebTestResult result = null;
 49  177
     try {
 50  177
       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  177
     if (result.hasException()) {
 57  12
       if (result.getExceptionClassName().equals("junit.framework.AssertionFailedError")) {
 58  6
         throw new AssertionFailedErrorWrapper(result.getExceptionMessage(), 
 59   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 60   
       } else {
 61  6
         throw new ServletExceptionWrapper(result.getExceptionMessage(), 
 62   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 63   
       } 
 64   
     } 
 65  165
     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  177
   private HttpURLConnection callRunTest(WebRequest theRequest) throws Throwable {
 80  177
     theRequest.addParameter("Cactus_Service", ServiceEnumeration.CALL_TEST_SERVICE.toString(), 
 81   
         "GET");
 82  177
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 83   
         theRequest));
 84  177
     HttpURLConnection connection = helper.connect(theRequest);
 85  177
     connection = new AutoReadHttpURLConnection(connection);
 86  177
     connection.getInputStream();
 87  177
     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  177
   private WebTestResult callGetResult(AbstractAuthentication theAuthentication) throws Throwable {
 103  177
     WebRequest resultsRequest = new WebRequest();
 104  177
     resultsRequest.addParameter("Cactus_Service", 
 105   
         ServiceEnumeration.GET_RESULTS_SERVICE.toString(), "GET");
 106  177
     resultsRequest.setAuthentication(theAuthentication);
 107  177
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 108   
         resultsRequest));
 109  177
     HttpURLConnection resultConnection = helper.connect(resultsRequest);
 110  177
     WebTestResultParser parser = new WebTestResultParser();
 111  177
     WebTestResult result = parser.parse(IoUtil.getText(resultConnection.getInputStream()));
 112  177
     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  177
   public AbstractHttpClient() {
 126  177
     super();
 127   
   } 
 128   
 }