001: /*
002: * ========================================================================
003: *
004: * Copyright 2001-2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.internal.server;
021:
022: import junit.framework.Assert;
023: import junit.framework.Test;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * Provide the ability to execute Cactus test case classes on the server side.
030: * It mimics the JUnit behavior by calling <code>setUp()</code>,
031: * <code>testXXX()</code> and <code>tearDown()</code> methods on the server
032: * side.
033: *
034: * @version $Id: ServerTestCaseCaller.java 238991 2004-05-22 11:34:50Z vmassol $
035: */
036: public class ServerTestCaseCaller extends Assert {
037: /**
038: * The logger.
039: */
040: private Log logger;
041:
042: /**
043: * The test we are delegating for.
044: */
045: private Test delegatedTest;
046:
047: /**
048: * Pure JUnit Test Case that we are wrapping (if any)
049: */
050: private Test wrappedTest;
051:
052: /**
053: * @param theDelegatedTest the test we are delegating for
054: * @param theWrappedTest the test being wrapped by this delegate (or null
055: * if none)
056: */
057: public ServerTestCaseCaller(Test theDelegatedTest,
058: Test theWrappedTest) {
059: if (theDelegatedTest == null) {
060: throw new IllegalStateException(
061: "The test object passed must not be null");
062: }
063:
064: setDelegatedTest(theDelegatedTest);
065: setWrappedTest(theWrappedTest);
066: }
067:
068: /**
069: * @param theWrappedTest the pure JUnit test that we need to wrap
070: */
071: public void setWrappedTest(Test theWrappedTest) {
072: this .wrappedTest = theWrappedTest;
073: }
074:
075: /**
076: * @return the wrapped JUnit test
077: */
078: public Test getWrappedTest() {
079: return this .wrappedTest;
080: }
081:
082: /**
083: * @param theDelegatedTest the test we are delegating for
084: */
085: public void setDelegatedTest(Test theDelegatedTest) {
086: this .delegatedTest = theDelegatedTest;
087: }
088:
089: /**
090: * @return the test we are delegating for
091: */
092: public Test getDelegatedTest() {
093: return this .delegatedTest;
094: }
095:
096: /**
097: * Perform server side initializations before each test, such as
098: * initializating the logger.
099: */
100: public void runBareInit() {
101: // Initialize the logging system. As this class is instanciated both
102: // on the server side and on the client side, we need to differentiate
103: // the logging initialisation. This method is only called on the server
104: // side, so we instanciate the log for server side here.
105: if (getLogger() == null) {
106: setLogger(LogFactory.getLog(getDelegatedTest().getClass()));
107: }
108: }
109:
110: /**
111: * @return the logger pointing to the wrapped test case that use to perform
112: * logging on behalf of the wrapped test.
113: */
114: private Log getLogger() {
115: return this .logger;
116: }
117:
118: /**
119: * @param theLogger the logger to use
120: */
121: private void setLogger(Log theLogger) {
122: this.logger = theLogger;
123: }
124: }
|