1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.exam.service.impl;
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import javax.annotation.Resource;
22
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.enrollment.exam.dto.ExamInfo;
28 import org.kuali.student.enrollment.exam.service.ExamService;
29 import org.kuali.student.r2.common.dto.ContextInfo;
30 import org.kuali.student.r2.common.dto.DtoConstants;
31 import org.kuali.student.r2.common.dto.StatusInfo;
32 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
33 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
34 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
35 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
36 import org.kuali.student.r2.common.exceptions.MissingParameterException;
37 import org.kuali.student.r2.common.exceptions.OperationFailedException;
38 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
39 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
40 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
41 import org.kuali.student.common.test.util.AttributeTester;
42 import org.kuali.student.common.test.util.RichTextTester;
43 import org.kuali.student.common.test.util.MetaTester;
44 import org.kuali.student.r2.common.util.constants.ExamServiceConstants;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
47 import static org.junit.Assert.assertEquals;
48 import static org.junit.Assert.assertFalse;
49 import static org.junit.Assert.assertNotNull;
50 import static org.junit.Assert.assertNull;
51 import static org.junit.Assert.assertTrue;
52 import static org.junit.Assert.fail;
53
54
55 @RunWith(SpringJUnit4ClassRunner.class)
56 @ContextConfiguration(locations = {"classpath:exam-test-with-map-context.xml"})
57 public abstract class TestExamServiceImplConformanceBaseCrud {
58
59
60
61
62
63 @Resource(name = "testExamService")
64 public ExamService testService;
65 public ExamService getExamService() { return testService; }
66 public void setExamService(ExamService service) { testService = service; }
67
68 public ContextInfo contextInfo = null;
69 public static String principalId = "123";
70
71 @Before
72 public void setUp()
73 {
74 principalId = "123";
75 contextInfo = new ContextInfo();
76 contextInfo.setPrincipalId(principalId);
77 }
78
79
80
81
82
83
84
85
86 @Test
87 public void testCrudExam()
88 throws DataValidationErrorException,
89 DoesNotExistException,
90 InvalidParameterException,
91 MissingParameterException,
92 OperationFailedException,
93 PermissionDeniedException,
94 ReadOnlyException,
95 VersionMismatchException,
96 DependentObjectsExistException
97 {
98
99
100
101 ExamInfo expected = new ExamInfo ();
102
103
104 testCrudExam_setDTOFieldsForTestCreate (expected);
105
106 new AttributeTester().add2ForCreate(expected.getAttributes());
107
108
109 ExamInfo actual = testService.createExam ( expected.getTypeKey(), expected, contextInfo);
110
111 assertNotNull(actual.getId());
112 new IdEntityTester().check(expected, actual);
113
114
115 testCrudExam_testDTOFieldsForTestCreateUpdate (expected, actual);
116
117 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
118 new MetaTester().checkAfterCreate(actual.getMeta());
119
120
121
122
123 expected = actual;
124 actual = testService.getExam ( actual.getId(), contextInfo);
125 assertEquals(expected.getId(), actual.getId());
126 new IdEntityTester().check(expected, actual);
127
128
129 testCrudExam_testDTOFieldsForTestCreateUpdate (expected, actual);
130
131 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
132 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
133
134
135
136
137 expected = actual;
138
139 expected.setStateKey(expected.getState() + "_Updated");
140
141
142 testCrudExam_setDTOFieldsForTestUpdate (expected);
143
144 new AttributeTester().delete1Update1Add1ForUpdate(expected.getAttributes());
145
146 actual = testService.updateExam ( expected.getId(), expected, contextInfo);
147
148 assertEquals(expected.getId(), actual.getId());
149 new IdEntityTester().check(expected, actual);
150
151
152 testCrudExam_testDTOFieldsForTestCreateUpdate (expected, actual);
153
154 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
155 new MetaTester().checkAfterUpdate(expected.getMeta(), actual.getMeta());
156
157
158
159
160
161 expected = actual;
162
163 actual = testService.getExam ( actual.getId(), contextInfo);
164
165 assertEquals(expected.getId(), actual.getId());
166 new IdEntityTester().check(expected, actual);
167
168
169 testCrudExam_testDTOFieldsForTestReadAfterUpdate (expected, actual);
170
171 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
172 new MetaTester().checkAfterGet(expected.getMeta(), actual.getMeta());
173
174 ExamInfo alphaDTO = actual;
175
176
177 ExamInfo betaDTO = new ExamInfo ();
178
179
180 testCrudExam_setDTOFieldsForTestReadAfterUpdate (betaDTO);
181
182 betaDTO.setTypeKey("typeKeyBeta");
183 betaDTO.setStateKey("stateKeyBeta");
184 betaDTO = testService.createExam ( betaDTO.getTypeKey(), betaDTO, contextInfo);
185
186
187
188
189
190 List<String> examIds = new ArrayList<String>();
191
192 List<ExamInfo> records = testService.getExamsByIds ( examIds, contextInfo);
193
194 assertEquals(examIds.size(), records.size());
195 assertEquals(0, examIds.size());
196
197
198
199
200 examIds = new ArrayList<String>();
201 examIds.add(alphaDTO.getId());
202 examIds.add(betaDTO.getId());
203
204 records = testService.getExamsByIds ( examIds, contextInfo);
205
206 assertEquals(examIds.size(), records.size());
207 for (ExamInfo record : records)
208 {
209 if (!examIds.remove(record.getId()))
210 {
211 fail(record.getId());
212 }
213 }
214 assertEquals(0, examIds.size());
215
216
217
218
219 ExamInfo infoByType = new ExamInfo();
220 testCrudExam_setDTOFieldsForTestCreate(infoByType);
221 infoByType.setStateKey(DtoConstants.STATE_ACTIVE);
222 infoByType.setTypeKey("firstByType");
223 infoByType = testService.createExam( infoByType.getTypeKey(), infoByType, contextInfo);
224 ExamInfo infoByType2 = new ExamInfo();
225 testCrudExam_setDTOFieldsForTestCreate(infoByType2);
226 infoByType2.setStateKey(DtoConstants.STATE_ACTIVE);
227 infoByType2.setTypeKey("otherByType");
228 infoByType2 = testService.createExam(infoByType2.getTypeKey(), infoByType2, contextInfo);
229
230
231
232
233 examIds = testService.getExamIdsByType ("firstByType", contextInfo);
234
235 assertEquals(1, examIds.size());
236 assertEquals(infoByType.getId(), examIds.get(0));
237
238
239
240 examIds = testService.getExamIdsByType ("otherByType", contextInfo);
241
242 assertEquals(1, examIds.size());
243 assertEquals(infoByType2.getId(), examIds.get(0));
244
245
246
247
248
249 StatusInfo status = testService.deleteExam ( actual.getId(), contextInfo);
250
251 assertNotNull(status);
252 assertTrue(status.getIsSuccess());
253 try
254 {
255 ExamInfo record = testService.getExam ( actual.getId(), contextInfo);
256 fail("Did not receive DoesNotExistException when attempting to get already-deleted entity");
257 }
258 catch (DoesNotExistException dnee)
259 {
260
261 }
262
263 }
264
265
266
267
268 public abstract void testCrudExam_setDTOFieldsForTestCreate(ExamInfo expected);
269
270
271
272
273
274
275
276 public abstract void testCrudExam_testDTOFieldsForTestCreateUpdate(ExamInfo expected, ExamInfo actual);
277
278
279
280
281 public abstract void testCrudExam_setDTOFieldsForTestUpdate(ExamInfo expected);
282
283
284
285
286
287 public abstract void testCrudExam_testDTOFieldsForTestReadAfterUpdate(ExamInfo expected, ExamInfo actual);
288
289
290
291
292
293 public abstract void testCrudExam_setDTOFieldsForTestReadAfterUpdate(ExamInfo expected);
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 @Test
316 public abstract void test_validateExam()
317 throws DoesNotExistException ,InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
318
319
320 @Test
321 public abstract void test_searchForExamIds()
322 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
323
324
325 @Test
326 public abstract void test_searchForExams()
327 throws InvalidParameterException ,MissingParameterException ,OperationFailedException ,PermissionDeniedException ;
328
329 }
330
331