1 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 42 public abstract class AbstractCactusTestCase extends TestCase 43 { 44 51 static 52 { 53 ConfigurationInitializer.initialize(); 54 } 55 56 62 private ClientTestCaseCaller clientCaller; 63 64 70 private ServerTestCaseCaller serverCaller; 71 72 74 80 protected abstract ProtocolHandler createProtocolHandler(); 81 82 84 89 public AbstractCactusTestCase() 90 { 91 init(null); 92 } 93 94 99 public AbstractCactusTestCase(String theName) 100 { 101 super(theName); 102 init(null); 103 } 104 105 111 public AbstractCactusTestCase(String theName, Test theTest) 112 { 113 super(theName); 114 init(theTest); 115 } 116 117 119 127 public void runBare() throws Throwable 128 { 129 TestCaseImplementChecker.checkTestName(this); 130 TestCaseImplementChecker.checkTestName( 131 getServerCaller().getWrappedTest()); 132 133 runBareClient(); 134 } 135 136 139 public void runBareServer() throws Throwable 140 { 141 getServerCaller().runBareInit(); 142 143 147 if (getServerCaller().getWrappedTest() != null) 148 { 149 ((TestCase) getServerCaller().getWrappedTest()).runBare(); 150 } 151 else 152 { 153 super.runBare(); 154 } 155 } 156 157 159 162 private void setClientCaller(ClientTestCaseCaller theCaller) 163 { 164 this.clientCaller = theCaller; 165 } 166 167 170 private void setServerCaller(ServerTestCaseCaller theCaller) 171 { 172 this.serverCaller = theCaller; 173 } 174 175 178 private ClientTestCaseCaller getClientCaller() 179 { 180 return this.clientCaller; 181 } 182 183 186 private ServerTestCaseCaller getServerCaller() 187 { 188 return this.serverCaller; 189 } 190 191 196 private void init(Test theTest) 197 { 198 setClientCaller(new ClientTestCaseCaller(this, theTest, 199 createProtocolHandler())); 200 setServerCaller(new ServerTestCaseCaller(this, theTest)); 201 } 202 203 208 private void runBareClient() throws Throwable 209 { 210 getClientCaller().runBareInit(); 211 212 try 214 { 215 getClientCaller().runTest(); 216 } 217 catch (Throwable t) 218 { 219 getClientCaller().getLogger().debug("Exception in test", t); 221 throw t; 222 } 223 } 224 } 225 | Popular Tags |