1 package org.kuali.student.lum.statement.config.context;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
13 import org.kuali.student.common.dto.StatusInfo;
14 import org.kuali.student.common.exceptions.AlreadyExistsException;
15 import org.kuali.student.common.exceptions.DataValidationErrorException;
16 import org.kuali.student.common.exceptions.DoesNotExistException;
17 import org.kuali.student.common.exceptions.InvalidParameterException;
18 import org.kuali.student.common.exceptions.MissingParameterException;
19 import org.kuali.student.common.exceptions.OperationFailedException;
20 import org.kuali.student.common.exceptions.PermissionDeniedException;
21 import org.kuali.student.common.exceptions.VersionMismatchException;
22 import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
23 import org.kuali.student.common.search.dto.SearchRequest;
24 import org.kuali.student.common.search.dto.SearchResult;
25 import org.kuali.student.common.search.dto.SearchResultTypeInfo;
26 import org.kuali.student.common.search.dto.SearchTypeInfo;
27 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
28 import org.kuali.student.core.statement.dto.ReqComponentInfo;
29 import org.kuali.student.lum.lrc.dto.CredentialInfo;
30 import org.kuali.student.lum.lrc.dto.CredentialTypeInfo;
31 import org.kuali.student.lum.lrc.dto.CreditInfo;
32 import org.kuali.student.lum.lrc.dto.CreditTypeInfo;
33 import org.kuali.student.lum.lrc.dto.GradeInfo;
34 import org.kuali.student.lum.lrc.dto.GradeTypeInfo;
35 import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
36 import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo;
37 import org.kuali.student.lum.lrc.dto.ScaleInfo;
38 import org.kuali.student.lum.lrc.service.LrcService;
39 import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes;
40
41 public class LrcContextImplTest {
42 private LrcService lrcService = new LrcServiceMock();
43 private LrcContextImpl lrcContext = new LrcContextImpl();
44 private ReqComponentInfo reqComponent1;
45 private ReqComponentInfo reqComponent2;
46 private ReqComponentInfo reqComponent3;
47 private ReqComponentInfo reqComponent4;
48
49 private void setupReqComponent1() {
50 reqComponent1 = new ReqComponentInfo();
51 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
52 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
53 reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
54 reqCompField1.setValue("A");
55 reqCompFieldList.add(reqCompField1);
56 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
57 reqCompField2.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
58 reqCompField2.setValue("kuali.resultComponent.grade.letter");
59 reqCompFieldList.add(reqCompField2);
60
61 reqComponent1.setReqCompFields(reqCompFieldList);
62 }
63
64 private void setupReqComponent2() {
65 reqComponent2 = new ReqComponentInfo();
66 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
67 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
68 reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
69 reqCompField1.setValue(null);
70 reqCompFieldList.add(reqCompField1);
71 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
72 reqCompField2.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
73 reqCompField2.setValue(null);
74 reqCompFieldList.add(reqCompField2);
75
76 reqComponent2.setReqCompFields(reqCompFieldList);
77 }
78
79 private void setupReqComponent3() {
80 reqComponent3 = new ReqComponentInfo();
81 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
82 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
83 reqCompField1.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
84 reqCompField1.setValue("kuali.resultComponent.grade.letter");
85 reqCompFieldList.add(reqCompField1);
86
87 reqComponent3.setReqCompFields(reqCompFieldList);
88 }
89
90 private void setupReqComponent4() {
91 reqComponent4 = new ReqComponentInfo();
92 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
93 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
94 reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
95 reqCompField1.setValue("A");
96 reqCompFieldList.add(reqCompField1);
97
98 reqComponent4.setReqCompFields(reqCompFieldList);
99 }
100
101 @Before
102 public void beforeMethod() {
103 lrcContext.setLrcService(lrcService);
104 setupReqComponent1();
105 setupReqComponent2();
106 setupReqComponent3();
107 setupReqComponent4();
108 }
109
110 @Test
111 public void testCreateContextMap() throws OperationFailedException {
112 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent1);
113 Assert.assertNotNull(contextMap);
114 Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TOKEN));
115 Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TYPE_TOKEN));
116 }
117
118 @Test
119 public void testCreateContextMap_GradeTypeToken() throws OperationFailedException {
120 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent3);
121 Assert.assertNotNull(contextMap);
122 Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TYPE_TOKEN));
123 }
124
125 @Test
126 public void testCreateContextMap_GradeToken() throws OperationFailedException {
127 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent4);
128 Assert.assertNotNull(contextMap);
129 Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TOKEN));
130 }
131
132 @Test
133 public void testCreateContextMap_GradeTypeTokenValues() throws OperationFailedException {
134 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent3);
135 ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
136
137 Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
138 }
139
140 @Test
141 public void testCreateContextMap_GradeTokenValues() throws OperationFailedException {
142 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent4);
143 ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
144 String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
145
146 Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
147 Assert.assertEquals("A", gradeId);
148 }
149
150 @Test
151 public void testCreateContextMap_TokenValues() throws OperationFailedException {
152 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent1);
153 ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
154 String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
155
156 Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
157 Assert.assertEquals("A", gradeId);
158 }
159
160 @Test
161 public void testCreateContextMap_NullTokenValues() throws OperationFailedException {
162 Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent2);
163 ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
164 String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
165
166 Assert.assertEquals(null, gradeTypeId);
167 Assert.assertEquals(null, gradeId);
168 }
169
170 private static class LrcServiceMock implements LrcService {
171
172 private Map<String, ResultComponentInfo> resultComponentMap = new HashMap<String, ResultComponentInfo>();
173 private List<ResultComponentTypeInfo> resultComponentTypeList = new ArrayList<ResultComponentTypeInfo>();
174 private Map<String, List<String>> typeIdMap = new HashMap<String, List<String>>();
175
176 public LrcServiceMock() {
177 ResultComponentInfo rc1 = new ResultComponentInfo();
178 rc1.setId("kuali.resultComponent.grade.letter");
179 rc1.setName("Letter");
180 rc1.setResultValues(Arrays.asList(new String[] {"A", "B", "C", "D", "F"}));
181 resultComponentMap.put("kuali.resultComponent.grade.letter", rc1);
182
183 ResultComponentInfo rc2 = new ResultComponentInfo();
184 rc2.setId("kuali.resultComponent.grade.passFail");
185 rc2.setName("Pass-Fail");
186 rc2.setResultValues(Arrays.asList(new String[] {"Pass", "Fail"}));
187 resultComponentMap.put("kuali.resultComponent.grade.passFail", rc2);
188
189 ResultComponentTypeInfo type1 = new ResultComponentTypeInfo();
190 type1.setId("kuali.resultComponentType.grade.finalGrade");
191 type1.setName("Final Grade");
192 resultComponentTypeList.add(type1);
193
194 ResultComponentTypeInfo type2 = new ResultComponentTypeInfo();
195 type2.setId("kuali.resultComponentType.credit.degree.fixed");
196 type2.setName("Fixed Number");
197 resultComponentTypeList.add(type2);
198
199 typeIdMap.put("kuali.resultComponentType.grade.finalGrade", Arrays.asList(new String[] {"kuali.resultComponent.grade.letter", "kuali.resultComponent.grade.passFail"}));
200 }
201
202 @Override
203 public String compareGrades(String gradeKey, String scaleKey,
204 String compareGradeKey, String compareScaleKey)
205 throws InvalidParameterException, MissingParameterException,
206 OperationFailedException {
207
208 return null;
209 }
210
211 @Override
212 public ResultComponentInfo createResultComponent(
213 String resultComponentTypeKey,
214 ResultComponentInfo resultComponentInfo)
215 throws AlreadyExistsException, DataValidationErrorException,
216 DoesNotExistException, InvalidParameterException,
217 MissingParameterException, OperationFailedException,
218 PermissionDeniedException {
219
220 return null;
221 }
222
223 @Override
224 public StatusInfo deleteResultComponent(String resultComponentId)
225 throws DoesNotExistException, InvalidParameterException,
226 MissingParameterException, OperationFailedException,
227 PermissionDeniedException {
228
229 return null;
230 }
231
232 @Override
233 public CredentialInfo getCredential(String credentialKey)
234 throws DoesNotExistException, InvalidParameterException,
235 MissingParameterException, OperationFailedException {
236
237 return null;
238 }
239
240 @Override
241 public List<String> getCredentialKeysByCredentialType(
242 String credentialTypeKey) throws DoesNotExistException,
243 InvalidParameterException, MissingParameterException,
244 OperationFailedException {
245
246 return null;
247 }
248
249 @Override
250 public CredentialTypeInfo getCredentialType(String credentialTypeKey)
251 throws DoesNotExistException, InvalidParameterException,
252 MissingParameterException, OperationFailedException {
253
254 return null;
255 }
256
257 @Override
258 public List<CredentialTypeInfo> getCredentialTypes()
259 throws OperationFailedException {
260
261 return null;
262 }
263
264 @Override
265 public List<CredentialInfo> getCredentialsByKeyList(
266 List<String> credentialKeyList) throws DoesNotExistException,
267 InvalidParameterException, MissingParameterException,
268 OperationFailedException {
269
270 return null;
271 }
272
273 @Override
274 public CreditInfo getCredit(String creditKey)
275 throws DoesNotExistException, InvalidParameterException,
276 MissingParameterException, OperationFailedException {
277
278 return null;
279 }
280
281 @Override
282 public List<String> getCreditKeysByCreditType(String creditTypeKey)
283 throws DoesNotExistException, InvalidParameterException,
284 MissingParameterException, OperationFailedException {
285
286 return null;
287 }
288
289 @Override
290 public CreditTypeInfo getCreditType(String creditTypeKey)
291 throws DoesNotExistException, InvalidParameterException,
292 MissingParameterException, OperationFailedException {
293
294 return null;
295 }
296
297 @Override
298 public List<CreditTypeInfo> getCreditTypes()
299 throws OperationFailedException {
300
301 return null;
302 }
303
304 @Override
305 public List<CreditInfo> getCreditsByKeyList(List<String> creditKeyList)
306 throws DoesNotExistException, InvalidParameterException,
307 MissingParameterException, OperationFailedException {
308
309 return null;
310 }
311
312 @Override
313 public GradeInfo getGrade(String gradeKey)
314 throws DoesNotExistException, InvalidParameterException,
315 MissingParameterException, OperationFailedException {
316
317 return null;
318 }
319
320 @Override
321 public List<String> getGradeKeysByGradeType(String gradeTypeKey)
322 throws DoesNotExistException, InvalidParameterException,
323 MissingParameterException, OperationFailedException {
324
325 return null;
326 }
327
328 @Override
329 public GradeTypeInfo getGradeType(String gradeTypeKey)
330 throws DoesNotExistException, InvalidParameterException,
331 MissingParameterException, OperationFailedException {
332
333 return null;
334 }
335
336 @Override
337 public List<GradeTypeInfo> getGradeTypes()
338 throws OperationFailedException {
339
340 return null;
341 }
342
343 @Override
344 public List<GradeInfo> getGradesByKeyList(List<String> gradeKeyList)
345 throws DoesNotExistException, InvalidParameterException,
346 MissingParameterException, OperationFailedException {
347
348 return null;
349 }
350
351 @Override
352 public List<GradeInfo> getGradesByScale(String scale)
353 throws DoesNotExistException, InvalidParameterException,
354 MissingParameterException, OperationFailedException {
355
356 return null;
357 }
358
359 @Override
360 public ResultComponentInfo getResultComponent(String resultComponentId)
361 throws DoesNotExistException, InvalidParameterException,
362 MissingParameterException, OperationFailedException {
363 return resultComponentMap.get(resultComponentId);
364 }
365
366 @Override
367 public List<String> getResultComponentIdsByResult(String resultValueId,
368 String resultComponentTypeKey) throws DoesNotExistException,
369 InvalidParameterException, MissingParameterException,
370 OperationFailedException {
371
372 return null;
373 }
374
375 @Override
376 public List<String> getResultComponentIdsByResultComponentType(
377 String resultComponentTypeKey) throws DoesNotExistException,
378 InvalidParameterException, MissingParameterException,
379 OperationFailedException {
380 return typeIdMap.get(resultComponentTypeKey);
381 }
382
383 @Override
384 public ResultComponentTypeInfo getResultComponentType(
385 String resultComponentTypeKey) throws DoesNotExistException,
386 InvalidParameterException, MissingParameterException,
387 OperationFailedException {
388
389 return null;
390 }
391
392 @Override
393 public List<ResultComponentTypeInfo> getResultComponentTypes()
394 throws OperationFailedException {
395 return this.resultComponentTypeList;
396 }
397
398 @Override
399 public ScaleInfo getScale(String scaleKey)
400 throws DoesNotExistException, InvalidParameterException,
401 MissingParameterException, OperationFailedException {
402
403 return null;
404 }
405
406 @Override
407 public List<GradeInfo> translateGrade(String gradeKey, String scaleKey,
408 String translateScaleKey) throws InvalidParameterException,
409 MissingParameterException, OperationFailedException {
410
411 return null;
412 }
413
414 @Override
415 public ResultComponentInfo updateResultComponent(
416 String resultComponentId,
417 ResultComponentInfo resultComponentInfo)
418 throws DataValidationErrorException, DoesNotExistException,
419 InvalidParameterException, MissingParameterException,
420 OperationFailedException, PermissionDeniedException,
421 VersionMismatchException {
422
423 return null;
424 }
425
426 @Override
427 public SearchCriteriaTypeInfo getSearchCriteriaType(
428 String searchCriteriaTypeKey) throws DoesNotExistException,
429 InvalidParameterException, MissingParameterException,
430 OperationFailedException {
431
432 return null;
433 }
434
435 @Override
436 public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
437 throws OperationFailedException {
438
439 return null;
440 }
441
442 @Override
443 public SearchResultTypeInfo getSearchResultType(
444 String searchResultTypeKey) throws DoesNotExistException,
445 InvalidParameterException, MissingParameterException,
446 OperationFailedException {
447
448 return null;
449 }
450
451 @Override
452 public List<SearchResultTypeInfo> getSearchResultTypes()
453 throws OperationFailedException {
454
455 return null;
456 }
457
458 @Override
459 public SearchTypeInfo getSearchType(String searchTypeKey)
460 throws DoesNotExistException, InvalidParameterException,
461 MissingParameterException, OperationFailedException {
462
463 return null;
464 }
465
466 @Override
467 public List<SearchTypeInfo> getSearchTypes()
468 throws OperationFailedException {
469
470 return null;
471 }
472
473 @Override
474 public List<SearchTypeInfo> getSearchTypesByCriteria(
475 String searchCriteriaTypeKey) throws DoesNotExistException,
476 InvalidParameterException, MissingParameterException,
477 OperationFailedException {
478
479 return null;
480 }
481
482 @Override
483 public List<SearchTypeInfo> getSearchTypesByResult(
484 String searchResultTypeKey) throws DoesNotExistException,
485 InvalidParameterException, MissingParameterException,
486 OperationFailedException {
487
488 return null;
489 }
490
491 @Override
492 public SearchResult search(SearchRequest searchRequest)
493 throws MissingParameterException {
494
495 return null;
496 }
497
498 @Override
499 public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
500
501 return null;
502 }
503
504 @Override
505 public List<String> getObjectTypes() {
506
507 return null;
508 }
509
510 }
511 }