KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > framework > AbstractDeploymentTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.integrationtests.framework;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import com.tc.test.TCTestCase;
10 import com.tc.test.TestConfigObject;
11 import com.tc.test.server.tcconfig.StandardTerracottaAppServerConfig;
12
13 import java.io.IOException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
19
20 public abstract class AbstractDeploymentTest extends TCTestCase {
21
22   protected Log logger = LogFactory.getLog(getClass());
23
24   protected ServerManager serverManager;
25   private WatchDog watchDog;
26
27   Map JavaDoc disabledVariants = new HashMap JavaDoc();
28   List JavaDoc disabledJavaVersion = new ArrayList JavaDoc();
29
30   private static final int TIMEOUT_DEFAULT = 30 * 60;
31
32   protected void setUp() throws Exception JavaDoc {
33     super.setUp();
34     serverManager = ServerManagerUtil.start(getClass(), isWithPersistentStore());
35   }
36
37   public void runBare() throws Throwable JavaDoc {
38     watchDog = new WatchDog(getTimeout());
39     try {
40       watchDog.startWatching();
41       super.runBare();
42     } finally {
43       watchDog.stopWatching();
44     }
45   }
46
47   protected int getTimeout() throws IOException JavaDoc {
48     String JavaDoc timeout = TestConfigObject.getInstance().springTestsTimeout();
49     if (timeout == null) {
50       return TIMEOUT_DEFAULT;
51     } else {
52       return Integer.parseInt(timeout);
53     }
54   }
55
56   protected void tearDown() throws Exception JavaDoc {
57     ServerManagerUtil.stop(serverManager);
58     super.tearDown();
59   }
60
61   protected WebApplicationServer makeWebApplicationServer(String JavaDoc tcConfig) throws Exception JavaDoc {
62     return serverManager.makeWebApplicationServer(tcConfig);
63   }
64
65   protected WebApplicationServer makeWebApplicationServer(FileSystemPath tcConfigPath) throws Exception JavaDoc {
66     return serverManager.makeWebApplicationServer(tcConfigPath);
67   }
68
69   protected WebApplicationServer makeWebApplicationServer(StandardTerracottaAppServerConfig tcConfig) throws Exception JavaDoc {
70     return serverManager.makeWebApplicationServer(tcConfig);
71   }
72
73   protected void restartDSO() throws Exception JavaDoc {
74     serverManager.restartDSO(isWithPersistentStore());
75   }
76
77   protected DeploymentBuilder makeDeploymentBuilder(String JavaDoc warFileName) {
78     return serverManager.makeDeploymentBuilder(warFileName);
79   }
80
81 // XXX: This causes the bad war file name which breaks WLS tests
82
// protected DeploymentBuilder makeDeploymentBuilder() throws IOException {
83
// return serverManager.makeDeploymentBuilder();
84
// }
85

86   protected void waitForSuccess(int timeoutInSeconds, TestCallback callback) throws Throwable JavaDoc {
87     long startingTime = System.currentTimeMillis();
88     long timeout = timeoutInSeconds * 1000;
89     while (true) {
90       try {
91         logger.debug("checking");
92         callback.check();
93         logger.debug("check passed");
94         return;
95       } catch (Throwable JavaDoc e) {
96         logger.debug("check failed");
97         if ((System.currentTimeMillis() - startingTime) >= timeout) {
98           logger.debug("check timed out", e);
99           throw e;
100         }
101       }
102       logger.debug("check sleeping");
103       Thread.sleep(100L);
104     }
105   }
106
107   protected StandardTerracottaAppServerConfig getConfigBuilder() {
108     return serverManager.getConfig();
109   }
110
111   protected void stopAllWebServers() {
112     ServerManagerUtil.stopAllWebServers(serverManager);
113   }
114   
115   public boolean isWithPersistentStore() {
116     return false;
117   }
118   
119   protected void disableVariant(String JavaDoc variantName, String JavaDoc variantValue) {
120     List JavaDoc variantList = (List JavaDoc)disabledVariants.get(variantName);
121     if (variantList == null) {
122       variantList = new ArrayList JavaDoc();
123       disabledVariants.put(variantName, variantList);
124     }
125     variantList.add(variantValue);
126   }
127   
128   protected void disableForJavaVersion(String JavaDoc version) {
129     this.disabledJavaVersion.add(version);
130   }
131
132   void disableAllTests() {
133     this.disableAllUntil(new Date JavaDoc(Long.MAX_VALUE));
134   }
135 }
136
Popular Tags