View Javadoc

1   /*
2    * Copyright 2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the Lic+ense is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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      // SETUP
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      // TESTING
84      // ====================
85  
86      // ****************************************************
87      //           ExamOfferingInfo
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         // test create
103         // -------------------------------------
104         ExamOfferingInfo expected = new ExamOfferingInfo ();
105 
106         // METHOD TO SET DTO FIELDS HERE FOR TEST CREATE
107         testCrudExamOffering_setDTOFieldsForTestCreate (expected);
108 
109         new AttributeTester().add2ForCreate(expected.getAttributes());
110 
111         // code to create actual
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         // METHOD TO TEST DTO FIELDS HERE FOR TEST CREATE
118         testCrudExamOffering_testDTOFieldsForTestCreateUpdate (expected, actual);
119 
120         new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
121         new MetaTester().checkAfterCreate(actual.getMeta());
122 
123         // -------------------------------------
124         // test read
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         // INSERT CODE FOR TESTING MORE DTO FIELDS HERE
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         // test update
139         // -------------------------------------
140         expected = actual;
141 
142         expected.setStateKey(expected.getState() + "_Updated");
143 
144         // METHOD TO INSERT CODE TO UPDATE DTO FIELDS HERE
145         testCrudExamOffering_setDTOFieldsForTestUpdate (expected);
146 
147         new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
148         // code to update
149         actual = testService.updateExamOffering ( expected.getId(), expected, contextInfo);
150 
151         assertEquals(expected.getId(), actual.getId());
152         new IdEntityTester().check(expected, actual);
153 
154         // METHOD TO INSERT CODE FOR TESTING DTO FIELDS HERE
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         // test read after update
162         // -------------------------------------
163 
164         expected = actual;
165         // code to get actual
166         actual = testService.getExamOffering ( actual.getId(), contextInfo);
167 
168         assertEquals(expected.getId(), actual.getId());
169         new IdEntityTester().check(expected, actual);
170 
171         // INSERT METHOD CODE FOR TESTING DTO FIELDS HERE
172         testCrudExamOffering_testDTOFieldsForTestReadAfterUpdate (expected, actual);
173 
174         new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
175 
176         ExamOfferingInfo alphaDTO = actual;
177 
178         // create a 2nd DTO
179         ExamOfferingInfo betaDTO = new ExamOfferingInfo ();
180 
181         // METHOD TO INSERT CODE TO SET MORE DTO FIELDS HERE
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         // test bulk get with no ids supplied
190         // -------------------------------------
191 
192         List<String> examOfferingIds = new ArrayList<String>();
193         // code to get DTO by Ids
194         List<ExamOfferingInfo> records = testService.getExamOfferingsByIds ( examOfferingIds, contextInfo);
195 
196         assertEquals(examOfferingIds.size(), records.size());
197         assertEquals(0, examOfferingIds.size());
198 
199         // -------------------------------------
200         // test bulk get
201         // -------------------------------------
202         examOfferingIds = new ArrayList<String>();
203         examOfferingIds.add(alphaDTO.getId());
204         examOfferingIds.add(betaDTO.getId());
205         // code to get DTO by Ids
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         // test get by type
220         // -------------------------------------
221         // code to get by specific type "typeKey01"
222         examOfferingIds = testService.getExamOfferingIdsByType ("typeKey01", contextInfo);
223 
224         assertEquals(1, examOfferingIds.size());
225         assertEquals(alphaDTO.getId(), examOfferingIds.get(0));
226 
227         // test get by other type
228         // code to get by specific type "typeKeyBeta"
229         examOfferingIds = testService.getExamOfferingIdsByType ("typeKeyBeta", contextInfo);
230 
231         assertEquals(1, examOfferingIds.size());
232         assertEquals(betaDTO.getId(), examOfferingIds.get(0));
233 
234         // -------------------------------------
235         // test delete
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             // expected
250         }
251 
252     }
253 
254     /*
255         A method to set the fields for a ExamOffering in a 'test create' section prior to calling the 'create' operation.
256     */
257     public abstract void testCrudExamOffering_setDTOFieldsForTestCreate(ExamOfferingInfo expected);
258 
259     /*
260         A method to test the fields for a ExamOffering. This is called after:
261         - creating a DTO, where actual is the DTO returned by the create operation, and expected is the dto passed in to the create operation
262         - reading a DTO after creating it, and actual is the read DTO, and expected is the dto that was created
263         - updating a DTO, where actual is DTO returned by the update operation, and expected is the dto that was passed in to the update operation
264     */
265     public abstract void testCrudExamOffering_testDTOFieldsForTestCreateUpdate(ExamOfferingInfo expected, ExamOfferingInfo actual);
266 
267     /*
268         A method to set the fields for a ExamOffering in a 'test update' section prior to calling the 'update' operation.
269     */
270     public abstract void testCrudExamOffering_setDTOFieldsForTestUpdate(ExamOfferingInfo expected);
271 
272     /*
273         A method to test the fields for a ExamOffering after an update operation, followed by a read operation,
274         where actual is the DTO returned by the read operation, and expected is the dto returned by the update operation.
275     */
276     public abstract void testCrudExamOffering_testDTOFieldsForTestReadAfterUpdate(ExamOfferingInfo expected, ExamOfferingInfo actual);
277 
278     /*
279         A method to set the fields for a ExamOffering in the 'test read after update' section.
280         This dto is another (second) dto object being created for other tests.
281     */
282     public abstract void testCrudExamOffering_setDTOFieldsForTestReadAfterUpdate(ExamOfferingInfo expected);
283 
284 
285     // ****************************************************
286     //           ExamOfferingRelationInfo
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         // test create
302         // -------------------------------------
303         ExamOfferingRelationInfo expected = new ExamOfferingRelationInfo ();
304 
305         // METHOD TO SET DTO FIELDS HERE FOR TEST CREATE
306         testCrudExamOfferingRelation_setDTOFieldsForTestCreate (expected);
307 
308         new AttributeTester().add2ForCreate(expected.getAttributes());
309 
310         // code to create actual
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         // METHOD TO TEST DTO FIELDS HERE FOR TEST CREATE
317         testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate (expected, actual);
318 
319         new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
320         new MetaTester().checkAfterCreate(actual.getMeta());
321 
322         // -------------------------------------
323         // test read
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         // INSERT CODE FOR TESTING MORE DTO FIELDS HERE
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         // test update
338         // -------------------------------------
339         expected = actual;
340 
341         expected.setStateKey(expected.getState() + "_Updated");
342 
343         // METHOD TO INSERT CODE TO UPDATE DTO FIELDS HERE
344         testCrudExamOfferingRelation_setDTOFieldsForTestUpdate (expected);
345 
346         new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
347         // code to update
348         actual = testService.updateExamOfferingRelation ( expected.getId(), expected, contextInfo);
349 
350         assertEquals(expected.getId(), actual.getId());
351         new RelationshipTester().check(expected, actual);
352 
353         // METHOD TO INSERT CODE FOR TESTING DTO FIELDS HERE
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         // test read after update
361         // -------------------------------------
362 
363         expected = actual;
364         // code to get actual
365         actual = testService.getExamOfferingRelation ( actual.getId(), contextInfo);
366 
367         assertEquals(expected.getId(), actual.getId());
368         new RelationshipTester().check(expected, actual);
369 
370         // INSERT METHOD CODE FOR TESTING DTO FIELDS HERE
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         // create a 2nd DTO
379         ExamOfferingRelationInfo betaDTO = new ExamOfferingRelationInfo ();
380 
381         // METHOD TO INSERT CODE TO SET MORE DTO FIELDS HERE
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         // test bulk get with no ids supplied
390         // -------------------------------------
391 
392         List<String> examOfferingRelationIds = new ArrayList<String>();
393         // code to get DTO by Ids
394         List<ExamOfferingRelationInfo> records = testService.getExamOfferingRelationsByIds ( examOfferingRelationIds, contextInfo);
395 
396         assertEquals(examOfferingRelationIds.size(), records.size());
397         assertEquals(0, examOfferingRelationIds.size());
398 
399         // -------------------------------------
400         // test bulk get
401         // -------------------------------------
402         examOfferingRelationIds = new ArrayList<String>();
403         examOfferingRelationIds.add(alphaDTO.getId());
404         examOfferingRelationIds.add(betaDTO.getId());
405         // code to get DTO by Ids
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         // test get by type
420         // -------------------------------------
421         // code to get by specific type "typeKey01"
422         examOfferingRelationIds = testService.getExamOfferingRelationIdsByType ("typeKey01", contextInfo);
423 
424         assertEquals(1, examOfferingRelationIds.size());
425         assertEquals(alphaDTO.getId(), examOfferingRelationIds.get(0));
426 
427         // test get by other type
428         // code to get by specific type "typeKeyBeta"
429         examOfferingRelationIds = testService.getExamOfferingRelationIdsByType ("typeKeyBeta", contextInfo);
430 
431         assertEquals(1, examOfferingRelationIds.size());
432         assertEquals(betaDTO.getId(), examOfferingRelationIds.get(0));
433 
434         // -------------------------------------
435         // test delete
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             // expected
450         }
451 
452     }
453 
454     /*
455         A method to set the fields for a ExamOfferingRelation in a 'test create' section prior to calling the 'create' operation.
456     */
457     public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestCreate(ExamOfferingRelationInfo expected);
458 
459     /*
460         A method to test the fields for a ExamOfferingRelation. This is called after:
461         - creating a DTO, where actual is the DTO returned by the create operation, and expected is the dto passed in to the create operation
462         - reading a DTO after creating it, and actual is the read DTO, and expected is the dto that was created
463         - updating a DTO, where actual is DTO returned by the update operation, and expected is the dto that was passed in to the update operation
464     */
465     public abstract void testCrudExamOfferingRelation_testDTOFieldsForTestCreateUpdate(ExamOfferingRelationInfo expected, ExamOfferingRelationInfo actual);
466 
467     /*
468         A method to set the fields for a ExamOfferingRelation in a 'test update' section prior to calling the 'update' operation.
469     */
470     public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestUpdate(ExamOfferingRelationInfo expected);
471 
472     /*
473         A method to test the fields for a ExamOfferingRelation after an update operation, followed by a read operation,
474         where actual is the DTO returned by the read operation, and expected is the dto returned by the update operation.
475     */
476     public abstract void testCrudExamOfferingRelation_testDTOFieldsForTestReadAfterUpdate(ExamOfferingRelationInfo expected, ExamOfferingRelationInfo actual);
477 
478     /*
479         A method to set the fields for a ExamOfferingRelation in the 'test read after update' section.
480         This dto is another (second) dto object being created for other tests.
481     */
482     public abstract void testCrudExamOfferingRelation_setDTOFieldsForTestReadAfterUpdate(ExamOfferingRelationInfo expected);
483 
484 
485     // ========================================
486     // SERVICE OPS TESTED IN BASE TEST CLASS
487     // ========================================
488 	
489 	/*
490 		The following methods are tested as part of CRUD operations for this service's DTOs:
491 			getExamOffering
492 			getExamOfferingsByIds
493 			getExamOfferingIdsByType
494 			createExamOffering
495 			updateExamOffering
496 			deleteExamOffering
497 			createExamOfferingRelation
498 			updateExamOfferingRelation
499 			deleteExamOfferingRelation
500 			getExamOfferingRelation
501 			getExamOfferingRelationsByIds
502 			getExamOfferingRelationIdsByType
503 	*/
504 
505     // ========================================
506     // SERVICE OPS NOT TESTED IN BASE TEST CLASS
507     // ========================================
508 
509     /* Method Name: searchForExamOfferingIds */
510     @Test
511     public abstract void test_searchForExamOfferingIds()
512             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
513 
514     /* Method Name: searchForExamOfferings */
515     @Test
516     public abstract void test_searchForExamOfferings()
517             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
518 
519     /* Method Name: validateExamOffering */
520     @Test
521     public abstract void test_validateExamOffering()
522             throws 	DoesNotExistException	,InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
523 
524     /* Method Name: changeExamOfferingState */
525     @Test
526     public abstract void test_changeExamOfferingState()
527             throws 	DoesNotExistException	,InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
528 
529     /* Method Name: getExamOfferingsByExamPeriod */
530     public abstract void test_getExamOfferingsByExamPeriod()
531             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException  ;
532 
533     /* Method Name: validateExamOfferingRelation */
534     @Test
535     public abstract void test_validateExamOfferingRelation()
536             throws 	DoesNotExistException	,InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
537 
538     /* Method Name: getExamOfferingRelationsByFormatOffering */
539     @Test
540     public abstract void test_getExamOfferingRelationsByFormatOffering()
541             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
542 
543     /* Method Name: getExamOfferingRelationsByExamOffering */
544     @Test
545     public abstract void test_getExamOfferingRelationsByExamOffering()
546             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
547 
548     /* Method Name: getExamOfferingRelationIdsByActivityOffering */
549     @Test
550     public abstract void test_getExamOfferingRelationIdsByActivityOffering()
551             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
552 
553     /* Method Name: searchForExamOfferingRelationIds */
554     @Test
555     public abstract void test_searchForExamOfferingRelationIds()
556             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
557 
558     /* Method Name: searchForExamOfferingRelations */
559     @Test
560     public abstract void test_searchForExamOfferingRelations()
561             throws 	InvalidParameterException	,MissingParameterException	,OperationFailedException	,PermissionDeniedException	;
562 
563 }