1
2
3
4
5 package org.kuali.student.enrollment.class1.lrc.service.impl;
6
7 import java.sql.Timestamp;
8 import java.util.ArrayList;
9 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
10 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
11 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
12 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
13 import org.kuali.student.r2.common.exceptions.MissingParameterException;
14 import org.kuali.student.r2.common.exceptions.OperationFailedException;
15 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
16 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
17 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import java.util.Date;
24
25 import java.util.List;
26 import javax.annotation.Resource;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.kuali.student.common.mock.MockService;
32 import org.kuali.student.enrollment.test.util.AttributeTester;
33 import org.kuali.student.enrollment.test.util.FloatAsStringTester;
34 import org.kuali.student.enrollment.test.util.KeyEntityTester;
35 import org.kuali.student.enrollment.test.util.ListOfStringTester;
36 import org.kuali.student.enrollment.test.util.MetaTester;
37 import org.kuali.student.enrollment.test.util.TimeTester;
38 import org.kuali.student.r2.common.dto.ContextInfo;
39 import org.kuali.student.r2.common.dto.StatusInfo;
40 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
41 import org.kuali.student.r2.common.util.RichTextHelper;
42 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
43 import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
44 import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
45 import org.kuali.student.r2.lum.lrc.dto.ResultValueRangeInfo;
46 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
47 import org.kuali.student.r2.lum.lrc.infc.ResultValueRange;
48 import org.kuali.student.r2.lum.lrc.service.LRCService;
49 import org.springframework.test.context.ContextConfiguration;
50 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
51
52 @RunWith(SpringJUnit4ClassRunner.class)
53 @ContextConfiguration(locations = {"classpath:lrc-mock-service-test-context.xml"})
54 public class TestLrcServiceMockImpl {
55
56 public LRCService getLRCService() {
57 return lrcService;
58 }
59
60 public void setLRCService(LRCService lrcService) {
61 this.lrcService = lrcService;
62 }
63 @Resource
64 private LRCService lrcService;
65 public static String principalId = "123";
66 public ContextInfo callContext = null;
67
68 @Before
69 public void setUp() {
70 principalId = "123";
71 callContext = new ContextInfo();
72 callContext.setPrincipalId(principalId);
73
74
75
76
77
78 }
79
80 @Test
81 public void testAll()
82 throws DataValidationErrorException,
83 DoesNotExistException,
84 InvalidParameterException,
85 MissingParameterException,
86 OperationFailedException,
87 PermissionDeniedException,
88 ReadOnlyException,
89 VersionMismatchException,
90 AlreadyExistsException,
91 DependentObjectsExistException {
92 testCrud();
93 testBusinessLogic();
94 }
95
96 private void testCrud()
97 throws DataValidationErrorException,
98 DoesNotExistException,
99 InvalidParameterException,
100 MissingParameterException,
101 OperationFailedException,
102 PermissionDeniedException,
103 ReadOnlyException,
104 VersionMismatchException,
105 AlreadyExistsException,
106 DependentObjectsExistException {
107 System.out.println("started testing crud");
108 if (this.getLRCService() instanceof MockService) {
109 System.out.println("clearing mock service");
110 MockService mockService = (MockService) this.getLRCService();
111 mockService.clear();
112 }
113
114 ResultScaleInfo expected = new ResultScaleInfo();
115 expected.setKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
116 expected.setTypeKey(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE);
117 expected.setStateKey(LrcServiceConstants.RESULT_SCALE_STATE_APPROVED);
118 expected.setEffectiveDate(new Date());
119 expected.setExpirationDate(new Date(new Date().getTime() + 1000));
120 expected.setName("A-F Letter Graded Scale");
121 expected.setDescr(new RichTextHelper().fromPlain("Letter Graded Scale description"));
122 new AttributeTester().add2ForCreate(expected.getAttributes());
123 ResultScaleInfo actual = lrcService.createResultScale(expected.getTypeKey(), expected,
124 callContext);
125 assertEquals(expected.getKey(), actual.getKey());
126 new KeyEntityTester().check(expected, actual);
127 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
128 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
129 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
130 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
131 new MetaTester().checkAfterCreate(actual.getMeta());
132
133
134 try {
135 lrcService.createResultScale(expected.getTypeKey(), expected, callContext);
136 fail("should have gotten an already exists exception");
137 } catch (AlreadyExistsException e) {
138
139 }
140
141
142 expected = actual;
143 actual = lrcService.getResultScale(actual.getKey(), callContext);
144 assertEquals(expected.getKey(), actual.getKey());
145 new KeyEntityTester().check(expected, actual);
146 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
147 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
148 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
149 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
150 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
151
152
153 expected = actual;
154 expected.setName(expected.getName() + " updated");
155 expected.setDescr(new RichTextHelper().fromPlain(expected.getDescr().getPlain() + " updated"));
156 expected.setEffectiveDate(new Timestamp(expected.getEffectiveDate().getTime() - 2000));
157 expected.setExpirationDate(new Timestamp(expected.getExpirationDate().getTime() + 2000));
158
159
160
161 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
162 actual = lrcService.updateResultScale(expected.getKey(), expected, callContext);
163 assertEquals(expected.getKey(), actual.getKey());
164 new KeyEntityTester().check(expected, actual);
165 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
166 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
167 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
168 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
169 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
170
171
172 expected = actual;
173 actual = lrcService.getResultScale(actual.getKey(), callContext);
174 assertEquals(expected.getKey(), actual.getKey());
175 new KeyEntityTester().check(expected, actual);
176 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
177 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
178 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
179 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
180 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
181
182 ResultScaleInfo letterGradedScale = actual;
183
184
185 ResultScaleInfo creditScale = new ResultScaleInfo();
186 creditScale.setKey(LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE);
187 creditScale.setTypeKey(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_CREDIT);
188 creditScale.setStateKey(LrcServiceConstants.RESULT_SCALE_STATE_APPROVED);
189 creditScale.setEffectiveDate(new Date());
190 creditScale.setExpirationDate(new Date(new Date().getTime() + 1000));
191 creditScale.setName("Degree Credit");
192 creditScale.setDescr(new RichTextHelper().fromPlain("Degree Credit"));
193 creditScale = lrcService.createResultScale(creditScale.getTypeKey(), creditScale,
194 callContext);
195
196
197 expected = new ResultScaleInfo();
198 expected.setKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_PERCENTAGE);
199 expected.setTypeKey(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE);
200 expected.setStateKey(LrcServiceConstants.RESULT_SCALE_STATE_APPROVED);
201 expected.setEffectiveDate(new Date());
202 expected.setExpirationDate(new Date(new Date().getTime() + 1000));
203 expected.setName("Pass/Fail Scale");
204 expected.setDescr(new RichTextHelper().fromPlain("pass/fail scale"));
205 ResultValueRangeInfo range = new ResultValueRangeInfo();
206 range.setMinValue("0");
207 range.setMaxValue("99");
208 range.setIncrement("1");
209 expected.setResultValueRange(range);
210 actual = lrcService.createResultScale(expected.getTypeKey(), expected,
211 callContext);
212 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
213
214
215 expected = actual;
216 expected.getResultValueRange().setMinValue("1");
217 expected.getResultValueRange().setMaxValue("100");
218 expected.getResultValueRange().setIncrement(".1");
219 actual = lrcService.updateResultScale(expected.getKey(), expected, callContext);
220 assertEquals(expected.getKey(), actual.getKey());
221 new KeyEntityTester().check(expected, actual);
222 checkRange(expected.getResultValueRange(), actual.getResultValueRange());
223 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
224 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
225 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
226 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
227 ResultScaleInfo percentScale = actual;
228
229
230 List<String> keys = new ArrayList<String>();
231 keys.add(letterGradedScale.getKey());
232 keys.add(percentScale.getKey());
233 keys.add(creditScale.getKey());
234 List<ResultScaleInfo> both = lrcService.getResultScalesByKeys(keys, callContext);
235 assertEquals(keys.size(), both.size());
236 for (ResultScaleInfo info : both) {
237 if (!keys.remove(info.getKey())) {
238 fail(info.getKey() + " was not in the return list");
239 }
240 }
241 assertEquals(0, keys.size());
242
243
244
245 keys = lrcService.getResultScaleKeysByType(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE, callContext);
246 assertEquals(2, keys.size());
247 if (!keys.remove(letterGradedScale.getKey())) {
248 fail("does not contain " + letterGradedScale.getKey());
249 }
250 if (!keys.remove(percentScale.getKey())) {
251 fail("does not contain " + percentScale.getKey());
252 }
253
254
255 ResultScaleInfo passFailScale = new ResultScaleInfo();
256 passFailScale.setKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_PF);
257 passFailScale.setTypeKey(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE);
258 passFailScale.setStateKey(LrcServiceConstants.RESULT_SCALE_STATE_APPROVED);
259 passFailScale.setEffectiveDate(new Date());
260 passFailScale.setExpirationDate(new Date(new Date().getTime() + 1000));
261 passFailScale.setName("Pass/Fail");
262 passFailScale.setDescr(new RichTextHelper().fromPlain("Pass Fail"));
263 passFailScale = lrcService.createResultScale(passFailScale.getTypeKey(), passFailScale,
264 callContext);
265
266 this.testCrudResultValue();
267
268
269 StatusInfo status = lrcService.deleteResultScale(letterGradedScale.getKey(), callContext);
270 assertNotNull(status);
271 assertTrue(status.getIsSuccess());
272 try {
273 actual = lrcService.getResultScale(letterGradedScale.getKey(), callContext);
274 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
275 } catch (DoesNotExistException dnee) {
276
277 }
278 status = lrcService.deleteResultScale(percentScale.getKey(), callContext);
279 assertNotNull(status);
280 assertTrue(status.getIsSuccess());
281 try {
282 actual = lrcService.getResultScale(percentScale.getKey(), callContext);
283 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
284 } catch (DoesNotExistException dnee) {
285
286 }
287 status = lrcService.deleteResultScale(passFailScale.getKey(), callContext);
288 assertNotNull(status);
289 assertTrue(status.getIsSuccess());
290 try {
291 actual = lrcService.getResultScale(passFailScale.getKey(), callContext);
292 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
293 } catch (DoesNotExistException dnee) {
294
295 }
296
297 }
298
299 private void checkRange(ResultValueRangeInfo expected,
300 ResultValueRangeInfo actual) {
301 if (expected == null && actual == null) {
302 return;
303 }
304 if (expected == null) {
305 fail("expected range was null but actual had a structure with fields=" + toString(actual));
306 }
307 if (actual == null) {
308 fail("actual range was null but expected had a structure with fields=" + toString(expected));
309 }
310 assertEquals(expected.getMinValue(), expected.getMinValue());
311 assertEquals(expected.getMaxValue(), expected.getMaxValue());
312 assertEquals(expected.getIncrement(), expected.getIncrement());
313 }
314
315 private String toString(ResultValueRange range) {
316 return range.getMinValue() + " to " + range.getMaxValue() + " + " + range.getIncrement();
317 }
318
319 public void testCrudResultValue()
320 throws DataValidationErrorException,
321 DoesNotExistException,
322 InvalidParameterException,
323 MissingParameterException,
324 OperationFailedException,
325 PermissionDeniedException,
326 ReadOnlyException,
327 VersionMismatchException,
328 AlreadyExistsException,
329 DependentObjectsExistException {
330
331
332 ResultValueInfo expected = new ResultValueInfo();
333 expected.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A);
334 expected.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
335 expected.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
336 expected.setEffectiveDate(new Date());
337 expected.setExpirationDate(new Date(new Date().getTime() + 1000));
338 expected.setName("Grade A+");
339 expected.setDescr(new RichTextHelper().fromPlain("value A+ description"));
340 expected.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
341 expected.setValue("A+");
342 expected.setNumericValue("4.5");
343 new AttributeTester().add2ForCreate(expected.getAttributes());
344 ResultValueInfo actual = lrcService.createResultValue(expected.getResultScaleKey(), expected.getTypeKey(), expected,
345 callContext);
346 assertEquals(expected.getKey(), actual.getKey());
347 new KeyEntityTester().check(expected, actual);
348 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
349 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
350 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
351 assertEquals(expected.getValue(), actual.getValue());
352 new FloatAsStringTester().check(expected.getNumericValue(), actual.getNumericValue());
353 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
354 new MetaTester().checkAfterCreate(actual.getMeta());
355
356
357 try {
358 lrcService.createResultValue(expected.getResultScaleKey(), expected.getTypeKey(), expected, callContext);
359 fail("should have gotten an already exists exception");
360 } catch (AlreadyExistsException e) {
361
362 }
363
364 expected = actual;
365 actual = lrcService.getResultValue(actual.getKey(), callContext);
366 assertEquals(expected.getKey(), actual.getKey());
367 new KeyEntityTester().check(expected, actual);
368 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
369 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
370 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
371 assertEquals(expected.getValue(), actual.getValue());
372 new FloatAsStringTester().check(expected.getNumericValue(), actual.getNumericValue());
373 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
374 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
375
376
377 expected = actual;
378 expected.setName("Grade A");
379 expected.setEffectiveDate(new Timestamp(expected.getEffectiveDate().getTime() - 2000));
380 expected.setExpirationDate(new Timestamp(expected.getExpirationDate().getTime() + 2000));
381 expected.setDescr(new RichTextHelper().fromPlain("Grade A description"));
382 expected.setValue("A");
383 expected.setValue("4.0");
384 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
385 actual = lrcService.updateResultValue(expected.getKey(), expected, callContext);
386 assertEquals(expected.getKey(), actual.getKey());
387 new KeyEntityTester().check(expected, actual);
388 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
389 assertEquals(expected.getValue(), actual.getValue());
390 new FloatAsStringTester().check(expected.getNumericValue(), actual.getNumericValue());
391 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
392 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
393 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
394 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
395
396
397 expected = actual;
398 actual = lrcService.getResultValue(actual.getKey(), callContext);
399 assertEquals(expected.getKey(), actual.getKey());
400 new KeyEntityTester().check(expected, actual);
401 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
402 assertEquals(expected.getValue(), actual.getValue());
403 new FloatAsStringTester().check(expected.getNumericValue(), actual.getNumericValue());
404 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
405 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
406 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
407 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
408
409 ResultValueInfo gradeA = actual;
410
411
412 ResultValueInfo gradeB = new ResultValueInfo();
413 gradeB.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B);
414 gradeB.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
415 gradeB.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
416 gradeB.setEffectiveDate(new Date());
417 gradeB.setExpirationDate(new Date(new Date().getTime() + 1000));
418 gradeB.setName("B grade");
419 gradeB.setDescr(new RichTextHelper().fromPlain("value B description"));
420 gradeB.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
421 gradeB.setValue("B");
422 gradeB.setNumericValue("3.0");
423 gradeB = lrcService.createResultValue(gradeB.getResultScaleKey(), gradeB.getTypeKey(), gradeB,
424 callContext);
425
426 List<String> keys = new ArrayList<String>();
427 keys.add(actual.getKey());
428 keys.add(gradeB.getKey());
429 List<ResultValueInfo> both = lrcService.getResultValuesByKeys(keys, callContext);
430 assertEquals(keys.size(), both.size());
431 for (ResultValueInfo info : both) {
432 if (!keys.remove(info.getKey())) {
433 fail(info.getKey() + " was not in the return list");
434 }
435 }
436 assertEquals(0, keys.size());
437
438 keys = lrcService.getResultValueKeysByType(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE, callContext);
439 if (keys.size() != 2) {
440 System.out.println("wrong number of keys");
441 for (String key : keys) {
442 System.out.println(key);
443 }
444 }
445 assertEquals(2, keys.size());
446 if (!keys.remove(actual.getKey())) {
447 fail("does ot contain " + actual.getKey());
448 }
449 if (!keys.remove(gradeB.getKey())) {
450 fail("does ot contain " + gradeB.getKey());
451 }
452
453
454
455
456 ResultValueInfo gradeC = new ResultValueInfo();
457 gradeC.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C);
458 gradeC.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
459 gradeC.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
460 gradeC.setEffectiveDate(new Date());
461 gradeC.setExpirationDate(new Date(new Date().getTime() + 1000));
462 gradeC.setName("value C");
463 gradeC.setDescr(new RichTextHelper().fromPlain("value C description"));
464 gradeC.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
465 gradeC.setValue("C");
466 gradeC.setNumericValue("2.0");
467 gradeC = lrcService.createResultValue(gradeC.getResultScaleKey(), gradeC.getTypeKey(), gradeC, callContext);
468
469
470 ResultValueInfo gradeD = new ResultValueInfo();
471 gradeD.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D);
472 gradeD.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
473 gradeD.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
474 gradeD.setEffectiveDate(new Date());
475 gradeD.setExpirationDate(new Date(new Date().getTime() + 1000));
476 gradeD.setName("value D");
477 gradeD.setDescr(new RichTextHelper().fromPlain("value D description"));
478 gradeD.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
479 gradeD.setValue("D");
480 gradeD.setNumericValue("1.0");
481 gradeD = lrcService.createResultValue(gradeD.getResultScaleKey(), gradeD.getTypeKey(), gradeD, callContext);
482
483
484 ResultValueInfo gradeF = new ResultValueInfo();
485 gradeF.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
486 gradeF.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
487 gradeF.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
488 gradeF.setEffectiveDate(new Date());
489 gradeF.setExpirationDate(new Date(new Date().getTime() + 1000));
490 gradeF.setName("value F");
491 gradeF.setDescr(new RichTextHelper().fromPlain("value F description"));
492 gradeF.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
493 gradeF.setValue("F");
494 gradeF.setNumericValue("0.0");
495 gradeF = lrcService.createResultValue(gradeF.getResultScaleKey(), gradeF.getTypeKey(), gradeF, callContext);
496
497
498 ResultValueInfo gradePfP = new ResultValueInfo();
499 gradePfP.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_P);
500 gradePfP.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
501 gradePfP.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
502 gradePfP.setEffectiveDate(new Date());
503 gradePfP.setExpirationDate(new Date(new Date().getTime() + 1000));
504 gradePfP.setName("value PF P");
505 gradePfP.setDescr(new RichTextHelper().fromPlain("value P description"));
506 gradePfP.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_PF);
507 gradePfP.setValue("P");
508 gradePfP.setNumericValue("1.0");
509 gradePfP = lrcService.createResultValue(gradePfP.getResultScaleKey(), gradePfP.getTypeKey(), gradePfP, callContext);
510
511
512 ResultValueInfo gradePfF = new ResultValueInfo();
513 gradePfF.setKey(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F);
514 gradePfF.setTypeKey(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE);
515 gradePfF.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
516 gradePfF.setEffectiveDate(new Date());
517 gradePfF.setExpirationDate(new Date(new Date().getTime() + 1000));
518 gradePfF.setName("value F");
519 gradePfF.setDescr(new RichTextHelper().fromPlain("value F description"));
520 gradePfF.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_PF);
521 gradePfF.setValue("F");
522 gradePfF.setNumericValue("0.0");
523 gradePfF = lrcService.createResultValue(gradePfF.getResultScaleKey(), gradePfF.getTypeKey(), gradePfF, callContext);
524
525
526 actual = lrcService.getResultValueForScaleAndValue(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_PF, "F", callContext);
527 assertEquals(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F, actual.getKey());
528 try {
529 lrcService.getResultValueForScaleAndValue(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER, "P", callContext);
530 fail("should not have found a P value in a letter grading scale");
531 } catch (DoesNotExistException ex) {
532
533 }
534 assertEquals(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F, actual.getKey());
535
536 this.testCrudResultValuesGroup();
537
538
539 StatusInfo status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A, callContext);
540 assertNotNull(status);
541 assertTrue(status.getIsSuccess());
542 try {
543 actual = lrcService.getResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A, callContext);
544 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
545 } catch (DoesNotExistException dnee) {
546
547 }
548 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B, callContext);
549 assertNotNull(status);
550 assertTrue(status.getIsSuccess());
551 try {
552 actual = lrcService.getResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B, callContext);
553 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
554 } catch (DoesNotExistException dnee) {
555
556 }
557 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C, callContext);
558 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D, callContext);
559 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F, callContext);
560 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_P, callContext);
561 status = lrcService.deleteResultValue(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F, callContext);
562 }
563
564 private void testCrudResultValuesGroup()
565 throws DataValidationErrorException,
566 DoesNotExistException,
567 InvalidParameterException,
568 MissingParameterException,
569 OperationFailedException,
570 PermissionDeniedException,
571 ReadOnlyException,
572 VersionMismatchException,
573 AlreadyExistsException {
574
575
576 ResultValuesGroupInfo expected = new ResultValuesGroupInfo();
577
578 expected.setKey(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION);
579 expected.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
580 expected.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
581 expected.setEffectiveDate(new Date());
582 expected.setExpirationDate(new Date(new Date().getTime() + 1000));
583 expected.setName("Passing Letter Grades");
584 expected.setDescr(new RichTextHelper().fromPlain("Grades that are considered passing on an A-F letter scale"));
585 expected.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
586 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A);
587 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B);
588 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C);
589 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D);
590 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
591 new AttributeTester().add2ForCreate(expected.getAttributes());
592 ResultValuesGroupInfo actual = lrcService.createResultValuesGroup(expected.getResultScaleKey(), expected.getTypeKey(),
593 expected,
594 callContext);
595 assertEquals(expected.getKey(), actual.getKey());
596 new KeyEntityTester().check(expected, actual);
597 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
598 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
599 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
600 new ListOfStringTester().check(expected.getResultValueKeys(), actual.getResultValueKeys());
601 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
602 new MetaTester().checkAfterCreate(actual.getMeta());
603
604
605 try {
606 lrcService.createResultValuesGroup(expected.getResultScaleKey(), expected.getTypeKey(), expected, callContext);
607 fail("should have gotten an already exists exception");
608 } catch (AlreadyExistsException e) {
609
610 }
611
612
613 expected = actual;
614 actual = lrcService.getResultValuesGroup(actual.getKey(), callContext);
615 assertEquals(expected.getKey(), actual.getKey());
616 new KeyEntityTester().check(expected, actual);
617 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
618 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
619 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
620 new ListOfStringTester().check(expected.getResultValueKeys(), actual.getResultValueKeys());
621 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
622 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
623 ResultValuesGroupInfo passingGradeTranslation = actual;
624
625
626 expected = actual;
627 expected.setName("name 1 updated");
628 expected.setEffectiveDate(new Timestamp(expected.getEffectiveDate().getTime() - 2000));
629 expected.setExpirationDate(new Timestamp(expected.getExpirationDate().getTime() + 2000));
630 expected.setDescr(new RichTextHelper().fromPlain("values group 1 description updated"));
631 expected.getResultValueKeys().remove(0);
632 expected.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
633 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
634 actual = lrcService.updateResultValuesGroup(expected.getKey(), expected, callContext);
635 assertEquals(expected.getKey(), actual.getKey());
636 new KeyEntityTester().check(expected, actual);
637 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
638 new ListOfStringTester().check(expected.getResultValueKeys(), actual.getResultValueKeys());
639 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
640 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
641 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
642 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
643
644
645 expected = actual;
646 actual = lrcService.getResultValuesGroup(actual.getKey(), callContext);
647 assertEquals(expected.getKey(), actual.getKey());
648 new KeyEntityTester().check(expected, actual);
649 assertEquals(expected.getResultScaleKey(), actual.getResultScaleKey());
650 new ListOfStringTester().check(expected.getResultValueKeys(), actual.getResultValueKeys());
651 new TimeTester().check(expected.getEffectiveDate(), actual.getEffectiveDate());
652 new TimeTester().check(expected.getExpirationDate(), actual.getExpirationDate());
653 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
654 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
655
656
657 ResultValuesGroupInfo gradeLetter = new ResultValuesGroupInfo();
658 gradeLetter.setKey(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
659 gradeLetter.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
660 gradeLetter.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
661 gradeLetter.setEffectiveDate(new Date());
662 gradeLetter.setExpirationDate(new Date(new Date().getTime() + 1000));
663 gradeLetter.setName("Letter Grades");
664 gradeLetter.setDescr(new RichTextHelper().fromPlain("Grades on an A-F letter scale"));
665 gradeLetter.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
666 gradeLetter.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A);
667 gradeLetter.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B);
668 gradeLetter.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C);
669 gradeLetter.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D);
670 gradeLetter.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
671 gradeLetter = lrcService.createResultValuesGroup(gradeLetter.getResultScaleKey(), gradeLetter.getTypeKey(),
672 gradeLetter,
673 callContext);
674
675
676 ResultValuesGroupInfo gradePF = new ResultValuesGroupInfo();
677 gradePF.setKey(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
678 gradePF.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
679 gradePF.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
680 gradePF.setEffectiveDate(new Date());
681 gradePF.setExpirationDate(new Date(new Date().getTime() + 1000));
682 gradePF.setName("Passing Letter Grades");
683 gradePF.setDescr(new RichTextHelper().fromPlain("Grades on the PF scale"));
684 gradePF.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_GRADE_LETTER);
685 gradePF.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_P);
686 gradePF.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F);
687 gradePF = lrcService.createResultValuesGroup(gradePF.getResultScaleKey(), gradePF.getTypeKey(),
688 gradePF,
689 callContext);
690
691
692 ResultValuesGroupInfo creditRange1To4 = new ResultValuesGroupInfo();
693 creditRange1To4.setKey(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_1_MINUS4);
694 creditRange1To4.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE);
695 creditRange1To4.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
696 creditRange1To4.setEffectiveDate(new Date());
697 creditRange1To4.setExpirationDate(new Date(new Date().getTime() + 1000));
698 creditRange1To4.setName("1-4 credits");
699 creditRange1To4.setDescr(new RichTextHelper().fromPlain("1-4 credits"));
700 creditRange1To4.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE);
701 creditRange1To4.setResultValueRange(new ResultValueRangeInfo());
702 creditRange1To4.getResultValueRange().setMinValue("1");
703 creditRange1To4.getResultValueRange().setMaxValue("4");
704 creditRange1To4.getResultValueRange().setIncrement("1");
705 creditRange1To4 = lrcService.createResultValuesGroup(creditRange1To4.getResultScaleKey(), creditRange1To4.getTypeKey(),
706 creditRange1To4,
707 callContext);
708
709 ResultValuesGroupInfo creditFixed2 = new ResultValuesGroupInfo();
710 creditFixed2.setKey(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_2_0);
711 creditFixed2.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED);
712 creditFixed2.setStateKey(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED);
713 creditFixed2.setEffectiveDate(new Date());
714 creditFixed2.setExpirationDate(new Date(new Date().getTime() + 1000));
715 creditFixed2.setName("2 credits");
716 creditFixed2.setDescr(new RichTextHelper().fromPlain("2 credits"));
717 creditFixed2.setResultScaleKey(LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE);
718 creditFixed2.getResultValueKeys().add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_P);
719 creditFixed2 = lrcService.createResultValuesGroup(creditFixed2.getResultScaleKey(), creditFixed2.getTypeKey(),
720 creditFixed2,
721 callContext);
722 List<String> keys = new ArrayList<String>();
723 keys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
724 keys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION);
725 List<ResultValuesGroupInfo> both = lrcService.getResultValuesGroupsByKeys(keys, callContext);
726 assertEquals(keys.size(), both.size());
727 for (ResultValuesGroupInfo info : both) {
728 if (!keys.remove(info.getKey())) {
729 fail(info.getKey() + " was not in the return list");
730 }
731 }
732 assertEquals(0, keys.size());
733
734
735 keys = lrcService.getResultValuesGroupKeysByType(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, callContext);
736 assertEquals(3, keys.size());
737 if (!keys.remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER)) {
738 fail("does not contain " + LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
739 }
740 if (!keys.remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION)) {
741 fail("does not contain " + LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION);
742 }
743 if (!keys.remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL)) {
744 fail("does not contain " + LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
745 }
746
747
748
749
750 List<String> expectedKeys = new ArrayList<String>();
751 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A);
752 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B);
753 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C);
754 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D);
755 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
756 List<ResultValueInfo> rvs = lrcService.getResultValuesForResultValuesGroup(
757 LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER, callContext);
758 assertEquals(expectedKeys.size(), rvs.size());
759 for (ResultValueInfo rv : rvs) {
760 if (!expectedKeys.remove(rv.getKey())) {
761 fail(rv.getKey() + " was not expected");
762 }
763 }
764 assertEquals(0, expectedKeys.size());
765
766
767 expectedKeys = new ArrayList<String>();
768 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_A);
769 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_B);
770 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_C);
771 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_D);
772 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_LETTER_F);
773 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_P);
774 expectedKeys.add(LrcServiceConstants.RESULT_VALUE_KEY_GRADE_PF_F);
775 List<String> groupKeys = new ArrayList<String>();
776 groupKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
777 groupKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION);
778 groupKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
779
780 rvs = lrcService.getResultValuesForResultValuesGroups(groupKeys, callContext);
781 assertEquals(expectedKeys.size(), rvs.size());
782 for (ResultValueInfo rv : rvs) {
783 if (!expectedKeys.remove(rv.getKey())) {
784 fail(rv.getKey() + " was not expected");
785 }
786 }
787 assertEquals(0, expectedKeys.size());
788
789
790
791 expectedKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
792 expectedKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION);
793 expectedKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
794
795 List<ResultValuesGroupInfo> rvgs = lrcService.getResultValuesGroupsByResultScaleType(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE, callContext);
796 assertEquals(expectedKeys.size(), rvgs.size());
797 for (ResultValuesGroupInfo rvg : rvgs) {
798 if (!expectedKeys.remove(rvg.getKey())) {
799 fail(rvg.getKey() + " was not expected");
800 }
801 }
802 assertEquals(0, expectedKeys.size());
803
804
805 expectedKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_2_0);
806 expectedKeys.add(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_1_MINUS4);
807
808 rvgs = lrcService.getResultValuesGroupsByResultScaleType(LrcServiceConstants.RESULT_SCALE_TYPE_KEY_CREDIT, callContext);
809 assertEquals(expectedKeys.size(), rvgs.size());
810 for (ResultValuesGroupInfo rvg : rvgs) {
811 if (!expectedKeys.remove(rvg.getKey())) {
812 fail(rvg.getKey() + " was not expected");
813 }
814 }
815 assertEquals(0, expectedKeys.size());
816
817
818
819
820 StatusInfo status = lrcService.deleteResultValuesGroup(
821 LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION, callContext);
822 assertNotNull(status);
823 assertTrue(status.getIsSuccess());
824 try {
825 actual = lrcService.getResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER_PASSING_TRANSLATION,
826 callContext);
827 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
828 } catch (DoesNotExistException dnee) {
829
830 }
831
832 status = lrcService.deleteResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER, callContext);
833 assertNotNull(status);
834 assertTrue(status.getIsSuccess());
835 try {
836 actual = lrcService.getResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER, callContext);
837 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
838 } catch (DoesNotExistException dnee) {
839
840 }
841 status = lrcService.deleteResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL, callContext);
842 assertNotNull(status);
843 assertTrue(status.getIsSuccess());
844 try {
845 actual = lrcService.getResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL, callContext);
846 fail("Did not receive DoesNotExistException when attempting to get already-deleted Entity");
847 } catch (DoesNotExistException dnee) {
848
849 }
850
851 status = lrcService.deleteResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_2_0, callContext);
852 status = lrcService.deleteResultValuesGroup(LrcServiceConstants.RESULT_GROUP_KEY_KUALI_CREDITTYPE_CREDIT_1_MINUS4, callContext);
853 System.out.println("finished testing crud");
854
855 }
856
857 private void testBusinessLogic()
858 throws DataValidationErrorException,
859 DoesNotExistException,
860 InvalidParameterException,
861 MissingParameterException,
862 OperationFailedException,
863 PermissionDeniedException,
864 ReadOnlyException,
865 VersionMismatchException,
866 AlreadyExistsException {
867 System.out.println("started testing business logic");
868 if (this.getLRCService() instanceof MockService) {
869 System.out.println("Clearing mock service");
870 MockService mockService = (MockService) this.getLRCService();
871 mockService.clear();
872 }
873 ResultValuesGroupInfo rvg = lrcService.getCreateFixedCreditResultValuesGroup("22",
874 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
875 assertEquals("kuali.creditType.credit.degree.22", rvg.getKey());
876 assertEquals(1, rvg.getResultValueKeys().size());
877 assertEquals("kuali.result.value.credit.degree.22", rvg.getResultValueKeys().get(0));
878 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, rvg.getTypeKey());
879
880 rvg = lrcService.getCreateFixedCreditResultValuesGroup("22",
881 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
882 assertEquals("kuali.creditType.credit.degree.22", rvg.getKey());
883 assertEquals(1, rvg.getResultValueKeys().size());
884 assertEquals("kuali.result.value.credit.degree.22", rvg.getResultValueKeys().get(0));
885 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, rvg.getTypeKey());
886 for (String rvKey : rvg.getResultValueKeys()) {
887 ResultValueInfo rv = this.lrcService.getResultValue(rvKey, callContext);
888 assertEquals("22", rv.getValue());
889 }
890
891 rvg = lrcService.getCreateRangeCreditResultValuesGroup("22", "24", "1",
892 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
893 assertEquals("kuali.creditType.credit.degree.22-24", rvg.getKey());
894 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE, rvg.getTypeKey());
895
896 rvg = lrcService.getCreateRangeCreditResultValuesGroup("22", "24", "1",
897 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
898 assertEquals("kuali.creditType.credit.degree.22-24", rvg.getKey());
899 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE, rvg.getTypeKey());
900
901
902 List<String> values = new ArrayList<String>();
903 values.add("1");
904 values.add("12");
905 values.add("16");
906 values.add("33");
907 List<String> expValueKeys = new ArrayList<String>();
908 expValueKeys.add("kuali.result.value.credit.degree.1");
909 expValueKeys.add("kuali.result.value.credit.degree.12");
910 expValueKeys.add("kuali.result.value.credit.degree.16");
911 expValueKeys.add("kuali.result.value.credit.degree.33");
912
913 rvg = lrcService.getCreateMultipleCreditResultValuesGroup(values,
914 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
915 assertEquals("kuali.creditType.credit.degree.1.12.16.33", rvg.getKey());
916 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, rvg.getTypeKey());
917 new ListOfStringTester().check(rvg.getResultValueKeys(), expValueKeys);
918 for (String rvKey : rvg.getResultValueKeys()) {
919 ResultValueInfo rv = this.lrcService.getResultValue(rvKey, callContext);
920 if (!values.contains(rv.getValue())) {
921 fail("Result value does not have an expected value");
922 }
923 }
924
925
926 rvg = lrcService.getCreateMultipleCreditResultValuesGroup(values,
927 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
928 assertEquals("kuali.creditType.credit.degree.1.12.16.33", rvg.getKey());
929 assertEquals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, rvg.getTypeKey());
930 new ListOfStringTester().check(rvg.getResultValueKeys(), expValueKeys);
931 for (String rvKey : rvg.getResultValueKeys()) {
932 ResultValueInfo rv = this.lrcService.getResultValue(rvKey, callContext);
933 if (!values.contains(rv.getValue())) {
934 fail("Result value does not have an expected value");
935 }
936 }
937
938 String value = "75";
939 ResultValueInfo rv = this.lrcService.getCreateResultValueForScale(value,
940 LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
941 assertEquals("kuali.result.value.credit.degree.75", rv.getKey());
942 assertEquals(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE, rv.getTypeKey());
943 assertEquals(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED, rv.getStateKey());
944 assertEquals(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE, rv.getTypeKey());
945 assertEquals(LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, rv.getResultScaleKey());
946 assertEquals(value, rv.getValue());
947 new FloatAsStringTester().check(value, rv.getNumericValue());
948
949 this.lrcService.getCreateResultValueForScale(value, LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, callContext);
950 assertEquals("kuali.result.value.credit.degree.75", rv.getKey());
951 assertEquals(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE, rv.getTypeKey());
952 assertEquals(LrcServiceConstants.RESULT_VALUE_STATE_APPROVED, rv.getStateKey());
953 assertEquals(LrcServiceConstants.RESULT_VALUE_TYPE_KEY_VALUE, rv.getTypeKey());
954 assertEquals(LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, rv.getResultScaleKey());
955 assertEquals(value, rv.getValue());
956 new FloatAsStringTester().check(value, rv.getNumericValue());
957
958 System.out.println("finished testing business logic");
959 }
960 }