1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.test;
17
18 import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
19 import org.kuali.rice.core.api.lifecycle.Lifecycle;
20 import org.kuali.rice.core.framework.resourceloader.RiceResourceLoaderFactory;
21 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
22 import org.kuali.rice.ken.core.SpringNotificationServiceLocator;
23 import org.kuali.rice.kew.batch.KEWXmlDataLoader;
24 import org.kuali.rice.test.BaselineTestCase;
25 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26 import org.kuali.rice.test.BaselineTestCase.Mode;
27 import org.kuali.rice.test.CompositeBeanFactory;
28 import org.kuali.rice.test.SQLDataLoader;
29 import org.kuali.rice.test.lifecycles.KEWXmlDataLoaderLifecycle;
30 import org.kuali.rice.test.lifecycles.SQLDataLoaderLifecycle;
31 import org.quartz.Scheduler;
32 import org.quartz.SchedulerException;
33 import org.springframework.beans.factory.BeanFactory;
34 import org.springframework.transaction.PlatformTransactionManager;
35
36 import javax.xml.namespace.QName;
37 import java.util.ArrayList;
38 import java.util.List;
39
40
41
42
43
44
45 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
46 public abstract class KENTestCase extends BaselineTestCase {
47 private static final String KEN_MODULE_NAME = "ken";
48 private static final String TX_MGR_BEAN_NAME = "transactionManager";
49
50 protected SpringNotificationServiceLocator services;
51 protected PlatformTransactionManager transactionManager;
52
53 public KENTestCase() {
54 super(KEN_MODULE_NAME);
55 }
56
57
58
59 @Override
60 protected List<Lifecycle> getSuiteLifecycles() {
61 List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
62 suiteLifecycles.add(new KEWXmlDataLoaderLifecycle("classpath:org/kuali/rice/ken/test/DefaultSuiteTestData.xml"));
63 return suiteLifecycles;
64 }
65
66 @Override
67 protected Lifecycle getLoadApplicationLifecycle() {
68 SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("KENTestHarnessApplicationResourceLoader"), "classpath:KENTestHarnessSpringBeans.xml", null);
69 springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
70 return springResourceLoader;
71 }
72
73 @Override
74 protected List<Lifecycle> getPerTestLifecycles() {
75 List<Lifecycle> lifecycles = super.getPerTestLifecycles();
76 lifecycles.add(new ClearCacheLifecycle());
77 lifecycles.addAll(getNotificationPerTestLifecycles());
78 return lifecycles;
79 }
80
81 protected List<Lifecycle> getNotificationPerTestLifecycles() {
82 List<Lifecycle> lifecycles = new ArrayList<Lifecycle>();
83 lifecycles.add(new BaseLifecycle() {
84 @Override
85 public void start() throws Exception {
86
87 BeanFactory moduleContext = CompositeBeanFactory.createBeanFactory(
88 RiceResourceLoaderFactory.getSpringResourceLoaders());
89
90 services = new SpringNotificationServiceLocator(moduleContext);
91
92 transactionManager = (PlatformTransactionManager) moduleContext.getBean(TX_MGR_BEAN_NAME, PlatformTransactionManager.class);
93 super.start();
94 }
95
96 });
97
98
99 lifecycles.add(new BaseLifecycle() {
100 @Override
101 public void start() throws Exception {
102 super.start();
103
104 LOG.info("Status of Ken scheduler on start: " + (services.getScheduler().isStarted() ? "started" : "stopped"));
105
106 disableQuartzJobs();
107 }
108 public void stop() throws Exception {
109
110
111 LOG.info("Status of Ken scheduler on stop: " + (services.getScheduler().isStarted() ? "started" : "stopped"));
112
113 disableQuartzJobs();
114
115 super.stop();
116 }
117 });
118
119
120
121
122
123
124
125 return lifecycles;
126
127 }
128
129
130
131
132
133
134 protected void loadDefaultTestData() throws Exception {
135
136
137
138 new SQLDataLoader(
139 "classpath:org/kuali/rice/ken/test/DefaultPerTestData.sql", ";")
140 .runSql();
141
142 KEWXmlDataLoader.loadXmlClassLoaderResource(KENTestCase.class, "DefaultPerTestData.xml");
143 }
144
145
146
147 @Override
148 protected List<String> getPerTestTablesToClear() {
149 List<String> tablesToClear = new ArrayList<String>();
150 tablesToClear.add("KREW_.*");
151 tablesToClear.add("KRSB_.*");
152 tablesToClear.add("KREN_.*");
153 return tablesToClear;
154 }
155
156 protected void setUpAfterDataLoad() throws Exception {
157
158 }
159
160
161
162
163 @Override
164 protected void loadPerTestData() throws Exception {
165 loadDefaultTestData();
166
167
168 setUpAfterDataLoad();
169
170 final long t4 = System.currentTimeMillis();
171 }
172
173
174
175
176 public class ClearCacheLifecycle extends BaseLifecycle {
177 @Override
178 public void stop() throws Exception {
179
180
181
182 super.stop();
183 }
184
185 }
186
187
188
189
190 protected void disableQuartzJobs() throws SchedulerException {
191
192
193 Scheduler scheduler = services.getScheduler();
194 scheduler.standby();
195
196 }
197
198
199
200
201
202 protected void enableQuartzJobs() throws SchedulerException {
203
204
205 Scheduler scheduler = services.getScheduler();
206 scheduler.start();
207 }
208
209 }