1
2
3
4
5
6
7
8
9
10
11
12
13 package org.kuali.test;
14
15 import java.util.List;
16
17 import org.kuali.rice.core.lifecycle.BaseLifecycle;
18 import org.kuali.rice.core.lifecycle.Lifecycle;
19 import org.kuali.rice.kew.batch.KEWXmlDataLoaderLifecycle;
20 import org.kuali.rice.kns.service.KNSServiceLocator;
21 import org.kuali.rice.kns.util.GlobalVariables;
22 import org.kuali.rice.kns.util.MessageMap;
23 import org.kuali.rice.test.RiceInternalSuiteDataTestCase;
24 import org.kuali.rice.test.TransactionalLifecycle;
25 import org.kuali.rice.test.lifecycles.JettyServerLifecycle;
26 import org.kuali.rice.test.lifecycles.SQLDataLoaderLifecycle;
27 import org.kuali.rice.test.web.HtmlUnitUtil;
28
29
30
31
32
33
34
35 public abstract class KNSTestCase extends RiceInternalSuiteDataTestCase {
36
37 private static final String SQL_FILE = "classpath:org/kuali/rice/kns/test/DefaultSuiteTestData.sql";
38 private static final String XML_FILE = "classpath:org/kuali/rice/kns/test/DefaultSuiteTestData.xml";
39
40 private String contextName = "/knstest";
41 private String relativeWebappRoot = "/../kns/src/test/webapp";
42
43
44 private TransactionalLifecycle transactionalLifecycle;
45
46 @Override
47 protected void loadSuiteTestData() throws Exception {
48 super.loadSuiteTestData();
49 new SQLDataLoaderLifecycle(SQL_FILE, ";").start();
50 }
51
52 @Override
53 protected List<Lifecycle> getSuiteLifecycles() {
54 List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
55 suiteLifecycles.add(new KEWXmlDataLoaderLifecycle(XML_FILE));
56 return suiteLifecycles;
57 }
58
59 @Override
60 protected Lifecycle getLoadApplicationLifecycle() {
61 return new BaseLifecycle() {
62 public void start() throws Exception {
63 new JettyServerLifecycle(getPort(), getContextName(), getRelativeWebappRoot()).start();
64 super.start();
65 }
66 };
67 }
68
69 public void setUp() throws Exception {
70 super.setUp();
71 final boolean needsSpring = getClass().isAnnotationPresent(KNSWithTestSpringContext.class);
72 GlobalVariables.setMessageMap(new MessageMap());
73 if (needsSpring) {
74 transactionalLifecycle = new TransactionalLifecycle();
75 transactionalLifecycle.setTransactionManager(KNSServiceLocator.getTransactionManager());
76 transactionalLifecycle.start();
77 }
78 }
79
80 public void tearDown() throws Exception {
81 final boolean needsSpring = getClass().isAnnotationPresent(KNSWithTestSpringContext.class);
82 if (needsSpring) {
83 if ( (transactionalLifecycle != null) && (transactionalLifecycle.isStarted()) ) {
84 transactionalLifecycle.stop();
85 }
86 }
87 GlobalVariables.setMessageMap(new MessageMap());
88 super.tearDown();
89 }
90
91
92 @Override
93 protected String getModuleName() {
94 return "kns";
95 }
96
97 protected String getContextName() {
98 return contextName;
99 }
100
101 protected void setContextName(String contextName) {
102 this.contextName = contextName;
103 }
104
105 protected int getPort() {
106 return HtmlUnitUtil.getPort();
107 }
108
109 protected String getRelativeWebappRoot() {
110 return relativeWebappRoot;
111 }
112
113 protected void setRelativeWebappRoot(String relativeWebappRoot) {
114 this.relativeWebappRoot = relativeWebappRoot;
115 }
116
117 }