01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.test.server.appserver.deployment;
06:
07: import java.io.IOException;
08: import java.util.Enumeration;
09:
10: import junit.extensions.TestSetup;
11: import junit.framework.TestSuite;
12:
13: public class ServerTestSetup extends TestSetup {
14:
15: private final Class testClass;
16: private ServerManager sm;
17: protected boolean persistentMode = false;
18:
19: public ServerTestSetup(Class testClass) {
20: super (new TestSuite(testClass));
21: this .testClass = testClass;
22: }
23:
24: public ServerTestSetup(Class testClass, boolean persistentMode) {
25: this (testClass);
26: this .persistentMode = persistentMode;
27: }
28:
29: protected void setUp() throws Exception {
30: super .setUp();
31: getServerManager();
32: }
33:
34: protected void tearDown() throws Exception {
35: if (sm != null) {
36: ServerManagerUtil.stopAndRelease(sm);
37: }
38: }
39:
40: protected ServerManager getServerManager() {
41: if (sm == null) {
42: try {
43: sm = ServerManagerUtil.startAndBind(testClass,
44: isWithPersistentStore());
45: } catch (Exception e) {
46: throw new RuntimeException(
47: "Unable to create server manager", e);
48: }
49: }
50: return sm;
51: }
52:
53: public DeploymentBuilder makeDeploymentBuilder() throws IOException {
54: return getServerManager().makeDeploymentBuilder();
55: }
56:
57: public DeploymentBuilder makeDeploymentBuilder(String warFileName) {
58: return getServerManager().makeDeploymentBuilder(warFileName);
59: }
60:
61: public boolean isWithPersistentStore() {
62: return persistentMode;
63: }
64:
65: public boolean shouldDisable() {
66: for (Enumeration e = ((TestSuite) fTest).tests(); e
67: .hasMoreElements();) {
68: Object o = e.nextElement();
69: if (o instanceof AbstractDeploymentTest
70: && ((AbstractDeploymentTest) o).shouldDisable()) {
71: return true;
72: }
73: }
74: return false;
75: }
76: }
|