Clover coverage report - Cactus 1.4.1 for J2EE API 13
Coverage timestamp: Sat Aug 31 2002 22:02:23 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.html,v 1.1 2003/04/14 12:27:31 sinisa 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  330
   public HttpURLConnection doTest(WebRequest theRequest) throws Throwable {
 47  330
     HttpURLConnection connection = this.callRunTest(theRequest);
 48  330
     WebTestResult result = null;
 49  330
     try {
 50  330
       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  330
     if (result.hasException()) {
 57  20
       if (result.getExceptionClassName().equals("junit.framework.AssertionFailedError")) {
 58  10
         throw new AssertionFailedErrorWrapper(result.getExceptionMessage(), 
 59   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 60   
       } else {
 61  10
         throw new ServletExceptionWrapper(result.getExceptionMessage(), 
 62   
             result.getExceptionClassName(), result.getExceptionStackTrace());
 63   
       } 
 64   
     } 
 65  310
     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  330
   private HttpURLConnection callRunTest(WebRequest theRequest) throws Throwable {
 80  330
     theRequest.addParameter("Cactus_Service", ServiceEnumeration.CALL_TEST_SERVICE.toString(), 
 81   
         "GET");
 82  330
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 83   
         theRequest));
 84  330
     HttpURLConnection connection = helper.connect(theRequest);
 85  330
     connection = new AutoReadHttpURLConnection(connection);
 86  330
     connection.getInputStream();
 87  330
     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  330
   private WebTestResult callGetResult(AbstractAuthentication theAuthentication) throws Throwable {
 103  330
     WebRequest resultsRequest = new WebRequest();
 104  330
     resultsRequest.addParameter("Cactus_Service", 
 105   
         ServiceEnumeration.GET_RESULTS_SERVICE.toString(), "GET");
 106  330
     resultsRequest.setAuthentication(theAuthentication);
 107  330
     ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(this.getRedirectorURL(
 108   
         resultsRequest));
 109  330
     HttpURLConnection resultConnection = helper.connect(resultsRequest);
 110  330
     WebTestResultParser parser = new WebTestResultParser();
 111  330
     WebTestResult result = parser.parse(IoUtil.getText(resultConnection.getInputStream()));
 112  330
     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.html,v 1.1 2003/04/14 12:27:31 sinisa Exp $ 
 124   
    */
 125  330
   public AbstractHttpClient() {
 126  330
     super();
 127   
   } 
 128   
 }