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 KSKRMSUploadTestCase 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:KRMSUploadHarnessSpringBeans.xml";
53
54 public KSKRMSUploadTestCase() {
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 getLoadApplicationLifecycle();
67 termBoService = KrmsRepositoryServiceLocator.getTermBoService();
68 agendaBoService = KrmsRepositoryServiceLocator.getAgendaBoService();
69 contextRepository = KrmsRepositoryServiceLocator.getContextBoService();
70 ruleBoService = KrmsRepositoryServiceLocator.getRuleBoService();
71 krmsTypeRepository = KrmsRepositoryServiceLocator
72 .getKrmsTypeRepositoryService();
73 }
74
75 @Override
76 protected void loadSuiteTestData() throws Exception {
77
78 }
79
80 @Override
81 protected List<String> getPerTestTablesNotToClear() {
82 List<String> tablesNotToClear = super.getPerTestTablesNotToClear();
83
84 return tablesNotToClear;
85 }
86
87 @Override
88 protected Lifecycle getLoadApplicationLifecycle() {
89 if (krmsTestResourceLoader == null) {
90 List<String> files = new ArrayList<String>();
91 files.add(KRMS_TEST_SPRING_BEANS);
92 if (this.getAdditionalSpringFile() != null){
93 files.add(getAdditionalSpringFile());
94 }
95
96 krmsTestResourceLoader = new SpringResourceLoader(new QName(
97 "KRMSTestHarnessApplicationResourceLoader"), files, null);
98 krmsTestResourceLoader
99 .setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
100 getTestHarnessSpringResourceLoader().addResourceLoader(
101 krmsTestResourceLoader);
102 }
103 return krmsTestResourceLoader;
104 }
105
106 protected String getAdditionalSpringFile(){
107 return null;
108 }
109
110 protected BusinessObjectService getBoService() {
111 return KRADServiceLocator.getBusinessObjectService();
112 }
113
114
115
116
117
118
119
120
121
122
123
124 protected AgendaDefinition getKRMSAgenda(String agendaName, ContextDefinition contextDef) {
125 AgendaDefinition agendaDef = agendaBoService
126 .getAgendaByNameAndContextId(agendaName,
127 contextDef.getId());
128 return agendaDef;
129 }
130
131
132
133
134
135
136
137
138
139
140
141 protected ContextDefinition getKRMSContext(String context) {
142 return contextRepository.getContextByNameAndNamespace(
143 context, KSKRMSConstants.KSNAMESPACE);
144 }
145
146 protected TermDefinition krmsTermLookup(String termName) {
147
148 Map<String, String> queryArgs = new HashMap<String, String>();
149 queryArgs.put("desc_txt", termName);
150 TermBo termBo = getBoService()
151 .findByPrimaryKey(TermBo.class, queryArgs);
152 if (termBo != null) {
153 return TermBo.to(termBo);
154 }
155 return null;
156 }
157
158 protected TermResolverDefinition krmsTermResolverLookup(String termResolverName) {
159
160 Map<String, String> queryArgs = new HashMap<String, String>();
161 queryArgs.put("nm", termResolverName);
162 TermResolverBo termBo = getBoService()
163 .findByPrimaryKey(TermResolverBo.class, queryArgs);
164 if (termBo != null) {
165 return TermResolverBo.to(termBo);
166 }
167 return null;
168 }
169
170 }