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