1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.examoffering.service.impl;
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import javax.annotation.Resource;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.kuali.student.common.test.util.IdEntityTester;
27 import org.kuali.student.common.test.util.KeyEntityTester;
28 import org.kuali.student.common.test.util.RelationshipTester;
29 import org.kuali.student.enrollment.examoffering.dto.ExamOfferingInfo;
30 import org.kuali.student.enrollment.examoffering.dto.ExamOfferingRelationInfo;
31 import org.kuali.student.enrollment.examoffering.service.ExamOfferingService;
32 import org.kuali.student.r2.common.dto.ContextInfo;
33 import org.kuali.student.r2.common.dto.IdEntityInfo;
34 import org.kuali.student.r2.common.dto.StatusInfo;
35 import org.kuali.student.r2.common.dto.TypeStateEntityInfo;
36 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
37 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
38 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
39 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
40 import org.kuali.student.r2.common.exceptions.MissingParameterException;
41 import org.kuali.student.r2.common.exceptions.OperationFailedException;
42 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
43 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
44 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
45 import org.kuali.student.r2.common.util.RichTextHelper;
46 import org.kuali.student.common.test.util.AttributeTester;
47 import org.kuali.student.common.test.util.MetaTester;
48 import org.springframework.test.context.ContextConfiguration;
49 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
50 import static org.junit.Assert.assertEquals;
51 import static org.junit.Assert.assertFalse;
52 import static org.junit.Assert.assertNotNull;
53 import static org.junit.Assert.assertNull;
54 import static org.junit.Assert.assertTrue;
55 import static org.junit.Assert.fail;
56
57
58 @RunWith(SpringJUnit4ClassRunner.class)
59 @ContextConfiguration(locations = {"classpath:examoffering-test-with-map-context.xml"})
60 public abstract class TestExamOfferingServiceImplConformanceBaseCrud {
61
62
63
64
65
66 @Resource
67 public ExamOfferingService testService;
68 public ExamOfferingService getExamOfferingService() { return testService; }
69 public void setExamOfferingService(ExamOfferingService service) { testService = service; }
70
71 public ContextInfo contextInfo = null;
72 public static String principalId = "123";
73
74 @Before
75 public void setUp()
76 {
77 principalId = "123";
78 contextInfo = new ContextInfo();
79 contextInfo.setPrincipalId(principalId);
80 }
81
82
83
84
85
86
87
88
89 @Test
90 public void testCrudExamOffering()
91 throws DataValidationErrorException,
92 DoesNotExistException,
93 InvalidParameterException,
94 MissingParameterException,
95 OperationFailedException,
96 PermissionDeniedException,
97 ReadOnlyException,
98 VersionMismatchException,
99 DependentObjectsExistException
100 {
101
102
103
104 ExamOfferingInfo expected = new ExamOfferingInfo ();
105
106
107 testCrudExamOffering_setDTOFieldsForTestCreate (expected);
108
109 new AttributeTester().add2ForCreate(expected.getAttributes());
110
111
112 ExamOfferingInfo actual = testService.createExamOffering ( expected.getExamPeriodId(), expected.getExamId(), expected.getTypeKey(), expected, contextInfo);
113
114 assertNotNull(actual.getId());
115 new IdEntityTester().check(expected, actual);
116
117
118 testCrudExamOffering_testDTOFieldsForTestCreateUpdate (expected, actual);
119
120 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
121 new MetaTester().checkAfterCreate(actual.getMeta());
122
123
124
125
126 expected = actual;
127 actual = testService.getExamOffering ( actual.getId(), contextInfo);
128 assertEquals(expected.getId(), actual.getId());
129 new IdEntityTester().check(expected, actual);
130
131
132 testCrudExamOffering_testDTOFieldsForTestCreateUpdate (expected, actual);
133
134 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
135 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
136
137
138
139
140 expected = actual;
141
142 expected.setStateKey(expected.getState() + "_Updated");
143
144
145 testCrudExamOffering_setDTOFieldsForTestUpdate (expected);
146
147 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
148
149 actual = testService.updateExamOffering ( expected.getId(), expected, contextInfo);
150
151 assertEquals(expected.getId(), actual.getId());
152 new IdEntityTester().check(expected, actual);
153
154
155 testCrudExamOffering_testDTOFieldsForTestCreateUpdate (expected, actual);
156
157 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
158 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
159
160
161
162
163
164 expected = actual;
165
166 actual = testService.getExamOffering ( actual.getId(), contextInfo);
167
168 assertEquals(expected.getId(), actual.getId());
169 new IdEntityTester().check(expected, actual);
170
171
172 testCrudExamOffering_testDTOFieldsForTestReadAfterUpdate (expected, actual);
173
174 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
175
176 ExamOfferingInfo alphaDTO = actual;
177
178
179 ExamOfferingInfo betaDTO = new ExamOfferingInfo ();
180
181
182 testCrudExamOffering_setDTOFieldsForTestReadAfterUpdate (betaDTO);
183
184 betaDTO.setTypeKey("typeKeyBeta");
185 betaDTO.setStateKey("stateKeyBeta");
186 betaDTO = testService.createExamOffering ( betaDTO.getExamPeriodId(), betaDTO.getExamId(), betaDTO.getTypeKey(), betaDTO, contextInfo);
187
188
189
190
191
192 List<String> examOfferingIds = new ArrayList<String>();
193
194 List<ExamOfferingInfo> records = testService.getExamOfferingsByIds ( examOfferingIds, contextInfo);
195
196 assertEquals(examOfferingIds.size(), records.size());
197 assertEquals(0, examOfferingIds.size());
198
199
200
201
202 examOfferingIds = new ArrayList<String>();
203 examOfferingIds.add(alphaDTO.getId());
204 examOfferingIds.add(betaDTO.getId());
205
206 records = testService.getExamOfferingsByIds ( examOfferingIds, contextInfo);
207
208 assertEquals(examOfferingIds.size(), records.size());
209 for (ExamOfferingInfo record : records)
210 {
211 if (!examOfferingIds.remove(record.getId()))
212 {
213 fail(record.getId());
214 }
215 }
216 assertEquals(0, examOfferingIds.size());
217
218
219
220
221
222 examOfferingIds = testService.getExamOfferingIdsByType ("typeKey01", contextInfo);
223
224 assertEquals(1, examOfferingIds.size());
225 assertEquals(alphaDTO.getId(), examOfferingIds.get(0));
226
227
228
229 examOfferingIds = testService.getExamOfferingIdsByType ("typeKeyBeta", contextInfo);
230
231 assertEquals(1, examOfferingIds.size());
232 assertEquals(betaDTO.getId(), examOfferingIds.get(0));
233
234
235
236
237
238 StatusInfo status = testService.deleteExamOffering ( actual.getId(), contextInfo);
239
240 assertNotNull(status);
241 assertTrue(status.getIsSuccess());
242 try
243 {
244 ExamOfferingInfo record = testService.getExamOffering ( actual.getId(), contextInfo);
245 fail("Did not receive DoesNotExistException when attempting to get already-deleted entity");
246 }
247 catch (DoesNotExistException dnee)
248 {
249
250 }
251
252 }
253
254
255
256
257 public abstract void testCrudExamOffering_setDTOFieldsForTestCreate(ExamOfferingInfo expected);
258
259
260
261
262
263
264
265 public abstract void testCrudExamOffering_testDTOFieldsForTestCreateUpdate(ExamOfferingInfo expected, ExamOfferingInfo actual);
266
267
268
269
270 public abstract void testCrudExamOffering_setDTOFieldsForTestUpdate(ExamOfferingInfo expected);
271
272
273
274
275
276 public abstract void testCrudExamOffering_testDTOFieldsForTestReadAfterUpdate(ExamOfferingInfo expected, ExamOfferingInfo actual);
277
278
279
280
281
282 public abstract void testCrudExamOffering_setDTOFieldsForTestReadAfterUpdate(ExamOfferingInfo expected);
283
284
285
286
287
288 @Test
289 public void testCrudExamOfferingRelation()
290 throws DataValidationErrorException,
291 DoesNotExistException,
292 InvalidParameterException,
293 MissingParameterException,
294 OperationFailedException,
295 PermissionDeniedException,
296 ReadOnlyException,
297 VersionMismatchException,
298 DependentObjectsExistException
299 {
300
301
302
303 ExamOfferingRelationInfo expected = new ExamOfferingRelationInfo ();
304
305
306 testCrudExamOfferingRelation_setDTOFieldsForTestCreate (expected);
307
308 new AttributeTester().add2ForCreate(expected.getAttributes());
309
310
311 ExamOfferingRelationInfo actual = testService.createExamOfferingRelation ( expected.getFormatOfferingId(), expected.getExamOfferingId(), expected.getTypeKey(), expected, contextInfo);
312
313 assertNotNull(actual.getId());
314 new RelationshipTester().check(expected, actual);
315
316
317 testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate (expected, actual);
318
319 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
320 new MetaTester().checkAfterCreate(actual.getMeta());
321
322
323
324
325 expected = actual;
326 actual = testService.getExamOfferingRelation ( actual.getId(), contextInfo);
327 assertEquals(expected.getId(), actual.getId());
328 new RelationshipTester().check(expected, actual);
329
330
331 testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate (expected, actual);
332
333 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
334 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
335
336
337
338
339 expected = actual;
340
341 expected.setStateKey(expected.getState() + "_Updated");
342
343
344 testCrudExamOfferingRelation_setDTOFieldsForTestUpdate (expected);
345
346 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
347
348 actual = testService.updateExamOfferingRelation ( expected.getId(), expected, contextInfo);
349
350 assertEquals(expected.getId(), actual.getId());
351 new RelationshipTester().check(expected, actual);
352
353
354 testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate (expected, actual);
355
356 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
357 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
358
359
360
361
362
363 expected = actual;
364
365 actual = testService.getExamOfferingRelation ( actual.getId(), contextInfo);
366
367 assertEquals(expected.getId(), actual.getId());
368 new RelationshipTester().check(expected, actual);
369
370
371 testCrudExamOfferingRelation_testDTOFieldsForTestReadAfterUpdate (expected, actual);
372
373 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
374 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
375
376 ExamOfferingRelationInfo alphaDTO = actual;
377
378
379 ExamOfferingRelationInfo betaDTO = new ExamOfferingRelationInfo ();
380
381
382 testCrudExamOfferingRelation_setDTOFieldsForTestReadAfterUpdate (betaDTO);
383
384 betaDTO.setTypeKey("typeKeyBeta");
385 betaDTO.setStateKey("stateKeyBeta");
386 betaDTO = testService.createExamOfferingRelation ( betaDTO.getFormatOfferingId(), betaDTO.getExamOfferingId(), betaDTO.getTypeKey(), betaDTO, contextInfo);
387
388
389
390
391
392 List<String> examOfferingRelationIds = new ArrayList<String>();
393
394 List<ExamOfferingRelationInfo> records = testService.getExamOfferingRelationsByIds ( examOfferingRelationIds, contextInfo);
395
396 assertEquals(examOfferingRelationIds.size(), records.size());
397 assertEquals(0, examOfferingRelationIds.size());
398
399
400
401
402 examOfferingRelationIds = new ArrayList<String>();
403 examOfferingRelationIds.add(alphaDTO.getId());
404 examOfferingRelationIds.add(betaDTO.getId());
405
406 records = testService.getExamOfferingRelationsByIds ( examOfferingRelationIds, contextInfo);
407
408 assertEquals(examOfferingRelationIds.size(), records.size());
409 for (ExamOfferingRelationInfo record : records)
410 {
411 if (!examOfferingRelationIds.remove(record.getId()))
412 {
413 fail(record.getId());
414 }
415 }
416 assertEquals(0, examOfferingRelationIds.size());
417
418
419
420
421
422 examOfferingRelationIds = testService.getExamOfferingRelationIdsByType ("typeKey01", contextInfo);
423
424 assertEquals(1, examOfferingRelationIds.size());
425 assertEquals(alphaDTO.getId(), examOfferingRelationIds.get(0));
426
427
428
429 examOfferingRelationIds = testService.getExamOfferingRelationIdsByType ("typeKeyBeta", contextInfo);
430
431 assertEquals(1, examOfferingRelationIds.size());
432 assertEquals(betaDTO.getId(), examOfferingRelationIds.get(0));
433
434
435
436
437
438 StatusInfo status = testService.deleteExamOfferingRelation ( actual.getId(), contextInfo);
439
440 assertNotNull(status);
441 assertTrue(status.getIsSuccess());
442 try
443 {
444 ExamOfferingRelationInfo record = testService.getExamOfferingRelation ( actual.getId(), contextInfo);
445 fail("Did not receive DoesNotExistException when attempting to get already-deleted entity");
446 }
447 catch (DoesNotExistException dnee)
448 {
449
450 }
451
452 }
453
454
455
456
457 public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestCreate(ExamOfferingRelationInfo expected);
458
459
460
461
462
463
464
465 public abstract void testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate(ExamOfferingRelationInfo expected, ExamOfferingRelationInfo actual);
466
467
468
469
470 public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestUpdate(ExamOfferingRelationInfo expected);
471
472
473
474
475
476 public abstract void testCrudExamOfferingRelation_testDTOFieldsForTestReadAfterUpdate(ExamOfferingRelationInfo expected, ExamOfferingRelationInfo actual);
477
478
479
480
481
482 public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestReadAfterUpdate(ExamOfferingRelationInfo expected);
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510 @Test
511 public abstract void test_searchForExamOfferingIds()
512 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
513
514
515 @Test
516 public abstract void test_searchForExamOfferings()
517 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
518
519
520 @Test
521 public abstract void test_validateExamOffering()
522 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
523
524
525 @Test
526 public abstract void test_changeExamOfferingState()
527 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
528
529
530 public abstract void test_getExamOfferingsByExamPeriod()
531 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException ;
532
533
534 @Test
535 public abstract void test_validateExamOfferingRelation()
536 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
537
538
539 @Test
540 public abstract void test_getExamOfferingRelationsByFormatOffering()
541 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
542
543
544 @Test
545 public abstract void test_getExamOfferingRelationsByExamOffering()
546 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
547
548
549 @Test
550 public abstract void test_getExamOfferingRelationIdsByActivityOffering()
551 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
552
553
554 @Test
555 public abstract void test_searchForExamOfferingRelationIds()
556 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
557
558
559 @Test
560 public abstract void test_searchForExamOfferingRelations()
561 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
562
563 }