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: 225   Methods: 11
NCLOC: 86   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
AbstractCactusTestCase.java 50% 70.8% 81.8% 73%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2003-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;
 21   
 
 22   
 import junit.framework.Test;
 23   
 import junit.framework.TestCase;
 24   
 
 25   
 import org.apache.cactus.internal.client.ClientTestCaseCaller;
 26   
 import org.apache.cactus.internal.configuration.ConfigurationInitializer;
 27   
 import org.apache.cactus.internal.server.ServerTestCaseCaller;
 28   
 import org.apache.cactus.internal.util.TestCaseImplementChecker;
 29   
 import org.apache.cactus.spi.client.connector.ProtocolHandler;
 30   
 
 31   
 /**
 32   
  * Base class for all Cactus test case extensions.
 33   
  * 
 34   
  * Note: We must not add any method that can be called by the end user to this
 35   
  * class as users will those methods and it will create a runtime dependency to 
 36   
  * this class. We will then have to break binary compatibility if we wish to
 37   
  * move this class around or change its implementation.
 38   
  * 
 39   
  * @version $Id: AbstractCactusTestCase.java 238991 2004-05-22 11:34:50Z vmassol $
 40   
  * @since 1.6 
 41   
  */
 42   
 public abstract class AbstractCactusTestCase extends TestCase
 43   
 {
 44   
     /**
 45   
      * As this class is the first one loaded on the client side, we ensure
 46   
      * that the Cactus configuration has been initialized. In the future,
 47   
      * this block will be removed as all initialization will be done in Cactus
 48   
      * test suites. However, as we still support using Cactus TestCase classes
 49   
      * we don't have a proper initialization hook and thus we need this hack.
 50   
      */
 51   
     static
 52   
     {
 53  1
         ConfigurationInitializer.initialize();
 54   
     }
 55   
 
 56   
     /**
 57   
      * Provides all client side Cactus calling logic.
 58   
      * Note that we are using a delegate class instead of inheritance in order 
 59   
      * to hide non public API to the users and thus to be able to easily change
 60   
      * the implementation.
 61   
      */
 62   
     private ClientTestCaseCaller clientCaller;
 63   
 
 64   
     /**
 65   
      * Provides all server side Cactus calling logic. 
 66   
      * Note that we are using a delegate class instead of inheritance in order 
 67   
      * to hide non public API to the users and thus to be able to easily change
 68   
      * the implementation.
 69   
      */
 70   
     private ServerTestCaseCaller serverCaller;
 71   
 
 72   
     // Abstract methods -----------------------------------------------------
 73   
 
 74   
     /**
 75   
      * Create a protocol handler instance that will be used to connect to the
 76   
      * server side.
 77   
      * 
 78   
      * @return the protocol handler instance
 79   
      */
 80   
     protected abstract ProtocolHandler createProtocolHandler();
 81   
     
 82   
     // Constructors ---------------------------------------------------------
 83   
 
 84   
     /**
 85   
      * Default constructor defined in order to allow creating Test Case
 86   
      * without needing to define constructor (new feature in JUnit 3.8.1).
 87   
      * Should only be used with JUnit 3.8.1 or greater. 
 88   
      */
 89  48
     public AbstractCactusTestCase()
 90   
     {
 91  48
         init(null);
 92   
     }
 93   
 
 94   
     /**
 95   
      * Constructs a JUnit test case with the given name.
 96   
      *
 97   
      * @param theName the name of the test case
 98   
      */
 99  0
     public AbstractCactusTestCase(String theName)
 100   
     {
 101  0
         super(theName);
 102  0
         init(null);
 103   
     }
 104   
 
 105   
     /**
 106   
      * Wraps a pure JUnit Test Case in a Cactus Test Case.
 107   
      *  
 108   
      * @param theName the name of the test
 109   
      * @param theTest the Test Case class to wrap
 110   
      */
 111  0
     public AbstractCactusTestCase(String theName, Test theTest)
 112   
     {
 113  0
         super(theName);
 114  0
         init(theTest);
 115   
     }
 116   
     
 117   
     // Public methods -------------------------------------------------------
 118   
 
 119   
     /**
 120   
      * JUnit method that is used to run the tests. However, we're intercepting
 121   
      * it so that we can call the server side of Cactus where the tests will
 122   
      * be run (instead of on the client side).
 123   
      *
 124   
      * @exception Throwable if any exception is thrown during the test. Any
 125   
      *            exception will be displayed by the JUnit Test Runner
 126   
      */
 127  24
     public void runBare() throws Throwable
 128   
     {
 129  24
         TestCaseImplementChecker.checkTestName(this);
 130  24
         TestCaseImplementChecker.checkTestName(
 131   
             getServerCaller().getWrappedTest());
 132   
 
 133  24
         runBareClient();
 134   
     }
 135   
 
 136   
     /**
 137   
      * @see CactusTestCase#runBareServer()
 138   
      */
 139  24
     public void runBareServer() throws Throwable
 140   
     {
 141  24
         getServerCaller().runBareInit();            
 142   
 
 143   
         // Note: We cannot delegate this piece of code in the
 144   
         // ServerTestCaseDelegate class as it requires to call
 145   
         // super.runBare()
 146   
 
 147  24
         if (getServerCaller().getWrappedTest() != null)
 148   
         {
 149  0
             ((TestCase) getServerCaller().getWrappedTest()).runBare();
 150   
         }
 151   
         else
 152   
         {
 153  24
             super.runBare();            
 154   
         }
 155   
     }
 156   
     
 157   
     // Private methods ------------------------------------------------------
 158   
     
 159   
     /**
 160   
      * @param theCaller the client test case calling class
 161   
      */
 162  48
     private void setClientCaller(ClientTestCaseCaller theCaller)
 163   
     {
 164  48
         this.clientCaller = theCaller;
 165   
     }
 166   
 
 167   
     /**
 168   
      * @param theCaller the server test case calling class
 169   
      */
 170  48
     private void setServerCaller(ServerTestCaseCaller theCaller)
 171   
     {
 172  48
         this.serverCaller = theCaller;
 173   
     }
 174   
 
 175   
     /**
 176   
      * @return the client test case caller
 177   
      */
 178  48
     private ClientTestCaseCaller getClientCaller()
 179   
     {
 180  48
         return this.clientCaller;
 181   
     }
 182   
 
 183   
     /**
 184   
      * @return the server test case caller
 185   
      */
 186  72
     private ServerTestCaseCaller getServerCaller()
 187   
     {
 188  72
         return this.serverCaller;
 189   
     }
 190   
     
 191   
     /**
 192   
      * Initializations common to all constructors.
 193   
      *  
 194   
      * @param theTest a pure JUnit Test that Cactus will wrap
 195   
      */
 196  48
     private void init(Test theTest)
 197   
     {
 198  48
         setClientCaller(new ClientTestCaseCaller(this, theTest,
 199   
             createProtocolHandler()));
 200  48
         setServerCaller(new ServerTestCaseCaller(this, theTest));
 201   
     }
 202   
 
 203   
     /**
 204   
      * Introduced for symmetry with {@link #runBareServer()}.
 205   
      * 
 206   
      * @see #runBare()
 207   
      */
 208  24
     private void runBareClient() throws Throwable
 209   
     {    
 210  24
         getClientCaller().runBareInit();            
 211   
 
 212   
         // Catch the exception just to have a chance to log it
 213  24
         try
 214   
         {
 215  24
             getClientCaller().runTest();
 216   
         }
 217   
         catch (Throwable t)
 218   
         {
 219   
             // TODO: Move getLogger to this class instead
 220  0
             getClientCaller().getLogger().debug("Exception in test", t);
 221  0
             throw t;
 222   
         }
 223   
     }   
 224   
 }
 225