1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.test;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.lifecycle.Lifecycle;
20 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
21 import org.kuali.rice.krad.datadictionary.DataDictionary;
22 import org.kuali.rice.test.BaselineTestCase;
23 import org.kuali.rice.test.SQLDataLoader;
24 import org.kuali.rice.test.TestHarnessServiceLocator;
25 import org.kuali.rice.test.TestUtilities;
26 import org.kuali.rice.test.lifecycles.KEWXmlDataLoaderLifecycle;
27
28 import javax.xml.namespace.QName;
29 import java.util.HashSet;
30 import java.util.List;
31
32
33
34
35
36
37 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
38 public abstract class KRADTestCase extends BaselineTestCase {
39
40 private static final String SQL_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.sql";
41 private static final String XML_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.xml";
42 private static final String KRAD_MODULE_NAME = "krad";
43
44 private SpringResourceLoader kradTestSpringResourceLoader;
45
46 protected DataDictionary dd = null;
47
48 public KRADTestCase() {
49 super(KRAD_MODULE_NAME);
50 }
51
52 @Override
53 protected void setUpInternal() throws Exception {
54 super.setUpInternal();
55
56 List<Class> classes = TestUtilities.getHierarchyClassesToHandle(getClass(),
57 new Class[]{TestDictionaryConfig.class}, new HashSet<String>());
58
59
60 if (!classes.isEmpty()) {
61 dd = (DataDictionary) kradTestSpringResourceLoader.getContext().getBean("testDataDictionary");
62
63
64 for (Class c : classes) {
65 if (c.isAnnotationPresent(TestDictionaryConfig.class)) {
66 TestDictionaryConfig testDictionaryConfig = (TestDictionaryConfig) c.getAnnotation(
67 TestDictionaryConfig.class);
68
69 String dictionaryFileString = testDictionaryConfig.dataDictionaryFiles();
70 String[] dictionaryFiles = StringUtils.split(dictionaryFileString, ",");
71 for (String dictionaryFile : dictionaryFiles) {
72 dd.addConfigFileLocation(dictionaryFile);
73 }
74 }
75 }
76
77 dd.parseDataDictionaryConfigurationFiles(true);
78 }
79 }
80
81
82
83
84
85
86
87 protected Object getTestDictionaryObject(String id) {
88 if (dd != null) {
89 return dd.getDictionaryObject(id);
90 }
91
92 return null;
93 }
94
95 @Override
96 protected List<Lifecycle> getSuiteLifecycles() {
97 List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
98 suiteLifecycles.add(new KEWXmlDataLoaderLifecycle(XML_FILE));
99 return suiteLifecycles;
100 }
101
102 @Override
103 protected void loadSuiteTestData() throws Exception {
104 super.loadSuiteTestData();
105 new SQLDataLoader(SQL_FILE, ";").runSql();
106 }
107
108 @Override
109 protected Lifecycle getLoadApplicationLifecycle() {
110 return getKRADTestSpringResourceLoader();
111 }
112
113 public SpringResourceLoader getKRADTestSpringResourceLoader() {
114 if (kradTestSpringResourceLoader == null) {
115 kradTestSpringResourceLoader = new SpringResourceLoader(new QName("KRADTestResourceLoader"),
116 "classpath:KRADTestSpringBeans.xml", null);
117 }
118 return kradTestSpringResourceLoader;
119 }
120 }