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 import org.springframework.context.ConfigurableApplicationContext;
28 import org.springframework.context.support.ClassPathXmlApplicationContext;
29
30 import javax.xml.namespace.QName;
31 import java.util.HashSet;
32 import java.util.List;
33
34
35
36
37
38
39 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
40 public abstract class KRADTestCase extends BaselineTestCase {
41
42 private static final String SQL_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.sql";
43 private static final String XML_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.xml";
44 private static final String KRAD_MODULE_NAME = "krad";
45
46 protected DataDictionary dd;
47
48 public KRADTestCase() {
49 super(KRAD_MODULE_NAME);
50 }
51
52
53
54
55
56 public KRADTestCase(String moduleName) {
57 super(moduleName);
58 }
59
60 @Override
61 protected void setUpInternal() throws Exception {
62 super.setUpInternal();
63
64 List<Class> classes = TestUtilities.getHierarchyClassesToHandle(getClass(),
65 new Class[]{TestDictionaryConfig.class}, new HashSet<String>());
66
67
68 if (!classes.isEmpty()) {
69 ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("TestDataDictionary.xml");
70 dd = (DataDictionary) context.getBean("testDataDictionary");
71
72
73 for (Class c : classes) {
74 if (c.isAnnotationPresent(TestDictionaryConfig.class)) {
75 TestDictionaryConfig testDictionaryConfig = (TestDictionaryConfig) c.getAnnotation(
76 TestDictionaryConfig.class);
77
78 String dictionaryFileString = testDictionaryConfig.dataDictionaryFiles();
79 String[] dictionaryFiles = StringUtils.split(dictionaryFileString, ",");
80 for (String dictionaryFile : dictionaryFiles) {
81 dd.addConfigFileLocation(dictionaryFile);
82 }
83 }
84 }
85
86 dd.parseDataDictionaryConfigurationFiles(true);
87 }
88 }
89
90
91
92
93
94
95
96 protected Object getTestDictionaryObject(String id) {
97 if (dd != null) {
98 return dd.getDictionaryObject(id);
99 }
100
101 return null;
102 }
103
104 @Override
105 protected List<Lifecycle> getSuiteLifecycles() {
106 List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
107 suiteLifecycles.add(new KEWXmlDataLoaderLifecycle(XML_FILE));
108
109 return suiteLifecycles;
110 }
111
112 @Override
113 protected void loadSuiteTestData() throws Exception {
114 super.loadSuiteTestData();
115 new SQLDataLoader(SQL_FILE, ";").runSql();
116 }
117
118 @Override
119 protected Lifecycle getLoadApplicationLifecycle() {
120 SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("KRADTestResourceLoader"),
121 "classpath:KRADTestSpringBeans.xml", null);
122 springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
123 return springResourceLoader;
124 }
125 }