1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.rice.student;
20
21 import java.io.BufferedReader;
22 import java.io.FileReader;
23 import java.util.List;
24
25 import javax.xml.namespace.QName;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.rice.core.lifecycle.BaseLifecycle;
29 import org.kuali.rice.core.lifecycle.Lifecycle;
30 import org.kuali.rice.core.resourceloader.SpringResourceLoader;
31 import org.kuali.rice.kew.batch.KEWXmlDataLoader;
32 import org.kuali.rice.kew.exception.WorkflowRuntimeException;
33 import org.kuali.rice.kim.service.KIMServiceLocator;
34 import org.kuali.rice.test.BaselineTestCase;
35 import org.kuali.rice.test.SQLDataLoader;
36
37
38
39
40
41 public class StudentStandaloneTestBase extends BaselineTestCase {
42
43 private static final String MODULE_NAME = "standalone";
44
45 public StudentStandaloneTestBase() {
46 super(MODULE_NAME);
47 }
48
49
50
51
52 @Override
53 protected Lifecycle getLoadApplicationLifecycle() {
54 SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("StudentStandaloneTestResourceLoader"), "classpath:StandaloneTestSpringBeans.xml");
55 springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
56 return springResourceLoader;
57 }
58
59
60
61
62
63 @Override
64 protected List<Lifecycle> getPerTestLifecycles() {
65 List<Lifecycle> lifecycles = super.getPerTestLifecycles();
66
67
68 lifecycles.add(new ClearCacheLifecycle());
69 return lifecycles;
70 }
71
72 public class ClearCacheLifecycle extends BaseLifecycle {
73 public void stop() throws Exception {
74 KIMServiceLocator.getIdentityManagementService().flushAllCaches();
75 KIMServiceLocator.getRoleManagementService().flushRoleCaches();
76 super.stop();
77 }
78 }
79
80
81 @Override
82 protected void loadSuiteTestData() throws Exception {
83 new SQLDataLoader(getKNSDefaultSuiteTestData(), "/").runSql();
84 BufferedReader reader = new BufferedReader(new FileReader(getKIMDataLoadOrderFile()));
85 String line = null;
86 while ((line = reader.readLine()) != null) {
87 if (!StringUtils.isBlank(line)) {
88 new SQLDataLoader(getKIMSqlFileBaseLocation() + "/" + line, "/").runSql();
89 }
90 }
91 new SQLDataLoader("file:" + getBaseDir() + "/../src/main/config/sql/kim.sql", ";").runSql();
92 }
93
94 protected String getKNSDefaultSuiteTestData() {
95 return "file:" + getBaseDir() + "/../src/test/config/data/DefaultSuiteTestDataKNS.sql";
96 }
97
98 protected String getKIMDataLoadOrderFile() {
99 return getBaseDir() + "/../src/test/config/data/KIMDataLoadOrder.txt";
100 }
101
102 protected String getKIMSqlFileBaseLocation() {
103 return "file:" + getBaseDir() + "/../src/test/config/data";
104 }
105
106 protected void loadXmlFile(String fileName) {
107 try {
108 KEWXmlDataLoader.loadXmlClassLoaderResource(getClass(), fileName);
109 } catch (Exception e) {
110 throw new WorkflowRuntimeException(e);
111 }
112 }
113
114 protected void loadXmlFileFromFileSystem(String fileName) {
115 try {
116 KEWXmlDataLoader.loadXmlFile(fileName);
117 } catch (Exception e) {
118 throw new WorkflowRuntimeException(e);
119 }
120 }
121
122 }