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.apache.log4j.Logger;
20 import org.kuali.rice.core.api.lifecycle.Lifecycle;
21 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
22 import org.kuali.rice.krad.datadictionary.DataDictionary;
23 import org.kuali.rice.test.BaselineTestCase;
24 import org.kuali.rice.test.SQLDataLoader;
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 private static final String SQL_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.sql";
42 private static final String XML_FILE = "classpath:org/kuali/rice/krad/test/DefaultSuiteTestData.xml";
43 private static final String KRAD_MODULE_NAME = "krad";
44
45 protected DataDictionary dd;
46
47 public KRADTestCase() {
48 super(KRAD_MODULE_NAME);
49 }
50
51
52
53
54
55 public KRADTestCase(String moduleName) {
56 super(moduleName);
57 }
58
59 @Override
60 protected void setUpInternal() throws Exception {
61 super.setUpInternal();
62
63 List<Class> classes = TestUtilities.getHierarchyClassesToHandle(getClass(),
64 new Class[]{TestDictionaryConfig.class}, new HashSet<String>());
65
66
67 if (!classes.isEmpty()) {
68 ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("TestDataDictionary.xml");
69 dd = (DataDictionary) context.getBean("testDataDictionary");
70
71
72 for (Class c : classes) {
73 if (c.isAnnotationPresent(TestDictionaryConfig.class)) {
74 TestDictionaryConfig testDictionaryConfig = (TestDictionaryConfig) c.getAnnotation(
75 TestDictionaryConfig.class);
76
77 String namespaceCode = testDictionaryConfig.namespaceCode();
78 String dictionaryFileString = testDictionaryConfig.dataDictionaryFiles();
79
80 String[] dictionaryFiles = StringUtils.split(dictionaryFileString, ",");
81 for (String dictionaryFile : dictionaryFiles) {
82 LOG.info("Adding test data dictionary file: " + dictionaryFile);
83
84 dd.addConfigFileLocation(namespaceCode, dictionaryFile);
85 }
86 }
87 }
88
89 dd.parseDataDictionaryConfigurationFiles(true);
90 }
91 }
92
93
94
95
96
97
98
99 protected Object getTestDictionaryObject(String id) {
100 if (dd != null) {
101 return dd.getDictionaryObject(id);
102 }
103
104 return null;
105 }
106
107 @Override
108 protected List<Lifecycle> getSuiteLifecycles() {
109 List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
110 suiteLifecycles.add(new KEWXmlDataLoaderLifecycle(XML_FILE));
111
112 return suiteLifecycles;
113 }
114
115 @Override
116 protected void loadSuiteTestData() throws Exception {
117 super.loadSuiteTestData();
118 new SQLDataLoader(SQL_FILE, ";").runSql();
119 }
120
121 @Override
122 protected Lifecycle getLoadApplicationLifecycle() {
123 SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("KRADTestResourceLoader"),
124 "classpath:KRADTestSpringBeans.xml", null);
125 springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
126 return springResourceLoader;
127 }
128 }