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

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.internal.server;
22  
23  import junit.framework.Assert;
24  import junit.framework.Test;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /**
30   * Provide the ability to execute Cactus test case classes on the server side.
31   * It mimics the JUnit behavior by calling <code>setUp()</code>, 
32   * <code>testXXX()</code> and <code>tearDown()</code> methods on the server
33   * side.
34   *
35   * @version $Id: ServerTestCaseCaller.java 238991 2004-05-22 11:34:50Z vmassol $
36   */
37  public class ServerTestCaseCaller extends Assert
38  {
39      /**
40       * The logger.
41       */
42      private Log logger;
43  
44      /**
45       * The test we are delegating for.
46       */
47      private Test delegatedTest;   
48  
49      /**
50       * Pure JUnit Test Case that we are wrapping (if any).
51       */
52      private Test wrappedTest;
53  
54      /**
55       * @param theDelegatedTest the test we are delegating for
56       * @param theWrappedTest the test being wrapped by this delegate (or null 
57       *        if none)
58       */
59      public ServerTestCaseCaller(Test theDelegatedTest, Test theWrappedTest) 
60      {        
61          if (theDelegatedTest == null)
62          {
63              throw new IllegalStateException(
64                  "The test object passed must not be null");
65          }
66  
67          setDelegatedTest(theDelegatedTest); 
68          setWrappedTest(theWrappedTest);
69      }
70  
71      /**
72       * @param theWrappedTest the pure JUnit test that we need to wrap 
73       */
74      public void setWrappedTest(Test theWrappedTest)
75      {
76          this.wrappedTest = theWrappedTest;
77      }
78  
79      /**
80       * @return the wrapped JUnit test
81       */
82      public Test getWrappedTest()
83      {
84          return this.wrappedTest;
85      }
86  
87      /**
88       * @param theDelegatedTest the test we are delegating for
89       */
90      public void setDelegatedTest(Test theDelegatedTest)
91      {
92          this.delegatedTest = theDelegatedTest;
93      }
94  
95      /**
96       * @return the test we are delegating for
97       */
98      public Test getDelegatedTest()
99      {
100         return this.delegatedTest;
101     }
102 
103     /**
104      * Perform server side initializations before each test, such as
105      * initializating the logger.
106      */
107     public void runBareInit()
108     {
109         // Initialize the logging system. As this class is instanciated both
110         // on the server side and on the client side, we need to differentiate
111         // the logging initialisation. This method is only called on the server
112         // side, so we instanciate the log for server side here.
113         if (getLogger() == null)
114         {
115             setLogger(LogFactory.getLog(getDelegatedTest().getClass()));
116         }        
117     }
118     
119     /**
120      * @return the logger pointing to the wrapped test case that use to perform
121      *         logging on behalf of the wrapped test.
122      */
123     private Log getLogger()
124     {
125         return this.logger;
126     }
127 
128     /**
129      * @param theLogger the logger to use 
130      */
131     private void setLogger(Log theLogger)
132     {
133         this.logger = theLogger;
134     }
135 }