1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.krms;
17
18 import org.kuali.rice.core.api.lifecycle.Lifecycle;
19 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
20 import org.kuali.rice.krad.service.BusinessObjectService;
21 import org.kuali.rice.krad.service.KRADServiceLocator;
22 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
23 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
24 import org.kuali.rice.krms.api.repository.term.TermDefinition;
25 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
26 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
27 import org.kuali.rice.krms.impl.repository.*;
28 import org.kuali.rice.test.BaselineTestCase;
29 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
30 import org.kuali.rice.test.BaselineTestCase.Mode;
31
32 import javax.xml.namespace.QName;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38 @BaselineMode(Mode.NONE)
39 public class KSKRMSTestCase extends BaselineTestCase {
40
41 private static final String KRMS_MODULE_NAME = "krms";
42
43 protected ContextBoService contextRepository;
44 protected KrmsTypeRepositoryService krmsTypeRepository;
45 protected AgendaBoService agendaBoService;
46 protected RuleBoService ruleBoService;
47
48
49 protected TermBoService termBoService;
50 protected SpringResourceLoader krmsTestResourceLoader;
51
52 private static String KRMS_TEST_SPRING_BEANS = "classpath:KRMSTestHarnessSpringBeans.xml";
53
54 public KSKRMSTestCase() {
55 super(KRMS_MODULE_NAME);
56 this.setClearTables(false);
57 }
58
59
60
61
62
63 @Override
64 public void setUp() throws Exception {
65 super.setUp();
66 termBoService = KrmsRepositoryServiceLocator.getTermBoService();
67 agendaBoService = KrmsRepositoryServiceLocator.getAgendaBoService();
68 contextRepository = KrmsRepositoryServiceLocator.getContextBoService();
69 ruleBoService = KrmsRepositoryServiceLocator.getRuleBoService();
70 krmsTypeRepository = KrmsRepositoryServiceLocator
71 .getKrmsTypeRepositoryService();
72 }
73
74 @Override
75 protected List<String> getPerTestTablesNotToClear() {
76 List<String> tablesNotToClear = super.getPerTestTablesNotToClear();
77
78 return tablesNotToClear;
79 }
80
81 @Override
82 protected Lifecycle getLoadApplicationLifecycle() {
83 if (krmsTestResourceLoader == null) {
84 List<String> files = new ArrayList<String>();
85 files.add(KRMS_TEST_SPRING_BEANS);
86 if (this.getAdditionalSpringFile() != null){
87 files.add(getAdditionalSpringFile());
88 }
89
90 krmsTestResourceLoader = new SpringResourceLoader(new QName(
91 "KRMSTestHarnessApplicationResourceLoader"), files, null);
92 krmsTestResourceLoader
93 .setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
94 getTestHarnessSpringResourceLoader().addResourceLoader(
95 krmsTestResourceLoader);
96 }
97 return krmsTestResourceLoader;
98 }
99
100 protected String getAdditionalSpringFile(){
101 return null;
102 }
103
104 protected BusinessObjectService getBoService() {
105 return KRADServiceLocator.getBusinessObjectService();
106 }
107
108
109
110
111
112
113
114
115
116
117
118 protected AgendaDefinition getKRMSAgenda(String agendaName, ContextDefinition contextDef) {
119 AgendaDefinition agendaDef = agendaBoService
120 .getAgendaByNameAndContextId(agendaName,
121 contextDef.getId());
122 return agendaDef;
123 }
124
125
126
127
128
129
130
131
132
133
134
135 protected ContextDefinition getKRMSContext(String context) {
136 return contextRepository.getContextByNameAndNamespace(
137 context, KSKRMSConstants.KSNAMESPACE);
138 }
139
140 protected TermDefinition krmsTermLookup(String termName) {
141
142 Map<String, String> queryArgs = new HashMap<String, String>();
143 queryArgs.put("desc_txt", termName);
144 TermBo termBo = getBoService()
145 .findByPrimaryKey(TermBo.class, queryArgs);
146 if (termBo != null) {
147 return TermBo.to(termBo);
148 }
149 return null;
150 }
151
152 protected TermResolverDefinition krmsTermResolverLookup(String termResolverName) {
153
154 Map<String, String> queryArgs = new HashMap<String, String>();
155 queryArgs.put("nm", termResolverName);
156 TermResolverBo termBo = getBoService()
157 .findByPrimaryKey(TermResolverBo.class, queryArgs);
158 if (termBo != null) {
159 return TermResolverBo.to(termBo);
160 }
161 return null;
162 }
163
164 }