001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.test.server.appserver.deployment;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009:
010: import com.tc.test.server.appserver.StandardAppServerParameters;
011: import com.tc.test.server.util.TcConfigBuilder;
012:
013: import junit.framework.Test;
014: import junit.framework.TestSuite;
015:
016: public abstract class AbstractOneServerDeploymentTest extends
017: AbstractDeploymentTest {
018: public WebApplicationServer server0;
019:
020: public void setServer0(WebApplicationServer server0) {
021: this .server0 = server0;
022: }
023:
024: protected boolean shouldKillAppServersEachRun() {
025: return false;
026: }
027:
028: public static abstract class OneServerTestSetup extends
029: ServerTestSetup {
030: private Log logger = LogFactory.getLog(getClass());
031:
032: private final Class testClass;
033: private final String context;
034: private final TcConfigBuilder tcConfigBuilder;
035:
036: private boolean start = true;
037:
038: protected WebApplicationServer server0;
039:
040: protected OneServerTestSetup(Class testClass, String context) {
041: this (testClass, new TcConfigBuilder(), context);
042: }
043:
044: protected OneServerTestSetup(Class testClass,
045: String tcConfigFile, String context) {
046: this (testClass, new TcConfigBuilder(tcConfigFile), context);
047: }
048:
049: protected OneServerTestSetup(Class testClass,
050: TcConfigBuilder configBuilder, String context) {
051: super (testClass);
052: this .testClass = testClass;
053: this .context = context;
054: this .tcConfigBuilder = configBuilder;
055: }
056:
057: protected void setStart(boolean start) {
058: this .start = start;
059: }
060:
061: protected void setUp() throws Exception {
062: if (shouldDisable())
063: return;
064: super .setUp();
065: try {
066: getServerManager();
067:
068: long l1 = System.currentTimeMillis();
069: Deployment deployment = makeWAR();
070: long l2 = System.currentTimeMillis();
071: logger.info("### WAR build " + (l2 - l1) / 1000f
072: + " at " + deployment.getFileSystemPath());
073:
074: configureTcConfig(tcConfigBuilder);
075: server0 = createServer(deployment);
076:
077: TestSuite suite = (TestSuite) getTest();
078: for (int i = 0; i < suite.testCount(); i++) {
079: Test t = suite.testAt(i);
080: if (t instanceof AbstractOneServerDeploymentTest) {
081: AbstractOneServerDeploymentTest test = (AbstractOneServerDeploymentTest) t;
082: test.setServer0(server0);
083: }
084: }
085: } catch (Exception e) {
086: e.printStackTrace();
087: throw e;
088: }
089: }
090:
091: private WebApplicationServer createServer(Deployment deployment)
092: throws Exception {
093: WebApplicationServer server = getServerManager()
094: .makeWebApplicationServer(tcConfigBuilder);
095: server.addWarDeployment(deployment, context);
096: configureServerParamers(server.getServerParameters());
097: if (start) {
098: server.start();
099: }
100: return server;
101: }
102:
103: private Deployment makeWAR() throws Exception {
104: DeploymentBuilder builder = makeDeploymentBuilder(this .context
105: + ".war");
106: builder.addDirectoryOrJARContainingClass(testClass);
107: configureWar(builder);
108: return builder.makeDeployment();
109: }
110:
111: protected abstract void configureWar(DeploymentBuilder builder);
112:
113: protected void configureTcConfig(TcConfigBuilder clientConfig) {
114: // override this method to modify tc-config.xml
115: }
116:
117: protected void configureServerParamers(
118: StandardAppServerParameters params) {
119: // override this method to modify jvm args for app server
120: }
121: }
122:
123: }
|