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.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.lifecycle.Lifecycle;
21 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
22 import org.kuali.rice.krad.service.BusinessObjectService;
23 import org.kuali.rice.krad.service.KRADServiceLocator;
24 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
25 import org.kuali.rice.krms.api.repository.term.TermDefinition;
26 import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
27 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
28 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
29 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition.Builder;
30 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
31 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
32 import org.kuali.rice.krms.impl.repository.*;
33 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
34 import org.kuali.rice.test.BaselineTestCase.Mode;
35
36 import javax.xml.namespace.QName;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 import static org.junit.Assert.assertNotNull;
43
44 public class TestKRMSCreateTermSpecificationPhase2 extends KSKRMSUploadTestCase {
45
46 public TestKRMSCreateTermSpecificationPhase2() {
47 super();
48 this.setClearTables(false);
49 }
50
51 static final String KSNAMESPACE = "KR-RULE-TEST";
52 protected ContextBoService contextRepository;
53 protected KrmsTypeRepositoryService krmsTypeRepository;
54 private AgendaBoService agendaBoService;
55 private RuleBoService ruleBoService;
56 private FunctionBoServiceImpl functionBoService;
57
58
59 private TermBoService termBoService;
60 private SpringResourceLoader krmsTestResourceLoader;
61
62 Map<String, ContextDefinition> phase1ContextDefs = new HashMap<String, ContextDefinition>();
63 KrmsTypeDefinition krmsTypeDefinition;
64 ContextDefinition contextStudElig;
65 static final String AGENDA1 = "Must have successfully completed <course>";
66 static final String EARTHQUAKE_EVENT = "Earthquake";
67 public static final String CAMPUS_CODE_TERM_NAME = "campusCodeTermSpec";
68 static final String BOOL1 = "bool1";
69 static final String BOOL2 = "bool2";
70 static final String PREREQ_TERM_NAME = "prereqTermSpec";
71
72
73 @Before
74 public void setup() {
75 getLoadApplicationLifecycle();
76 termBoService = KrmsRepositoryServiceLocator.getTermBoService();
77 agendaBoService = KrmsRepositoryServiceLocator.getAgendaBoService();
78 contextRepository = KrmsRepositoryServiceLocator.getContextBoService();
79 ruleBoService = KrmsRepositoryServiceLocator.getRuleBoService();
80 krmsTypeRepository = KrmsRepositoryServiceLocator
81 .getKrmsTypeRepositoryService();
82 functionBoService = KrmsRepositoryServiceLocator.getBean("functionRepositoryService");
83
84 }
85
86 @Override
87 protected void loadSuiteTestData() throws Exception {
88
89 }
90
91 @Override
92 protected List<String> getPerTestTablesNotToClear() {
93 List<String> tablesNotToClear = super.getPerTestTablesNotToClear();
94
95 return tablesNotToClear;
96 }
97
98 @Override
99 protected Lifecycle getLoadApplicationLifecycle() {
100 if (krmsTestResourceLoader == null) {
101 krmsTestResourceLoader = new SpringResourceLoader(new QName(
102 "KRMSTestHarnessApplicationResourceLoader"),
103 "classpath:KRMSTestHarnessSpringBeans.xml", null);
104 krmsTestResourceLoader
105 .setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
106 getTestHarnessSpringResourceLoader().addResourceLoader(
107 krmsTestResourceLoader);
108 }
109 return krmsTestResourceLoader;
110 }
111
112 @Test
113 public void createAllKRMSTermSpecificationsPhase1() {
114 String nameSpace = KSNAMESPACE;
115
116
117
118
119
120
121
122
123
124 }
125
126 private TermSpecificationDefinition createKRMSTermSpecification(
127 String nameSpace, String termSpecName, String descr, String termType) {
128 Map<String, String> queryArgs = new HashMap<String, String>();
129 queryArgs.put("namespace", nameSpace);
130 queryArgs.put("name", termSpecName);
131 TermSpecificationBo termSpecBo = getBoService().findByPrimaryKey(
132 TermSpecificationBo.class, queryArgs);
133
134
135 TermSpecificationDefinition termSpec = null;
136 if (termSpecBo == null) {
137
138 Builder termSpecDefBuilder = TermSpecificationDefinition.Builder
139 .create(null, termSpecName, nameSpace, termType);
140 termSpecDefBuilder.setDescription(descr);
141
142 termSpec = termSpecDefBuilder.build();
143
144
145 termSpec = termBoService.createTermSpecification(termSpec);
146
147 } else {
148 termSpec = termSpecBo.to(termSpecBo);
149 }
150 return termSpec;
151 }
152
153 @Test
154 public void createAllKRMSTermDefinitions() {
155 String nameSpace = KSNAMESPACE;
156
157
158
159 List<TermParameterDefinition.Builder> termParameters = new ArrayList<TermParameterDefinition.Builder>();
160
161 setupTermParameters(termParameters, KSKRMSConstants.ORG_ID_TERM_PROPERTY, "???termParameterValue");
162 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_ORG_NUMBER,
163 KSKRMSConstants.TERM_DEPT_NUMBER, null);
164
165 termParameters.clear();
166 setupTermParameters(termParameters, KSKRMSConstants.ORG_KEY_TYPE_TERM_PROPERTY, "???termParameterValue");
167 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_ORG_NUMBER,
168 KSKRMSConstants.TERM_ADMIN_ORG_NUMBER, null);
169
170 termParameters.clear();
171 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
172 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
173 KSKRMSConstants.TERM_COMPLETED_COURSE_NUMBER, termParameters);
174
175 termParameters.clear();
176 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
177 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
178 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, termParameters);
179
180 termParameters.clear();
181 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
182 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
183 KSKRMSConstants.TERM_COMPLETED_COURSE_SET, termParameters);
184
185 termParameters.clear();
186 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
187 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
188 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_FROM, termParameters);
189
190 termParameters.clear();
191 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
192 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
193 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_TO, termParameters);
194
195 termParameters.clear();
196 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
197 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
198 KSKRMSConstants.TERM_COMPLETED_LEARNING_OBJ_DESCR, termParameters);
199
200 termParameters.clear();
201 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
202 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
203 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
204 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_RANGE, termParameters);
205
206 termParameters.clear();
207 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
208 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
209 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
210 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_SUBJECT_CODE, termParameters);
211
212 termParameters.clear();
213 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
214 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
215 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
216 KSKRMSConstants.TERM_ENROLLED_SET, termParameters);
217
218 termParameters.clear();
219 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
220 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
221 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
222 KSKRMSConstants.TERM_ENROLLED_COURSE, termParameters);
223
224 termParameters.clear();
225 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
226 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
227 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
228 KSKRMSConstants.TERM_ENROLLED_COURSES, termParameters);
229
230 termParameters.clear();
231 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
232 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
233 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
234 KSKRMSConstants.TERM_ENROLLED_EFFECTIVE_DATE_FROM, termParameters);
235
236 termParameters.clear();
237 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
238 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
239 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
240 KSKRMSConstants.TERM_ENROLLED_EFFECTIVE_DATE_TO, termParameters);
241
242 termParameters.clear();
243 setupTermParameters(termParameters, KSKRMSConstants.PERSON_ID_TERM_PROPERTY, "???termParameterValue");
244 setupTermParameters(termParameters, KSKRMSConstants.TERM_ID_TERM_PROPERTY, "???termParameterValue");
245 createKRMSTermDefinition(nameSpace, KSKRMSConstants.TERM_SPEC_COURSE,
246 KSKRMSConstants.TERM_ENROLLED_LEARNING_OBJ_DESCR, termParameters);
247
248
249
250
251
252
253
254 }
255
256 private void setupTermParameters(
257 List<TermParameterDefinition.Builder> termParameters, String termParamName, String termParamValue) {
258 TermParameterDefinition.Builder termParamBuilder2 =
259 TermParameterDefinition.Builder.create(null, null, termParamName, termParamValue);
260 termParameters.add(termParamBuilder2);
261 }
262
263 private void createKRMSTermDefinition(String nameSpace,
264 String termSpecName, String termName, List<TermParameterDefinition.Builder> termParameters) {
265
266 Map<String, String> queryArgs = new HashMap<String, String>();
267 queryArgs.put("namespace", nameSpace);
268 queryArgs.put("name", termSpecName);
269 String a = queryArgs.get("name");
270 TermSpecificationBo termSpecBo = getBoService().findByPrimaryKey(
271 TermSpecificationBo.class, queryArgs);
272
273 TermSpecificationDefinition termSpec = null;
274
275 termSpec = termSpecBo.to(termSpecBo);
276
277 Builder termSpecDefBuilder = TermSpecificationDefinition.Builder
278 .create(termSpec);
279
280
281
282
283
284
285 TermDefinition.Builder termDefBuilder = TermDefinition.Builder.create(
286 null, termSpecDefBuilder, termParameters);
287
288 termDefBuilder.setDescription(termName);
289
290 TermDefinition termDefinition = termDefBuilder.build();
291
292 termDefinition = termBoService.createTerm(termDefinition);
293
294 }
295
296 private KrmsTypeDefinition getKSKRMSType(String nameSpace, String typeName, String typeServiceName) {
297 KrmsTypeDefinition krmsAgendaType = krmsTypeRepository
298 .getTypeByName(nameSpace, typeName);
299
300 if (krmsAgendaType == null) {
301
302 KrmsTypeDefinition.Builder krmsAgendaTypeDefinition = KrmsTypeDefinition.Builder
303 .create(typeName, nameSpace);
304 krmsAgendaTypeDefinition.setServiceName(typeServiceName);
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321 krmsAgendaType = krmsTypeRepository
322 .createKrmsType(krmsAgendaTypeDefinition.build());
323 return krmsAgendaType;
324 }
325
326 return krmsAgendaType;
327 }
328
329
330 public void TestCreateType() {
331 getKSKRMSType(KSNAMESPACE, KSKRMSConstants.KS_AGENDA_TYPE, "testAgendaTypeService");
332 }
333
334 protected BusinessObjectService getBoService() {
335 return KRADServiceLocator.getBusinessObjectService();
336 }
337
338 public TermDefinition krmsTermLookup(String termName) {
339
340 Map<String, String> queryArgs = new HashMap<String, String>();
341 queryArgs.put("desc_txt", termName);
342 TermBo termBo = getBoService()
343 .findByPrimaryKey(TermBo.class, queryArgs);
344 if (termBo != null) {
345 return TermBo.to(termBo);
346 }
347 return null;
348 }
349
350
351 public void testTermLookup() {
352
353 TermDefinition term = krmsTermLookup(KSKRMSConstants.TERM_APPROVED_COURSE);
354 assertNotNull(term);
355 }
356
357 public void createKRMSTermResolver(String termResolverName, TermSpecificationDefinition termSpecDefinition) {
358
359 KrmsTypeDefinition krmsTermResolverTypeDefinition = getKSKRMSType(KSKRMSConstants.KSNAMESPACE, KSKRMSConstants.KS_TERM_RESOLVER_TYPE, "ksKRMSTermResolverTypeService");
360
361
362 TermResolverDefinition termResolverDef =
363 TermResolverDefinition.Builder.create(null, KSKRMSConstants.KSNAMESPACE, termResolverName, krmsTermResolverTypeDefinition.getId(),
364 TermSpecificationDefinition.Builder.create(termSpecDefinition),
365 null,
366 null,
367 null).build();
368 termResolverDef = termBoService.createTermResolver(termResolverDef);
369 }
370
371 }